From e59eb00ce1f671e1137c44f21eecc973e9b6a9d0 Mon Sep 17 00:00:00 2001 From: Violet Hynes Date: Thu, 10 Jul 2025 17:19:01 -0400 Subject: [PATCH] Fix issue with merging observations config (#31248) --- command/server/config.go | 4 ++-- command/server/config_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index eff210ab30..12f09df0dd 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -447,8 +447,8 @@ func (c *Config) Merge(c2 *Config) *Config { if c2.Observations.LedgerPath != "" { result.Observations.LedgerPath = c2.Observations.LedgerPath } - result.Observations.TypePrefixDenylist = append(c.Observations.TypePrefixDenylist, c2.Observations.TypePrefixDenylist...) - result.Observations.TypePrefixAllowlist = append(c.Observations.TypePrefixAllowlist, c2.Observations.TypePrefixAllowlist...) + result.Observations.TypePrefixDenylist = append(result.Observations.TypePrefixDenylist, c2.Observations.TypePrefixDenylist...) + result.Observations.TypePrefixAllowlist = append(result.Observations.TypePrefixAllowlist, c2.Observations.TypePrefixAllowlist...) if c2.Observations.FileMode != "" { result.Observations.FileMode = c2.Observations.FileMode } diff --git a/command/server/config_test.go b/command/server/config_test.go index a3d7205b31..7f12def700 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -139,6 +139,27 @@ func Test_ObservationSystemConfigMerge(t *testing.T) { require.Equal(t, "0777", merged.Observations.FileMode) } +// Test_ObservationSystemConfigMergeFromNoObservations checks merge for observation system config from a config +// without an observation system defined +func Test_ObservationSystemConfigMergeFromNoObservations(t *testing.T) { + config, err := LoadConfigFile("./test-fixtures/config.hcl") + require.NoError(t, err) + require.NotNil(t, config) + + config2, err := LoadConfigFile("./test-fixtures/observations_allow_deny.hcl") + require.NoError(t, err) + require.NotNil(t, config2) + + merged := config.Merge(config2) + require.NotNil(t, merged) + require.NotNil(t, merged.Observations) + require.Equal(t, "/var/ledger.log", merged.Observations.LedgerPath) + require.Equal(t, []string{"deny1", "deny2"}, merged.Observations.TypePrefixDenylist) + require.Equal(t, []string{"allow1", "allow2", "allow3"}, merged.Observations.TypePrefixAllowlist) + require.Equal(t, "0777", merged.Observations.FileMode) + require.Equal(t, true, merged.EnableUI) +} + // TestDuplicateKeyValidationHcl checks that the server command displays a warning when the HCL config file contains duplicate keys. func TestDuplicateKeyValidationHcl(t *testing.T) { testDuplicateKeyValidationHcl(t)