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

Remove Unmarshal and UnmarshalExact method from the config API #29992

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ replace (
github.com/DataDog/datadog-agent/pkg/config/model => ../../../../../../pkg/config/model
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel => ../../../../../../pkg/config/nodetreemodel
github.com/DataDog/datadog-agent/pkg/config/setup => ../../../../../../pkg/config/setup
github.com/DataDog/datadog-agent/pkg/config/structure => ../../../../../../pkg/config/structure
github.com/DataDog/datadog-agent/pkg/config/teeconfig => ../../../../../../pkg/config/teeconfig
github.com/DataDog/datadog-agent/pkg/config/utils => ../../../../../../pkg/config/utils
github.com/DataDog/datadog-agent/pkg/metrics => ../../../../../../pkg/metrics
Expand Down Expand Up @@ -108,6 +109,7 @@ require (
github.com/DataDog/datadog-agent/pkg/config/model v0.57.1 // indirect
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel v0.60.0-devel // indirect
github.com/DataDog/datadog-agent/pkg/config/setup v0.57.1 // indirect
github.com/DataDog/datadog-agent/pkg/config/structure v0.0.0-00010101000000-000000000000 // indirect
github.com/DataDog/datadog-agent/pkg/config/teeconfig v0.60.0-devel // indirect
github.com/DataDog/datadog-agent/pkg/config/utils v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/orchestrator/model v0.56.0-rc.3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ require (
github.com/DataDog/datadog-agent/comp/core/tagger/utils v0.56.2
github.com/DataDog/datadog-agent/comp/otelcol/ddflareextension/def v0.56.0-rc.3
github.com/DataDog/datadog-agent/comp/otelcol/ddflareextension/impl v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/config/structure v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/config/structure v0.60.0-devel
github.com/DataDog/datadog-agent/pkg/util/defaultpaths v0.0.0-00010101000000-000000000000
github.com/containerd/containerd/api v1.7.19
github.com/containerd/errdefs v0.1.0
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ type Setup interface {
// some misc functions, that should likely be split into another interface
type Compound interface {
UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error
Unmarshal(rawVal interface{}) error
UnmarshalExact(rawVal interface{}) error

ReadInConfig() error
ReadConfig(in io.Reader) error
Expand Down
14 changes: 0 additions & 14 deletions pkg/config/model/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,20 +579,6 @@ func (c *safeConfig) UnmarshalKey(key string, rawVal interface{}, opts ...viper.
return c.Viper.UnmarshalKey(key, rawVal, opts...)
}

// Unmarshal wraps Viper for concurrent access
func (c *safeConfig) Unmarshal(rawVal interface{}) error {
c.RLock()
defer c.RUnlock()
return c.Viper.Unmarshal(rawVal)
}

// UnmarshalExact wraps Viper for concurrent access
func (c *safeConfig) UnmarshalExact(rawVal interface{}) error {
c.RLock()
defer c.RUnlock()
return c.Viper.UnmarshalExact(rawVal)
}

// ReadInConfig wraps Viper for concurrent access
func (c *safeConfig) ReadInConfig() error {
c.Lock()
Expand Down
15 changes: 1 addition & 14 deletions pkg/config/nodetreemodel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,24 +535,11 @@ func (c *safeConfig) UnmarshalKey(key string, rawVal interface{}, opts ...viper.
return c.Viper.UnmarshalKey(key, rawVal, opts...)
}

// Unmarshal wraps Viper for concurrent access
func (c *safeConfig) Unmarshal(rawVal interface{}) error {
c.RLock()
defer c.RUnlock()
return c.Viper.Unmarshal(rawVal)
}

// UnmarshalExact wraps Viper for concurrent access
func (c *safeConfig) UnmarshalExact(rawVal interface{}) error {
c.RLock()
defer c.RUnlock()
return c.Viper.UnmarshalExact(rawVal)
}

// ReadInConfig wraps Viper for concurrent access
func (c *safeConfig) ReadInConfig() error {
c.Lock()
defer c.Unlock()

// ReadInConfig reset configuration with the main config file
err := errors.Join(c.Viper.ReadInConfig(), c.configSources[model.SourceFile].ReadInConfig())
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions pkg/config/teeconfig/teeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ func (t *teeConfig) UnmarshalKey(key string, rawVal interface{}, opts ...viper.D
return t.baseline.UnmarshalKey(key, rawVal, opts...)
}

// Unmarshal wraps Viper for concurrent access
func (t *teeConfig) Unmarshal(rawVal interface{}) error {
return t.baseline.Unmarshal(rawVal)
}

// UnmarshalExact wraps Viper for concurrent access
func (t *teeConfig) UnmarshalExact(rawVal interface{}) error {
return t.baseline.UnmarshalExact(rawVal)
}

// ReadInConfig wraps Viper for concurrent access
func (t *teeConfig) ReadInConfig() error {
err1 := t.baseline.ReadInConfig()
Expand Down
10 changes: 6 additions & 4 deletions pkg/metrics/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ replace (
github.com/DataDog/datadog-agent/pkg/aggregator/ckey => ../aggregator/ckey/
github.com/DataDog/datadog-agent/pkg/collector/check/defaults => ../../pkg/collector/check/defaults
github.com/DataDog/datadog-agent/pkg/config/env => ../../pkg/config/env
github.com/DataDog/datadog-agent/pkg/config/mock => ../../pkg/config/mock
github.com/DataDog/datadog-agent/pkg/config/mock => ../config/mock
github.com/DataDog/datadog-agent/pkg/config/model => ../config/model/
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel => ../../pkg/config/nodetreemodel
github.com/DataDog/datadog-agent/pkg/config/setup => ../../pkg/config/setup
github.com/DataDog/datadog-agent/pkg/config/teeconfig => ../../pkg/config/teeconfig
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel => ../config/nodetreemodel
github.com/DataDog/datadog-agent/pkg/config/setup => ../config/setup
github.com/DataDog/datadog-agent/pkg/config/structure => ../config/structure
github.com/DataDog/datadog-agent/pkg/config/teeconfig => ../config/teeconfig
github.com/DataDog/datadog-agent/pkg/tagger/types => ../../pkg/tagger/types
github.com/DataDog/datadog-agent/pkg/tagset => ../tagset/
github.com/DataDog/datadog-agent/pkg/telemetry => ../telemetry/
Expand All @@ -40,6 +41,7 @@ require (
github.com/DataDog/datadog-agent/pkg/aggregator/ckey v0.56.0-rc.3
github.com/DataDog/datadog-agent/pkg/config/mock v0.57.1
github.com/DataDog/datadog-agent/pkg/config/model v0.57.1
github.com/DataDog/datadog-agent/pkg/config/structure v0.0.0-00010101000000-000000000000
github.com/DataDog/datadog-agent/pkg/tagger/types v0.56.0-rc.3
github.com/DataDog/datadog-agent/pkg/tagset v0.56.0-rc.3
github.com/DataDog/datadog-agent/pkg/telemetry v0.56.0-rc.3
Expand Down
15 changes: 6 additions & 9 deletions pkg/metrics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"

pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/config/structure"
"github.com/DataDog/datadog-agent/pkg/util/log"
)

Expand Down Expand Up @@ -50,13 +51,9 @@ var (
defaultPercentiles = []int(nil)
)

type histogramPercentilesConfig struct {
Percentiles []string `mapstructure:"histogram_percentiles"`
}

func (h *histogramPercentilesConfig) percentiles() []int {
func parsePercentiles(percentiles []string) []int {
res := []int{}
for _, p := range h.Percentiles {
for _, p := range percentiles {
i, err := strconv.ParseFloat(p, 64)
if err != nil {
log.Errorf("Could not parse '%s' from 'histogram_percentiles' (skipping): %s", p, err)
Expand All @@ -81,12 +78,12 @@ func NewHistogram(interval int64, config pkgconfigmodel.Config) *Histogram {
defaultAggregates = config.GetStringSlice("histogram_aggregates")
}
if defaultPercentiles == nil {
c := histogramPercentilesConfig{}
err := config.Unmarshal(&c)
c := []string{}
err := structure.UnmarshalKey(config, "histogram_percentiles", &c)
if err != nil {
log.Errorf("Could not Unmarshal histogram configuration: %s", err)
} else {
defaultPercentiles = c.percentiles()
defaultPercentiles = parsePercentiles(c)
sort.Ints(defaultPercentiles)
}
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/metrics/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import (
)

func TestHistogramConf(t *testing.T) {
h := histogramPercentilesConfig{Percentiles: []string{"0.95", "0.96", "0.28", "0.57", "0.58"}}
assert.Equal(t, []int{95, 96, 28, 57, 58}, h.percentiles())
assert.Equal(t, []int{95, 96, 28, 57, 58}, parsePercentiles([]string{"0.95", "0.96", "0.28", "0.57", "0.58"}))
}

func TestHistogramConfError(t *testing.T) {
h := histogramPercentilesConfig{Percentiles: []string{"0.95", "test", "0.12test", "0.22", "200", "-50"}}
assert.Equal(t, []int{95, 22}, h.percentiles())
assert.Equal(t, []int{95, 22}, parsePercentiles([]string{"0.95", "test", "0.12test", "0.22", "200", "-50"}))
}

func TestConfigureDefault(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/serializer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ replace (
github.com/DataDog/datadog-agent/pkg/config/model => ../config/model
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel => ../../pkg/config/nodetreemodel
github.com/DataDog/datadog-agent/pkg/config/setup => ../config/setup/
github.com/DataDog/datadog-agent/pkg/config/structure => ../../pkg/config/structure
github.com/DataDog/datadog-agent/pkg/config/teeconfig => ../../pkg/config/teeconfig
github.com/DataDog/datadog-agent/pkg/config/utils => ../config/utils/
github.com/DataDog/datadog-agent/pkg/metrics => ../metrics/
Expand Down Expand Up @@ -98,6 +99,7 @@ require (
github.com/DataDog/datadog-agent/pkg/config/env v0.57.1 // indirect
github.com/DataDog/datadog-agent/pkg/config/nodetreemodel v0.60.0-devel // indirect
github.com/DataDog/datadog-agent/pkg/config/setup v0.57.1 // indirect
github.com/DataDog/datadog-agent/pkg/config/structure v0.0.0-00010101000000-000000000000 // indirect
github.com/DataDog/datadog-agent/pkg/config/teeconfig v0.60.0-devel // indirect
github.com/DataDog/datadog-agent/pkg/config/utils v0.56.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/orchestrator/model v0.56.0-rc.3 // indirect
Expand Down
Loading