Skip to content

Commit

Permalink
Deprecate confmap.Conf.Set, not used anywhere for the moment (#5485)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Jun 7, 2022
1 parent 09cb558 commit 0bc2777
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,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
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
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
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
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
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

0 comments on commit 0bc2777

Please sign in to comment.