diff --git a/internal/confmapprovider/discovery/README.md b/internal/confmapprovider/discovery/README.md index 7b2fd436fe..53a84b88b9 100644 --- a/internal/confmapprovider/discovery/README.md +++ b/internal/confmapprovider/discovery/README.md @@ -125,6 +125,25 @@ splunk.discovery.extensions.k8s_observer.enabled: false These properties can be in `config.d/properties.discovery.yaml` or specified at run time with `--set` command line options. +The `config.d/properties.discovery.yaml` file supports specifying the property values directly as well within a mapped form: + +```yaml +# --set form will take priority to mapped values +splunk.discovery.receivers.prometheus_simple.config.labels::my_label: my_label_value +splunk.discovery.receivers.prometheus_simple.enabled: true + +# mapped property form +splunk.discovery: + extensions: + docker_observer: + enabled: false + config: + endpoint: tcp://localhost:54321 + receivers: + prometheus_simple: + enabled: false # will be overwritten by above --set form (discovery is attempted for the receiver) +``` + Each discovery property also has an equivalent environment variable form using `_x_` encoded delimiters for non-word characters `[^a-zA-Z0-9_]`: @@ -142,9 +161,11 @@ SPLUNK_DISCOVERY_EXTENSIONS_docker_observer_CONFIG_endpoint="tcp://localhost:808 SPLUNK_DISCOVERY_EXTENSIONS_k8s_observer_ENABLED=false ``` -The priority order for discovery config content from lowest to highest is: +The priority order for discovery config values from lowest to highest is: -1. `config.d//*.discovery.yaml` file content (lowest). -2. `config.d/properties.discovery.yaml` file content. -3. `SPLUNK_DISCOVERY_` environment variables available to the collector process. -4. `--set splunk.discovery.` commandline options (highest). +1. Pre-made `bundle.d` component config content (lowest). +2. `config.d//*.discovery.yaml` component config file content. +3. `config.d/properties.discovery.yaml` properties file mapped form content. +4. `config.d/properties.discovery.yaml` properties file --set form content. +5. `SPLUNK_DISCOVERY_` property environment variables available to the collector process. +6. `--set splunk.discovery.` property commandline options (highest). diff --git a/internal/confmapprovider/discovery/discoverer.go b/internal/confmapprovider/discovery/discoverer.go index 382795fe4a..45c6e26695 100644 --- a/internal/confmapprovider/discovery/discoverer.go +++ b/internal/confmapprovider/discovery/discoverer.go @@ -44,6 +44,7 @@ import ( "github.com/signalfx/splunk-otel-collector/internal/common/discovery" "github.com/signalfx/splunk-otel-collector/internal/components" + "github.com/signalfx/splunk-otel-collector/internal/confmapprovider/discovery/internal" "github.com/signalfx/splunk-otel-collector/internal/confmapprovider/discovery/properties" "github.com/signalfx/splunk-otel-collector/internal/receiver/discoveryreceiver" "github.com/signalfx/splunk-otel-collector/internal/version" @@ -401,7 +402,7 @@ func (d *discoverer) updateReceiverForObserver(receiverID component.ID, receiver } if hasObserverConfigBlock { if hasDefault { - if err := mergeMaps(defaultConfig, observerConfigBlock); err != nil { + if err := internal.MergeMaps(defaultConfig, observerConfigBlock); err != nil { return false, fmt.Errorf("failed merging %q config for %q: %w", receiverID, observerID, err) } } else { @@ -709,19 +710,17 @@ func (d *discoverer) ConsumeLogs(_ context.Context, ld plog.Logs) error { // Priority is discovery.properties.yaml < env var properties < --set properties. --set and env var properties // are already resolved at this point. func (d *discoverer) mergeDiscoveryPropertiesEntry(cfg *Config) error { - props := map[string]any{} - for k, v := range cfg.DiscoveryProperties.Entry { - if prop, err := properties.NewProperty(k, fmt.Sprintf("%s", v)); err != nil { - d.logger.Warn(fmt.Sprintf("invalid discovery property %q", k), zap.Error(err)) - } else { - mergeMaps(props, prop.ToStringMap()) - } + conf, warning, fatal := properties.LoadConf(cfg.DiscoveryProperties.ToStringMap()) + if fatal != nil { + return fatal + } + if warning != nil { + d.logger.Warn("invalid discovery properties will be disregarded", zap.Error(warning)) } - fileProps := confmap.NewFromStringMap(props) - if err := fileProps.Merge(d.propertiesConf); err != nil { + if err := conf.Merge(d.propertiesConf); err != nil { return err } - d.propertiesConf = fileProps + d.propertiesConf = conf return nil } @@ -738,15 +737,3 @@ func determineCurrentStatus(current, observed discovery.StatusType) discovery.St } return current } - -func mergeMaps(dst, src map[string]any) error { - dstMap := confmap.NewFromStringMap(dst) - srcMap := confmap.NewFromStringMap(src) - if err := dstMap.Merge(srcMap); err != nil { - return err - } - for k, v := range dstMap.ToStringMap() { - dst[k] = v - } - return nil -} diff --git a/internal/confmapprovider/discovery/discoverer_test.go b/internal/confmapprovider/discovery/discoverer_test.go index b5abdb973e..1d07309619 100644 --- a/internal/confmapprovider/discovery/discoverer_test.go +++ b/internal/confmapprovider/discovery/discoverer_test.go @@ -21,9 +21,7 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/confmap" "go.uber.org/zap" "go.uber.org/zap/zaptest/observer" @@ -69,81 +67,6 @@ func TestDiscovererDurationFromEnv(t *testing.T) { }, 2*time.Second, time.Millisecond) } -func TestMergeEntries(t *testing.T) { - a := confmap.NewFromStringMap(map[string]any{}) - b := confmap.NewFromStringMap(map[string]any{}) - a.Merge(b) - - first := map[string]any{ - "one.key": "one.val", - "two.key": "two.val", - } - second := map[string]any{ - "three.key": "three.val", - "four.key": map[any]any{ - "four.a.key": "four.a.val", - "four.b.key": "four.b.val", - }, - } - err := mergeMaps(first, second) - assert.NoError(t, err) - require.Equal(t, map[string]any{ - "one.key": "one.val", - "two.key": "two.val", - "three.key": "three.val", - "four.key": map[string]any{ - "four.a.key": "four.a.val", - "four.b.key": "four.b.val", - }, - }, first) - - third := map[string]any{ - "three.key": "three.val^", - "four.key": map[any]any{ - "four.b.key": "four.b.val^", - "four.c.key": "four.c.val", - }, - } - err = mergeMaps(first, third) - assert.NoError(t, err) - require.Equal(t, map[string]any{ - "one.key": "one.val", - "two.key": "two.val", - "three.key": "three.val^", - "four.key": map[string]any{ - "four.a.key": "four.a.val", - "four.b.key": "four.b.val^", - "four.c.key": "four.c.val", - }, - }, first) - - fourth := map[string]any{ - "four.key": map[any]any{ - "four.c.key": map[any]any{ - "six.key": "six.val", - }, - "four.d.key": "four.d.val", - }, - "five.key": "five.val", - } - err = mergeMaps(first, fourth) - assert.NoError(t, err) - require.Equal(t, map[string]any{ - "one.key": "one.val", - "two.key": "two.val", - "three.key": "three.val^", - "four.key": map[string]any{ - "four.a.key": "four.a.val", - "four.b.key": "four.b.val^", - "four.c.key": map[string]any{ - "six.key": "six.val", - }, - "four.d.key": "four.d.val", - }, - "five.key": "five.val", - }, first) -} - func TestDetermineCurrentStatus(t *testing.T) { for _, test := range []struct { current, observed, expected discovery.StatusType diff --git a/internal/confmapprovider/discovery/internal/utils.go b/internal/confmapprovider/discovery/internal/utils.go new file mode 100644 index 0000000000..880cef4c60 --- /dev/null +++ b/internal/confmapprovider/discovery/internal/utils.go @@ -0,0 +1,29 @@ +// Copyright Splunk, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package internal + +import "go.opentelemetry.io/collector/confmap" + +func MergeMaps(dst, src map[string]any) error { + dstMap := confmap.NewFromStringMap(dst) + srcMap := confmap.NewFromStringMap(src) + if err := dstMap.Merge(srcMap); err != nil { + return err + } + for k, v := range dstMap.ToStringMap() { + dst[k] = v + } + return nil +} diff --git a/internal/confmapprovider/discovery/internal/utils_test.go b/internal/confmapprovider/discovery/internal/utils_test.go new file mode 100644 index 0000000000..0bfee72cd2 --- /dev/null +++ b/internal/confmapprovider/discovery/internal/utils_test.go @@ -0,0 +1,98 @@ +// Copyright Splunk, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package internal + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/confmap" +) + +func TestMergeMaps(t *testing.T) { + a := confmap.NewFromStringMap(map[string]any{}) + b := confmap.NewFromStringMap(map[string]any{}) + a.Merge(b) + + first := map[string]any{ + "one.key": "one.val", + "two.key": "two.val", + } + second := map[string]any{ + "three.key": "three.val", + "four.key": map[any]any{ + "four.a.key": "four.a.val", + "four.b.key": "four.b.val", + }, + } + err := MergeMaps(first, second) + assert.NoError(t, err) + require.Equal(t, map[string]any{ + "one.key": "one.val", + "two.key": "two.val", + "three.key": "three.val", + "four.key": map[string]any{ + "four.a.key": "four.a.val", + "four.b.key": "four.b.val", + }, + }, first) + + third := map[string]any{ + "three.key": "three.val^", + "four.key": map[any]any{ + "four.b.key": "four.b.val^", + "four.c.key": "four.c.val", + }, + } + err = MergeMaps(first, third) + assert.NoError(t, err) + require.Equal(t, map[string]any{ + "one.key": "one.val", + "two.key": "two.val", + "three.key": "three.val^", + "four.key": map[string]any{ + "four.a.key": "four.a.val", + "four.b.key": "four.b.val^", + "four.c.key": "four.c.val", + }, + }, first) + + fourth := map[string]any{ + "four.key": map[any]any{ + "four.c.key": map[any]any{ + "six.key": "six.val", + }, + "four.d.key": "four.d.val", + }, + "five.key": "five.val", + } + err = MergeMaps(first, fourth) + assert.NoError(t, err) + require.Equal(t, map[string]any{ + "one.key": "one.val", + "two.key": "two.val", + "three.key": "three.val^", + "four.key": map[string]any{ + "four.a.key": "four.a.val", + "four.b.key": "four.b.val^", + "four.c.key": map[string]any{ + "six.key": "six.val", + }, + "four.d.key": "four.d.val", + }, + "five.key": "five.val", + }, first) +} diff --git a/internal/confmapprovider/discovery/properties/conf.go b/internal/confmapprovider/discovery/properties/conf.go new file mode 100644 index 0000000000..a43c533cd5 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/conf.go @@ -0,0 +1,125 @@ +// Copyright Splunk, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package properties + +import ( + "fmt" + "sort" + + "go.opentelemetry.io/collector/confmap" + "go.uber.org/multierr" + + "github.com/signalfx/splunk-otel-collector/internal/confmapprovider/discovery/internal" +) + +// File is loaded from properties.discovery.yaml +// and can consist of --set discovery property entries +// as well as a splunk.discovery: property mapping +type File struct { + Mapping `mapstructure:"splunk.discovery"` + Entries map[string]any `mapstructure:",remain"` +} + +type Mapping struct { + Receivers map[string]Entry `mapstructure:"receivers"` + Extensions map[string]Entry `mapstructure:"extensions"` + Unknown map[any]any `mapstructure:",remain"` +} + +type Entry struct { + Config *map[string]any `mapstructure:"config"` + Enabled *bool `mapstructure:"enabled"` + Unknown map[any]any `mapstructure:",remain"` +} + +type propTuple struct { + value any + key string +} + +func LoadConf(raw map[string]any) (properties *confmap.Conf, warning, fatal error) { + file := &File{} + if err := confmap.NewFromStringMap(raw).Unmarshal(file); err != nil { + return nil, nil, err + } + + if len(file.Unknown) > 0 { + var unknownMappings []string + for unknown := range file.Unknown { + unknownMappings = append(unknownMappings, fmt.Sprintf("%v", unknown)) + } + // for testability + sort.Strings(unknownMappings) + for _, unknown := range unknownMappings { + warning = multierr.Combine(warning, fmt.Errorf(`unknown discovery property mapping "splunk.discovery.%v"`, unknown)) + } + } + + // all properties are loaded individually, so we maintain a slice of kv tuples + var props []propTuple + + for _, entry := range []struct { + entry map[string]Entry + typ string + }{ + {typ: "extensions", entry: file.Extensions}, + {typ: "receivers", entry: file.Receivers}, + } { + var unknownMappings []string + for cid, ent := range entry.entry { + prefix := fmt.Sprintf("splunk.discovery.%s.%s", entry.typ, cid) + if ent.Enabled != nil { + props = append(props, propTuple{key: fmt.Sprintf("%s.enabled", prefix), value: *ent.Enabled}) + } + + if ent.Config != nil { + conf := confmap.NewFromStringMap(*ent.Config) + for _, ck := range conf.AllKeys() { + val := conf.Get(ck) + props = append(props, propTuple{key: fmt.Sprintf("%s.config.%s", prefix, ck), value: val}) + } + } + + for unknown := range ent.Unknown { + unknownMappings = append(unknownMappings, fmt.Sprintf("%s.%v", prefix, unknown)) + } + } + + sort.Strings(unknownMappings) + for _, unknown := range unknownMappings { + warning = multierr.Combine(warning, fmt.Errorf("unknown property %q", unknown)) + } + } + + // --set property form has priority to splunk.discovery mappings (processed afterward and overwrites) + entriesConf := confmap.NewFromStringMap(file.Entries) + for _, k := range entriesConf.AllKeys() { + props = append(props, propTuple{key: k, value: entriesConf.Get(k)}) + } + + confProperties := map[string]any{} + + for _, prop := range props { + if p, err := NewProperty(prop.key, fmt.Sprintf("%v", prop.value)); err != nil { + warning = multierr.Combine(warning, err) + } else { + if err = internal.MergeMaps(confProperties, p.ToStringMap()); err != nil { + return nil, warning, fmt.Errorf("failed merging properties.discovery.yaml content: %w", err) + } + } + } + + return confmap.NewFromStringMap(confProperties), warning, nil +} diff --git a/internal/confmapprovider/discovery/properties/conf_test.go b/internal/confmapprovider/discovery/properties/conf_test.go new file mode 100644 index 0000000000..4b7c355cda --- /dev/null +++ b/internal/confmapprovider/discovery/properties/conf_test.go @@ -0,0 +1,115 @@ +// Copyright Splunk, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package properties + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +func TestConf(t *testing.T) { + for _, path := range []string{ + filepath.Join(".", "testdata", "valid-mapping.yaml"), + filepath.Join(".", "testdata", "valid-set.yaml"), + filepath.Join(".", "testdata", "valid-mix.yaml"), + } { + t.Run(filepath.Base(path), func(t *testing.T) { + conf, err := confmaptest.LoadConf(path) + require.NoError(t, err) + loaded, warning, fatal := LoadConf(conf.ToStringMap()) + require.NoError(t, warning) + require.NoError(t, fatal) + require.Equal(t, map[string]any{ + "extensions": map[string]any{ + "docker_observer": map[string]any{ + "enabled": "false", + }, + "host_observer/with_a_name": map[string]any{ + "refresh_interval": "1h", + }, + }, + "receivers": map[string]any{ + "a_receiver": map[string]any{ + "config": map[string]any{ + "some_field": "some_value", + }, + }, + "another_receiver/with-name": map[string]any{ + "config": map[string]any{ + "parent": map[string]any{ + "child_one": map[string]any{ + "another_field": "another_value", + "child_two": map[string]any{ + "another_field": "another_value", + "yet_another_field": "yet_another_value", + }, + }, + }, + }, + }, + }, + }, loaded.ToStringMap()) + }) + } +} + +func TestInvalidPropertiesIgnoredWhenLoadingConf(t *testing.T) { + for _, fixture := range []struct { + expectedError string + path string + }{ + { + expectedError: `unknown property "splunk.discovery.receivers.a_receiver.unknown"; unknown property "splunk.discovery.receivers.another_receiver/with-name.another_unknown"`, + path: filepath.Join(".", "testdata", "invalid-mapping-unknown-subfield.yaml"), + }, + { + expectedError: `unknown discovery property mapping "splunk.discovery.123"; unknown discovery property mapping "splunk.discovery.processors"`, + path: filepath.Join(".", "testdata", "invalid-mapping-unknown-component.yaml"), + }, + { + expectedError: `invalid property "splunk.discovery.123" (parsing error): splunk.discovery:1:18: unexpected token "123" (expected ("receivers" | "extensions") ComponentID (("config" ) | "enabled") ( | | )*); invalid property "splunk.discovery.processors.a_processor.config.some_field" (parsing error): splunk.discovery:1:18: unexpected token "processors" (expected ("receivers" | "extensions") ComponentID (("config" ) | "enabled") ( | | )*); invalid property "splunk.discovery.receivers.a_receiver.unknown.some_field" (parsing error): splunk.discovery:1:57: unexpected token "" (expected (("config" ) | "enabled") ( | | )*); invalid property "splunk.discovery.receivers.another_receiver/with-name.another_unknown.some_other_field" (parsing error): splunk.discovery:1:87: unexpected token "" (expected (("config" ) | "enabled") ( | | )*)`, + path: filepath.Join(".", "testdata", "invalid-set.yaml"), + }, + } { + t.Run(filepath.Base(fixture.path), func(t *testing.T) { + conf, err := confmaptest.LoadConf(fixture.path) + require.NoError(t, err) + require.NotNil(t, conf) + loaded, warning, fatal := LoadConf(conf.ToStringMap()) + require.NoError(t, fatal) + require.EqualError(t, warning, fixture.expectedError) + require.Equal(t, map[string]any{ + "receivers": map[string]any{ + "another_receiver/with-name": map[string]any{ + "config": map[string]any{ + "parent": map[string]any{ + "child_one": map[string]any{ + "another_field": "another_value", + "child_two": map[string]any{ + "another_field": "another_value", + "yet_another_field": "yet_another_value", + }, + }, + }, + }, + }, + }, + }, loaded.ToStringMap()) + }) + } +} diff --git a/internal/confmapprovider/discovery/properties/property.go b/internal/confmapprovider/discovery/properties/property.go index 38c64af6ea..059655a6c7 100644 --- a/internal/confmapprovider/discovery/properties/property.go +++ b/internal/confmapprovider/discovery/properties/property.go @@ -74,7 +74,7 @@ type ComponentID struct { func NewProperty(property, val string) (*Property, error) { p, err := parser.ParseString("splunk.discovery", property) if err != nil { - return nil, fmt.Errorf("invalid property (parsing error): %w", err) + return nil, fmt.Errorf("invalid property %q (parsing error): %w", property, err) } p.Val = val diff --git a/internal/confmapprovider/discovery/properties/property_test.go b/internal/confmapprovider/discovery/properties/property_test.go index d0f10400fb..1352d31ec1 100644 --- a/internal/confmapprovider/discovery/properties/property_test.go +++ b/internal/confmapprovider/discovery/properties/property_test.go @@ -232,9 +232,9 @@ func TestInvalidProperties(t *testing.T) { for _, tt := range []struct { property, expectedError string }{ - {property: "splunk.discovery.invalid", expectedError: "invalid property (parsing error): splunk.discovery:1:18: unexpected token \"invalid\" (expected (\"receivers\" | \"extensions\") ComponentID ((\"config\" ) | \"enabled\") ( | | )*)"}, - {property: "splunk.discovery.extensions.config.one.two", expectedError: "invalid property (parsing error): splunk.discovery:1:43: unexpected token \"\" (expected ((\"config\" ) | \"enabled\") ( | | )*)"}, - {property: "splunk.discovery.receivers.type/name.config", expectedError: "invalid property (parsing error): splunk.discovery:1:44: unexpected token \"\" (expected )"}, + {property: "splunk.discovery.invalid", expectedError: "invalid property \"splunk.discovery.invalid\" (parsing error): splunk.discovery:1:18: unexpected token \"invalid\" (expected (\"receivers\" | \"extensions\") ComponentID ((\"config\" ) | \"enabled\") ( | | )*)"}, + {property: "splunk.discovery.extensions.config.one.two", expectedError: "invalid property \"splunk.discovery.extensions.config.one.two\" (parsing error): splunk.discovery:1:43: unexpected token \"\" (expected ((\"config\" ) | \"enabled\") ( | | )*)"}, + {property: "splunk.discovery.receivers.type/name.config", expectedError: "invalid property \"splunk.discovery.receivers.type/name.config\" (parsing error): splunk.discovery:1:44: unexpected token \"\" (expected )"}, } { t.Run(tt.property, func(t *testing.T) { p, err := NewProperty(tt.property, "val") diff --git a/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-component.yaml b/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-component.yaml new file mode 100644 index 0000000000..61f05936f1 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-component.yaml @@ -0,0 +1,15 @@ +splunk.discovery: + 123: + processors: + a_processor: + config: + some_field: some_value + receivers: + another_receiver/with-name: + config: + parent: + child_one: + another_field: another_value + child_two: + another_field: another_value + yet_another_field: yet_another_value diff --git a/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-subfield.yaml b/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-subfield.yaml new file mode 100644 index 0000000000..a0f5fbad48 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/invalid-mapping-unknown-subfield.yaml @@ -0,0 +1,15 @@ +splunk.discovery: + receivers: + a_receiver: + unknown: + some_field: some_value + another_receiver/with-name: + config: + parent: + child_one: + another_field: another_value + child_two: + another_field: another_value + yet_another_field: yet_another_value + another_unknown: + some_other_field: some_value diff --git a/internal/confmapprovider/discovery/properties/testdata/invalid-set.yaml b/internal/confmapprovider/discovery/properties/testdata/invalid-set.yaml new file mode 100644 index 0000000000..76730e4396 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/invalid-set.yaml @@ -0,0 +1,7 @@ +splunk.discovery.123: +splunk.discovery.processors.a_processor.config.some_field: some_value +splunk.discovery.receivers.a_receiver.unknown.some_field: some_value +splunk.discovery.receivers.another_receiver/with-name.another_unknown.some_other_field: some_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::another_field: another_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::child_two::another_field: another_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::child_two::yet_another_field: yet_another_value diff --git a/internal/confmapprovider/discovery/properties/testdata/valid-mapping.yaml b/internal/confmapprovider/discovery/properties/testdata/valid-mapping.yaml new file mode 100644 index 0000000000..deadf6fca9 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/valid-mapping.yaml @@ -0,0 +1,20 @@ +splunk.discovery: + receivers: + a_receiver: + config: + some_field: some_value + another_receiver/with-name: + config: + parent: + child_one: + another_field: another_value + child_two: + another_field: another_value + yet_another_field: yet_another_value + extensions: + docker_observer: + enabled: false + host_observer/with_a_name: + config: + refresh_interval: 1h + diff --git a/internal/confmapprovider/discovery/properties/testdata/valid-mix.yaml b/internal/confmapprovider/discovery/properties/testdata/valid-mix.yaml new file mode 100644 index 0000000000..27639d47a8 --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/valid-mix.yaml @@ -0,0 +1,23 @@ +splunk.discovery.receivers.a_receiver.config.some_field: some_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::another_field: another_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::child_two::another_field: another_value +splunk.discovery.extensions.docker_observer.enabled: false +splunk.discovery.extensions.host_observer/with_a_name.config.refresh_interval: 1h +splunk.discovery: + receivers: + a_receiver: + config: + some_field: overwritten + another_receiver/with-name: + config: + parent: + child_one: + another_field: overwritten + child_two: + yet_another_field: yet_another_value + extensions: + docker_observer: + enabled: true # overwritten + host_observer/with_a_name: + config: + refresh_interval: 100h # overwritten diff --git a/internal/confmapprovider/discovery/properties/testdata/valid-set.yaml b/internal/confmapprovider/discovery/properties/testdata/valid-set.yaml new file mode 100644 index 0000000000..511474f87c --- /dev/null +++ b/internal/confmapprovider/discovery/properties/testdata/valid-set.yaml @@ -0,0 +1,6 @@ +splunk.discovery.receivers.a_receiver.config.some_field: some_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::another_field: another_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::child_two::another_field: another_value +splunk.discovery.receivers.another_receiver/with-name.config.parent::child_one::child_two::yet_another_field: yet_another_value +splunk.discovery.extensions.docker_observer.enabled: false +splunk.discovery.extensions.host_observer/with_a_name.config.refresh_interval: 1h diff --git a/tests/general/discoverymode/testdata/docker-observer-config.d/properties.discovery.yaml b/tests/general/discoverymode/testdata/docker-observer-config.d/properties.discovery.yaml index f823901109..434988e343 100644 --- a/tests/general/discoverymode/testdata/docker-observer-config.d/properties.discovery.yaml +++ b/tests/general/discoverymode/testdata/docker-observer-config.d/properties.discovery.yaml @@ -1,3 +1,12 @@ splunk.discovery.receivers.prometheus_simple.config.labels::label_three: overwritten by --set property splunk.discovery.receivers.prometheus_simple.config.labels::label_four: overwritten by env var property splunk.discovery.receivers.prometheus_simple.config.labels::label_five: actual.label.five.value +splunk.discovery: + extensions: + docker_observer: + enabled: false # overwritten by --set and env var properties + receivers: + prometheus_simple: + config: + labels: + label_five: overwritten by above --set form