Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promtail: show a clearer reason in "disable watchConfig" log message when server is disabled #11420

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

* [10677](https://github.com/grafana/loki/pull/10677) **chaudum** Remove deprecated `stream_lag_labels` setting from both the `options` and `client` configuration sections.
* [10689](https://github.com/grafana/loki/pull/10689) **dylanguedes**: Ingester: Make jitter to be 20% of flush check period instead of 1%.
* [11420](https://github.com/grafana/loki/pull/11420) **zry98**: Show a clearer reason in "disable watchConfig" log message when server is disabled.

##### Fixes

Expand Down
36 changes: 20 additions & 16 deletions clients/pkg/promtail/promtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,29 @@ func (p *Promtail) watchConfig() {
level.Warn(p.logger).Log("msg", "disable watchConfig", "reason", "Promtail newConfig func is Empty")
return
}
promtailServer, ok := p.server.(*server.PromtailServer)
if !ok {
level.Warn(p.logger).Log("msg", "disable watchConfig", "reason", "promtailServer cast fail")
switch srv := p.server.(type) {
case *server.NoopServer:
level.Warn(p.logger).Log("msg", "disable watchConfig", "reason", "Promtail server is disabled")
return
}
level.Warn(p.logger).Log("msg", "enable watchConfig")
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
for {
select {
case <-hup:
_ = p.reload()
case rc := <-promtailServer.Reload():
if err := p.reload(); err != nil {
rc <- err
} else {
rc <- nil
case *server.PromtailServer:
level.Warn(p.logger).Log("msg", "enable watchConfig")
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
for {
select {
case <-hup:
_ = p.reload()
case rc := <-srv.Reload():
if err := p.reload(); err != nil {
rc <- err
} else {
rc <- nil
}
}
}
default:
level.Warn(p.logger).Log("msg", "disable watchConfig", "reason", "Unknown Promtail server type")
return
}
}

Expand Down
10 changes: 5 additions & 5 deletions clients/pkg/promtail/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,25 @@ func computeExternalURL(u string, port int) (*url.URL, error) {
return eu, nil
}

type noopServer struct {
type NoopServer struct {
log log.Logger
sigs chan os.Signal
}

func newNoopServer(log log.Logger) *noopServer {
return &noopServer{
func newNoopServer(log log.Logger) *NoopServer {
return &NoopServer{
log: log,
sigs: make(chan os.Signal, 1),
}
}

func (s *noopServer) Run() error {
func (s *NoopServer) Run() error {
signal.Notify(s.sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-s.sigs
level.Info(s.log).Log("msg", "received shutdown signal", "sig", sig)
return nil
}

func (s *noopServer) Shutdown() {
func (s *NoopServer) Shutdown() {
s.sigs <- syscall.SIGTERM
}