Files
telemetry/confmap/testdata/merge-append-scenarios-featuregate-disabled.yaml
Vihas MakwanaandGitHub a60b77972a [confmap] - new feature flag for append merging strategy (#12097)
Koanf's default merging strategy currently overrides static values such
as slices, numbers, and strings. However, lists of components should be
treated as a special case. This pull request introduces a new command
line option to allow for merging lists instead of discarding the
existing ones.

With this new merging strategy:
- All the lists are merged rather than replaced.
- The merging logic is name-aware, meaning that if components with the
same name appear in both lists, they will only appear once in the final
merged list.

<!-- Issue number if applicable -->
#### Link to tracking issue
Related issues:
- https://github.com/open-telemetry/opentelemetry-collector/issues/8754
- https://github.com/open-telemetry/opentelemetry-collector/issues/8394
- https://github.com/open-telemetry/opentelemetry-collector/issues/10370

<!--Describe what testing was performed and which tests were added.-->
#### Testing
- Added

<!--Describe the documentation added.-->
#### Documentation
- Added under readme.


##### Example
Consider the following configs,

```yaml
# main.yaml
receivers:
  otlp/in:
processors:
  batch:
exporters:
  otlp/out:
extensions:
  file_storage:

service:
  pipelines:
    traces:
      receivers: [ otlp/in ]
      processors: [ batch ]
      exporters: [ otlp/out ]
  extensions: [ file_storage ]
```


```yaml
# extra_extension.yaml
extensions:
  healthcheckv2:

service:
  extensions: [ healthcheckv2 ]
```

If you run the collector with following command,
```
otelcol --config=main.yaml --config=extra_extension.yaml --feature-gates=-confmap.enableMergeAppendOption
```
then the final configuration after config resolution will look like
following:

```yaml
# main.yaml
receivers:
  otlp/in:
processors:
  batch:
exporters:
  otlp/out:
extensions:
  file_storage:
  healthcheckv2:

service:
  pipelines:
    traces:
      receivers: [ otlp/in ]
      processors: [ batch ]
      exporters: [ otlp/out ]
  extensions: [ file_storage, healthcheckv2 ]
```

For backward compatibly, the default behaviour is **not** to merge
lists. Users who want to explicitly merge lists can enable the command
line option.

Note: I’d appreciate your feedback on this šŸ™
2025-03-04 09:56:22 +00:00

210 lines
3.7 KiB
YAML

- name: merge-mode-default
configs:
-
receivers:
nop:
nop/myreceiver:
processors:
nop:
nop/myprocessor:
exporters:
nop:
nop/myexporter:
extensions:
nop:
nop/myextension:
service:
extensions: [nop]
pipelines:
traces:
receivers: [nop]
processors: [nop]
exporters: [nop]
-
receivers:
nop2:
exporters:
nop2:
extensions:
nop2:
service:
extensions: [nop2]
pipelines:
traces:
receivers: [nop2]
processors: [nop2]
exporters: [nop2]
expected:
receivers:
nop2:
nop:
nop/myreceiver:
exporters:
nop2:
nop:
nop/myexporter:
processors:
nop:
nop/myprocessor:
extensions:
nop2:
nop:
nop/myextension:
service:
extensions: [nop2]
pipelines:
traces:
receivers: [nop2]
processors: [nop2]
exporters: [nop2]
- name: merge-mode-append
append_paths: ["service"]
configs:
-
receivers:
nop:
key: val
processors:
nop:
exporters:
nop:
key: 2
extensions:
nop:
service:
extensions: [nop]
pipelines:
traces:
receivers: [nop]
processors: [nop]
exporters: [nop]
-
receivers:
nop2:
exporters:
nop2:
nop:
key: updated_value
extensions:
nop2:
service:
extensions: [nop2]
pipelines:
traces:
receivers: [nop2]
processors: [nop2]
exporters: [nop2]
expected:
receivers:
nop2:
nop:
key: val
exporters:
nop2:
nop:
key: updated_value
processors:
nop:
extensions:
nop2:
nop:
service:
extensions: [nop2]
pipelines:
traces:
receivers: [nop2]
processors: [nop2]
exporters: [nop2]
- name: merge-mode-append-override-old-values
append_paths: ["service"]
configs:
-
receivers:
nop:
key1: "value"
key2: 1
processors:
nop:
exporters:
nop:
extensions:
nop:
ext:
key: 1
service:
extensions: [nop, ext]
pipelines:
traces:
receivers: [nop]
processors: [nop]
exporters: [nop]
-
receivers:
nop2:
exporters:
nop2:
extensions:
ext:
key: 2
service:
extensions: [ext]
pipelines:
traces:
receivers: [nop2]
exporters: [nop2]
expected:
receivers:
nop:
key1: "value"
key2: 1
nop2:
exporters:
nop2:
nop:
processors:
nop:
extensions:
nop:
ext:
key: 2
service:
extensions: [ext]
pipelines:
traces:
receivers: [nop2]
processors: [nop]
exporters: [nop2]