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

Deprecate confmap.Conf.Set, not used anywhere for the moment #5485

Merged
merged 1 commit into from
Jun 7, 2022
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 @@ -25,6 +25,7 @@
- Package `overwritepropertiesmapconverter` -> `overwritepropertiesconverter`
- Deprecate `component.ExtensionDefaultConfigFunc` in favor of `component.ExtensionCreateDefaultConfigFunc` (#5451)
- Deprecate `confmap.Received.AsMap` in favor of `confmap.Received.AsConf` (#5465)
- Deprecate `confmap.Conf.Set`, not used anywhere for the moment (#5485)

### 💡 Enhancements 💡

Expand Down
6 changes: 3 additions & 3 deletions config/internal/configsource/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func NewManager(_ *confmap.Conf) (*Manager, error) {
// the given input config map are resolved to actual literal values of the env vars or config sources.
// This method must be called only once per lifetime of a Manager object.
func (m *Manager) Resolve(ctx context.Context, configMap *confmap.Conf) (*confmap.Conf, error) {
res := confmap.New()
out := make(map[string]interface{})
allKeys := configMap.AllKeys()
for _, k := range allKeys {
if strings.HasPrefix(k, configSourcesKey) {
Expand All @@ -209,10 +209,10 @@ func (m *Manager) Resolve(ctx context.Context, configMap *confmap.Conf) (*confma
if err != nil {
return nil, err
}
res.Set(k, value)
out[k] = value
}

return res, nil
return confmap.NewFromStringMap(out), nil
}

// WatchForUpdate must watch for updates on any of the values retrieved from config sources
Expand Down
2 changes: 1 addition & 1 deletion confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (l *Conf) Get(key string) interface{} {
return l.k.Get(key)
}

// Set sets the value for the key.
// Deprecated: [v0.53.0] use "Merge" or construct a map[string]interface{}.
func (l *Conf) Set(key string, value interface{}) {
// koanf doesn't offer a direct setting mechanism so merging is required.
merged := koanf.New(KeyDelimiter)
Expand Down
7 changes: 3 additions & 4 deletions confmap/confmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
"gopkg.in/yaml.v3"
)

func TestToStringMap_WithSet(t *testing.T) {
parser := New()
parser.Set("key::embedded", int64(123))
assert.Equal(t, map[string]interface{}{"key": map[string]interface{}{"embedded": int64(123)}}, parser.ToStringMap())
func TestToStringMapFlatten(t *testing.T) {
conf := NewFromStringMap(map[string]interface{}{"key::embedded": int64(123)})
assert.Equal(t, map[string]interface{}{"key": map[string]interface{}{"embedded": int64(123)}}, conf.ToStringMap())
}

func TestToStringMap(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions confmap/converter/expandconverter/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func New() confmap.Converter {
}

func (converter) Convert(_ context.Context, conf *confmap.Conf) error {
out := make(map[string]interface{})
for _, k := range conf.AllKeys() {
conf.Set(k, expandStringValues(conf.Get(k)))
out[k] = expandStringValues(conf.Get(k))
}
return nil
return conf.Merge(confmap.NewFromStringMap(out))
}

func expandStringValues(value interface{}) interface{} {
Expand Down
9 changes: 3 additions & 6 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,11 @@ func TestCollectorFailedShutdown(t *testing.T) {
// mapConverter applies extraMap of config settings. Useful for overriding the config
// for testing purposes. Keys must use "::" delimiter between levels.
type mapConverter struct {
extraMap map[string]*string
extraMap map[string]interface{}
}

func (m mapConverter) Convert(ctx context.Context, conf *confmap.Conf) error {
for k, v := range m.extraMap {
conf.Set(k, v)
}
return nil
return conf.Merge(confmap.NewFromStringMap(m.extraMap))
}

type labelState int
Expand Down Expand Up @@ -299,7 +296,7 @@ func testCollectorStartHelper(t *testing.T, telemetry collectorTelemetryExporter
})

// Prepare config properties to be merged with the main config.
extraCfgAsProps := map[string]*string{
extraCfgAsProps := map[string]interface{}{
// Set the metrics address to expose own metrics on.
"service::telemetry::metrics::address": &metricsAddr,
}
Expand Down