Skip to content

Commit

Permalink
Fix bug with unnecessary config reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Jul 8, 2024
1 parent 4bc33dc commit 9cd3ec8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions static/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/grafana/loki/clients/pkg/promtail/wal"
"github.com/grafana/loki/pkg/tracing"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v2"
)

func init() {
Expand Down Expand Up @@ -121,6 +122,8 @@ type Instance struct {
log log.Logger
reg *util.Unregisterer

previousConfig string

promtail *promtail.Promtail
}

Expand Down Expand Up @@ -155,14 +158,20 @@ func (i *Instance) ApplyConfig(c *InstanceConfig, g GlobalConfig, dryRun bool) e
defer i.mut.Unlock()

// No-op if the configs haven't changed.
if util.CompareYAML(c, i.cfg) {
newConfigByteArr, err := yaml.Marshal(c)
if err != nil {
return fmt.Errorf("failed to marshal new logs instance config: %w", err)
}
newConfig := string(newConfigByteArr[:])
if newConfig == i.previousConfig {
level.Debug(i.log).Log("msg", "instance config hasn't changed, not recreating Promtail")
return nil
}
i.previousConfig = newConfig
i.cfg = c

positionsDir := filepath.Dir(c.PositionsConfig.PositionsFile)
err := os.MkdirAll(positionsDir, 0775)
err = os.MkdirAll(positionsDir, 0775)
if err != nil {
level.Warn(i.log).Log("msg", "failed to create the positions directory. logs may be unable to save their position", "path", positionsDir, "err", err)
}
Expand Down

0 comments on commit 9cd3ec8

Please sign in to comment.