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

feat(ConfigProvider): Modify config merge to do replace instead of update for Specific tags #1604

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
04f6cb0
Update provider.go
jagan2221 Jun 11, 2024
28013f4
Update provider.go
jagan2221 Jun 13, 2024
64d9df3
Create utils.go
jagan2221 Jun 13, 2024
5be51e6
Create go.mod
jagan2221 Jun 13, 2024
bf94cab
Update provider.go
jagan2221 Jun 13, 2024
f47b831
link util with providers
jagan2221 Jun 13, 2024
6d7f86e
move common util to providerutils package
jagan2221 Jun 13, 2024
3ffa983
refactor
jagan2221 Jun 13, 2024
4b39061
build err
jagan2221 Jun 13, 2024
0a5c12d
pkg/configprovider/opampprovider/go.mod
jagan2221 Jun 13, 2024
f95b34d
Update pkg/configprovider/opampprovider/provider.go
jagan2221 Jun 26, 2024
a136bff
check while key path while removing fields+ add test cases
jagan2221 Jun 26, 2024
44125f6
Merge branch 'j_config_merge_override' of https://github.com/SumoLogi…
jagan2221 Jun 26, 2024
3ea8f1b
Update pkg/configprovider/providerutil/utils.go
jagan2221 Jun 27, 2024
d80a304
Review changes
jagan2221 Jul 2, 2024
e0912f9
Update utils.go
jagan2221 Jul 2, 2024
6f4ac0b
Create 1604.changed.txt
jagan2221 Jul 3, 2024
c49cc08
Delete .changelog/.changelog directory
jagan2221 Jul 3, 2024
083e81e
Add files via upload
jagan2221 Jul 3, 2024
6a6cefe
Update utils.go
jagan2221 Jul 3, 2024
98ba5ac
Add makefile
jagan2221 Jul 3, 2024
055013f
Rename Makefile.txt to Makefile
jagan2221 Jul 3, 2024
dccff3b
add mod file for providerUtil
jagan2221 Jul 3, 2024
3e177fc
goimports refactror
jagan2221 Jul 3, 2024
850f7e7
goimports refactor
jagan2221 Jul 3, 2024
e1079be
refactor UT
jagan2221 Jul 4, 2024
8d96491
Update .changelog/1604.changed.txt
jagan2221 Jul 4, 2024
ae4bcc8
Rename 1604.changed.txt to 1604.breaking.txt
jagan2221 Jul 4, 2024
438ce8a
Update upgrading.md- breaking changes for config merge flow change
jagan2221 Jul 4, 2024
0b88b1e
Update upgrading.md(review changes)
jagan2221 Jul 5, 2024
a3e3261
Merge branch 'main' into j_config_merge_override
jagan2221 Jul 5, 2024
c3aa5ec
Update docs/upgrading.md
jagan2221 Jul 9, 2024
1f4d959
Update utils.go
jagan2221 Jul 10, 2024
4f3acc5
Merge branch 'main' into j_config_merge_override
jagan2221 Jul 16, 2024
3bea173
Update upgrading.md
jagan2221 Jul 16, 2024
4a81307
Update utils.go
jagan2221 Jul 16, 2024
89df819
Update utils.go
jagan2221 Jul 17, 2024
15c02ee
Update utils.go
jagan2221 Jul 17, 2024
47883a8
Merge branch 'main' into j_config_merge_override
jagan2221 Jul 30, 2024
3e13dd3
Update upgrading.md
jagan2221 Aug 1, 2024
3f931b9
Update opamp_agent.go
jagan2221 Aug 30, 2024
34103e8
Update opamp_agent.go
jagan2221 Sep 16, 2024
dfe9f87
Simulate en error to see how agent behaves
jagan2221 Sep 17, 2024
844457a
Update opamp_agent.go
jagan2221 Sep 17, 2024
d0819b4
Update opamp_agent.go
jagan2221 Sep 20, 2024
46c3e56
Update opamp_agent.go
jagan2221 Sep 20, 2024
e01d6ad
Update opamp_agent.go
jagan2221 Sep 20, 2024
473f940
Update components.go
jagan2221 Sep 20, 2024
3cfeed2
Update go.mod
jagan2221 Sep 20, 2024
c2f28b6
Update go.sum
jagan2221 Sep 20, 2024
6bc6400
Merge branch 'main' into j_config_merge_override
jagan2221 Sep 20, 2024
4f327e4
Update opamp_agent.go
jagan2221 Sep 20, 2024
168c20e
Update components.go
jagan2221 Sep 20, 2024
25ec054
Update go.sum
jagan2221 Sep 20, 2024
595308d
Update go.mod
jagan2221 Sep 20, 2024
d10bb30
Update opamp_agent.go
jagan2221 Sep 20, 2024
a041740
Update opamp_agent.go
jagan2221 Sep 20, 2024
9faba5c
Update opamp_agent.go
jagan2221 Sep 20, 2024
388c38a
Update opamp_agent.go
jagan2221 Sep 20, 2024
ac2d872
Update opamp_agent.go
jagan2221 Oct 1, 2024
975f321
Update opamp_agent.go
jagan2221 Oct 1, 2024
b238169
Merge branch 'main' into j_config_merge_override
jagan2221 Oct 17, 2024
be003c7
Update go.sum
jagan2221 Oct 17, 2024
3c1007b
Update opamp_agent.go
jagan2221 Oct 17, 2024
b920ccb
Update upgrading.md
jagan2221 Oct 17, 2024
58ec38e
Update upgrading.md
jagan2221 Oct 22, 2024
d9014a7
enable tag edit config merge flow change only for remotely managed co…
jagan2221 Nov 13, 2024
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/1604.breaking.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat(ConfigProvider)!: Modify config merge to do replace instead of update for Specific tags
75 changes: 75 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- [Upgrading to v0.104.0-sumo-0](#upgrading-to-v01040-sumo-0)
- [`sumologic` exporter: remove `compress_encoding`](#sumologic-exporter-remove-compress_encoding)
- [Upgrading to v0.103.0-sumo-0](#upgrading-to-v01030-sumo-0)
- [`sumologic` configuration: modified the `configuration files` merge behaviour](#sumologic-configuration-modified-the-configuration-files-merge-behaviour)
- [Upgrading to v0.96.0-sumo-0](#upgrading-to-v0960-sumo-0)
- [`sumologic` exporter: remove `json_logs`](#sumologic-exporter-remove-json_logs)
- [`sumologic` exporter: remove `clear_logs_timestamp`](#sumologic-exporter-remove-clear_logs_timestamp)
Expand Down Expand Up @@ -81,6 +83,79 @@ to this:
compression: ""
```

## Upgrading to v0.103.0-sumo-0
jagan2221 marked this conversation as resolved.
Show resolved Hide resolved

### `sumologic` configuration: modified the `configuration files` merge behaviour

Modified the configuration merge behaviour to perform overwrite instead of update for `collector_fields` key of [Sumo Logic Extension](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/sumologicextension#configuration).

For example, if two configuration files(say `conf1.yaml` and `conf2.yaml`) define the `collector_fields`,

In previous flow, the values of `collector_fields` from `conf2.yaml` will be added to `conf1.yaml` and the effective configuration will have vaules from both the configurations.

Starting from `v0.103.0-sumo-0`, the values of `collector_fields` tag from `conf1.yaml` will be overwritten by values from `conf2.yaml` and the effective configuration will have `collector_fields` value of `conf2.yaml` only.

For example:

`conf1.yaml`:

```
extensions:
sumologic:
collector_description: "My OpenTelemetry Collector"
collector_fields:
cluster: "cluster-1"
some_list:
- element 1
- element 2
```

`conf2.yaml`:

```
extensions:
sumologic:
collector_fields:
zone: "eu"
some_list:
- element 3
- element 4
```

effective configuration (`old behaviour`)

```
extensions:
sumologic:
collector_description: "My OpenTelemetry Collector"
collector_fields:
cluster: "cluster-1"
zone: "eu"
some_list:
- element 3
- element 4
```

effective configuration (`new behaviour`)
jagan2221 marked this conversation as resolved.
Show resolved Hide resolved

```
extensions:
sumologic:
collector_description: "My OpenTelemetry Collector"
collector_fields:
zone: "eu"
some_list:
- element 3
- element 4
```

If you have multiple config files with `collector_fields` key specified, only the value from the last file(**alphabetically** sorted order) will be present in effective configuration.
Due to above, avoid maintaining `collector_fields` in multiple configuration files and move them to a single file.

Note: This applies only to `collector_fields` key, all other key behaviour will remain the same.

For more details regarding configuration structure and merge behaviour, see https://help.sumologic.com/docs/send-data/opentelemetry-collector/data-source-configurations/overview/#configuration-structure

## Upgrading to v0.96.0-sumo-0

### `sumologic` exporter: remove `json_logs`
Expand Down
1 change: 1 addition & 0 deletions otelcolbuilder/.otelcol-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,4 @@ replaces:
- github.com/SumoLogic/sumologic-otel-collector/pkg/extension/opampextension => ../../pkg/extension/opampextension
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/globprovider => ../../pkg/configprovider/globprovider
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/opampprovider => ../../pkg/configprovider/opampprovider
- github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil => ../../pkg/configprovider/providerutil
3 changes: 3 additions & 0 deletions pkg/configprovider/globprovider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.0
toolchain go1.22.3

require (
github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/confmap v0.104.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -24,3 +25,5 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
)

replace github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil => ../providerutil
7 changes: 4 additions & 3 deletions pkg/configprovider/globprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"sort"
"strings"

"gopkg.in/yaml.v3"

"github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil"
"go.opentelemetry.io/collector/confmap"
"gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -68,11 +68,12 @@ func (fmp *provider) Retrieve(ctx context.Context, uri string, _ confmap.Watcher
return &confmap.Retrieved{}, err
}
pathConf := confmap.NewFromStringMap(rawConf)
providerutil.PrepareForReplaceBehavior(conf, pathConf)
if err := conf.Merge(pathConf); err != nil {
return &confmap.Retrieved{}, err
}
}

}
return confmap.NewRetrieved(conf.ToStringMap())
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/configprovider/opampprovider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.3

require (
github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/globprovider v0.0.0-00010101000000-000000000000
github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil v0.0.0-00010101000000-000000000000
github.com/google/go-cmp v0.5.9
go.opentelemetry.io/collector/confmap v0.104.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.104.0
Expand All @@ -27,3 +28,5 @@ require (
)

replace github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/globprovider => ../globprovider

replace github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil => ../providerutil
4 changes: 4 additions & 0 deletions pkg/configprovider/opampprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/globprovider"
"github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -100,6 +101,9 @@ func (p *Provider) Retrieve(ctx context.Context, configPath string, fn confmap.W
if err != nil {
return nil, err
}
// Order of conf parameters is important, see method comments
providerutil.PrepareForReplaceBehavior(addlConf, retConf)

// merge the file config in
if err := conf.Merge(addlConf); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/configprovider/providerutil/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
24 changes: 24 additions & 0 deletions pkg/configprovider/providerutil/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/SumoLogic/sumologic-otel-collector/pkg/configprovider/providerutil

go 1.21.0

toolchain go1.22.3

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/confmap v0.102.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
30 changes: 30 additions & 0 deletions pkg/configprovider/providerutil/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU=
github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU=
github.com/knadh/koanf/v2 v2.1.1 h1:/R8eXqasSTsmDCsAyYj+81Wteg8AqrV9CP6gvsTsOmM=
github.com/knadh/koanf/v2 v2.1.1/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/collector/confmap v0.102.1 h1:wZuH+d/P11Suz8wbp+xQCJ0BPE9m5pybtUe74c+rU7E=
go.opentelemetry.io/collector/confmap v0.102.1/go.mod h1:KgpS7UxH5rkd69CzAzlY2I1heH8Z7eNCZlHmwQBMxNg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
44 changes: 44 additions & 0 deletions pkg/configprovider/providerutil/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package providerutil

import (
"go.opentelemetry.io/collector/confmap"
)

// Removes the key(path passed in keys array) from sourceMap if same key path is present in MergeMap
func removeMatchingKeyFromSrcMap(srcMap map[string]interface{}, mergeMap map[string]interface{}, keys []string) map[string]interface{} {

if len(keys) == 0 {
return srcMap
}

currentKey := keys[0]
if len(keys) == 1 { // Got Leaf key, if leaf key exists in both maps, remove it from source map
_, existInSrc := srcMap[currentKey]
_, existInMerge := mergeMap[currentKey]
// If leaf key exists in both maps, remove from source map
if existInSrc && existInMerge {
delete(srcMap, currentKey)
}
jagan2221 marked this conversation as resolved.
Show resolved Hide resolved
return srcMap
}
// More levels to go, descend into child if current key present in both maps
srcNestedMap, isCurrKeyInSrcMap := srcMap[currentKey].(map[string]interface{})
mergeNestedMap, isCurrKeyInMergeMap := mergeMap[currentKey].(map[string]interface{})
if isCurrKeyInSrcMap && isCurrKeyInMergeMap {
removeMatchingKeyFromSrcMap(srcNestedMap, mergeNestedMap, keys[1:])
rnishtala-sumo marked this conversation as resolved.
Show resolved Hide resolved
}
return srcMap
}

// Checks and prepares scrConf for replace behavior instead of map merge
// Hack for confmap.Conf.Merge method to replace specific fields instead of merging them
// Merge method merges field values from source and mergeConf, so by removing existing values from
// source map, we can achieve replace behavior
func PrepareForReplaceBehavior(srcConf *confmap.Conf, mergeConf *confmap.Conf) {
keyPathsWithReplaceBehavior := [][]string{
{"extensions", "sumologic", "collector_fields"},
}
for _, keyPath := range keyPathsWithReplaceBehavior {
*srcConf = *confmap.NewFromStringMap(removeMatchingKeyFromSrcMap(srcConf.ToStringMap(), mergeConf.ToStringMap(), keyPath))
}
}
91 changes: 91 additions & 0 deletions pkg/configprovider/providerutil/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package providerutil

import (
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/confmap"
)

func TestPrepareForReplaceBehavior(t *testing.T) {
tests := []struct {
name string
srcConf *confmap.Conf
mergeConf *confmap.Conf
expectedConf *confmap.Conf
}{
{
name: "Remove matching key path from source map",
srcConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"childKey2": "value2",
"collector_fields": map[string]interface{}{
"cluster": "cluster-1",
},
},
},
"anotherKey": "anotherValue",
}),
mergeConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"collector_fields": map[string]interface{}{
"zone": "eu",
},
"childKey2": "value2",
},
},
"anotherKey": "anotherValue",
}),
expectedConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"childKey2": "value2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't "zone": "eu" the expected field here?

Copy link
Contributor Author

@jagan2221 jagan2221 Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added just some random sample test values. Do you think we should have specific values here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I don't understand the assertion here. My questions are

  • why doesn't the expected config have any collector_fields.
  • why are we removing "cluster": "cluster-1" from the src/original conf? and why isn't collector_fields from mergeConf in the expected result?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagan2221 would appreciate clarification here, maybe I'm missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagan2221 could we clarify this?

Copy link
Contributor

@chan-tim-sumo chan-tim-sumo Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with Raj, the expected config should have collector_fields 🤔 i remember there was a sumo documentation showing the merge functionality, think it was this:

https://help.sumologic.com/docs/send-data/opentelemetry-collector/data-source-configurations/overview/#configuration-structure:~:text=Note%20that%20the%20list%20has%20been%20overridden%20and%20maps%20have%20been%20merged.

},
},
"anotherKey": "anotherValue",
}),
},
{
name: "No matching key paths to remove, source map remains unaffected",
srcConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"collector_fields1": map[string]interface{}{
"cluster": "cluster-1",
},
},
},
"anotherKey": "anotherValue",
}),
mergeConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"collector_fields2": map[string]interface{}{
"zone": "eu",
},
},
},
"anotherKey": "anotherValue",
}),
expectedConf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": map[string]interface{}{
"sumologic": map[string]interface{}{
"collector_fields1": map[string]interface{}{
"cluster": "cluster-1",
},
},
},
"anotherKey": "anotherValue",
}),
},
}

for _, tt := range tests {
rnishtala-sumo marked this conversation as resolved.
Show resolved Hide resolved
t.Run(tt.name, func(t *testing.T) {
PrepareForReplaceBehavior(tt.srcConf, tt.mergeConf)
assert.Equal(t, tt.expectedConf, tt.srcConf)
})
}
}
Loading