Skip to content

Commit

Permalink
fix default values applied to Config
Browse files Browse the repository at this point in the history
PR grafana#546 introduced a default value for the overall Config struct which
overwrote the defaults coming from flags. This commit ensures that
flag-level defaults take precedence.
  • Loading branch information
rfratto committed Apr 22, 2021
1 parent 238dc73 commit 415e8d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/grafana/agent/pkg/loki"
"github.com/grafana/agent/pkg/prom"
"github.com/grafana/agent/pkg/tempo"
"github.com/grafana/agent/pkg/util"
"github.com/pkg/errors"
"github.com/prometheus/common/version"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -42,7 +43,10 @@ type Config struct {

// UnmarshalYAML implements yaml.Unmarshaler.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Apply defaults to the config from our struct and any defaults inherited from flags.
*c = DefaultConfig
util.DefaultConfigFromFlags(c)

type config Config
return unmarshal((*config)(c))
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ prometheus:
require.NotEmpty(t, c.Prometheus.ServiceConfig.Lifecycler.InfNames)
require.NotZero(t, c.Prometheus.ServiceConfig.Lifecycler.NumTokens)
require.NotZero(t, c.Prometheus.ServiceConfig.Lifecycler.HeartbeatPeriod)
require.True(t, c.Server.RegisterInstrumentation)
}

func TestConfig_OverrideDefaultsOnLoad(t *testing.T) {
Expand Down

0 comments on commit 415e8d8

Please sign in to comment.