Skip to content

Commit 24b9e2c

Browse files
committed
Merge configs section by section
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
1 parent 8ebffec commit 24b9e2c

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

services/server/config/config.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,27 @@ func resolveImports(parent string, imports []string) ([]string, error) {
297297
// 0 1 1
298298
// []{"1"} []{"2"} []{"1","2"}
299299
// []{"1"} []{} []{"1"}
300+
// Maps merged by keys, but values are replaced entirely.
300301
func mergeConfig(to, from *Config) error {
301-
return mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
302+
err := mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
303+
if err != nil {
304+
return err
305+
}
306+
307+
// Replace entire sections instead of merging map's values.
308+
for k, v := range from.Plugins {
309+
to.Plugins[k] = v
310+
}
311+
312+
for k, v := range from.StreamProcessors {
313+
to.StreamProcessors[k] = v
314+
}
315+
316+
for k, v := range from.ProxyPlugins {
317+
to.ProxyPlugins[k] = v
318+
}
319+
320+
return nil
302321
}
303322

304323
// V1DisabledFilter matches based on ID

services/server/config/config_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ import (
2929

3030
func TestMergeConfigs(t *testing.T) {
3131
a := &Config{
32-
Version: 2,
33-
Root: "old_root",
34-
RequiredPlugins: []string{"old_plugin"},
35-
DisabledPlugins: []string{"old_plugin"},
36-
State: "old_state",
37-
OOMScore: 1,
38-
Timeouts: map[string]string{"a": "1"},
32+
Version: 2,
33+
Root: "old_root",
34+
RequiredPlugins: []string{"old_plugin"},
35+
DisabledPlugins: []string{"old_plugin"},
36+
State: "old_state",
37+
OOMScore: 1,
38+
Timeouts: map[string]string{"a": "1"},
39+
StreamProcessors: map[string]StreamProcessor{"1": {Path: "2", Returns: "4"}, "2": {Path: "5"}},
3940
}
4041

4142
b := &Config{
42-
Root: "new_root",
43-
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
44-
OOMScore: 2,
45-
Timeouts: map[string]string{"b": "2"},
43+
Root: "new_root",
44+
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
45+
OOMScore: 2,
46+
Timeouts: map[string]string{"b": "2"},
47+
StreamProcessors: map[string]StreamProcessor{"1": {Path: "3"}},
4648
}
4749

4850
err := mergeConfig(a, b)
@@ -55,6 +57,7 @@ func TestMergeConfigs(t *testing.T) {
5557
assert.DeepEqual(t, a.RequiredPlugins, []string{"old_plugin", "new_plugin1", "new_plugin2"})
5658
assert.DeepEqual(t, a.DisabledPlugins, []string{"old_plugin"})
5759
assert.DeepEqual(t, a.Timeouts, map[string]string{"a": "1", "b": "2"})
60+
assert.DeepEqual(t, a.StreamProcessors, map[string]StreamProcessor{"1": {Path: "3"}, "2": {Path: "5"}})
5861
}
5962

6063
func TestResolveImports(t *testing.T) {

0 commit comments

Comments
 (0)