Skip to content

Commit 5a9dbb5

Browse files
authored
[chore][confma] minor refactor of enableMergeAppendOption feature gate (#12976)
@mx-psi @dmitryax While working on my RFC, I realized that we can simplify the logic by moving the merge behavior into `conf.Merge`. Currently, the feature gate check happens externally, and we choose the merge option based on that. This PR moves the check inside `conf.Merge`. By doing this [converters](https://github.com/open-telemetry/opentelemetry-collector/blob/main/confmap/README.md) can also make use of this feature. There are no changes to any API signatures, so this doesn’t introduce any breaking changes. Let me know what you think about this.
1 parent 4aaf5ee commit 5a9dbb5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

confmap/confmap.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func (l *Conf) IsSet(key string) bool {
173173
// Merge merges the input given configuration into the existing config.
174174
// Note that the given map may be modified.
175175
func (l *Conf) Merge(in *Conf) error {
176+
if enableMergeAppendOption.IsEnabled() {
177+
// only use MergeAppend when enableMergeAppendOption featuregate is enabled.
178+
return l.mergeAppend(in)
179+
}
176180
return l.k.Merge(in.k)
177181
}
178182

confmap/resolver.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,8 @@ func (mr *Resolver) Resolve(ctx context.Context) (*Conf, error) {
183183
if err != nil {
184184
return nil, err
185185
}
186-
if enableMergeAppendOption.IsEnabled() {
187-
// only use MergeAppend when enableMergeAppendOption featuregate is enabled.
188-
err = retMap.mergeAppend(retCfgMap)
189-
} else {
190-
err = retMap.Merge(retCfgMap)
191-
}
192-
if err != nil {
186+
187+
if err := retMap.Merge(retCfgMap); err != nil {
193188
return nil, err
194189
}
195190
}

0 commit comments

Comments
 (0)