diff --git a/.chloggen/purefa-receiver-missing-config-code.yaml b/.chloggen/purefa-receiver-missing-config-code.yaml new file mode 100644 index 000000000000..cba229b8e951 --- /dev/null +++ b/.chloggen/purefa-receiver-missing-config-code.yaml @@ -0,0 +1,17 @@ + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: receiver/purefareceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add missing code snippet that validate the config file + +# One or more tracking issues related to the change +issues: [14886] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: \ No newline at end of file diff --git a/receiver/purefareceiver/config.go b/receiver/purefareceiver/config.go index 72578a974fbe..d57c03c4e151 100644 --- a/receiver/purefareceiver/config.go +++ b/receiver/purefareceiver/config.go @@ -15,10 +15,12 @@ package purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver" import ( + "errors" "time" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" + "go.uber.org/multierr" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver/internal" ) @@ -64,6 +66,23 @@ type ReloadIntervals struct { } func (c *Config) Validate() error { - // TODO(dgoscn): perform config validation - return nil + var errs error + + if c.Settings.ReloadIntervals.Array == 0 { + errs = multierr.Append(errs, errors.New("reload interval for 'array' must be provided")) + } + if c.Settings.ReloadIntervals.Hosts == 0 { + errs = multierr.Append(errs, errors.New("reload interval for 'hosts' must be provided")) + } + if c.Settings.ReloadIntervals.Directories == 0 { + errs = multierr.Append(errs, errors.New("reload interval for 'directories' must be provided")) + } + if c.Settings.ReloadIntervals.Pods == 0 { + errs = multierr.Append(errs, errors.New("reload interval for 'pods' must be provided")) + } + if c.Settings.ReloadIntervals.Volumes == 0 { + errs = multierr.Append(errs, errors.New("reload interval for 'volumes' must be provided")) + } + + return errs } diff --git a/receiver/purefareceiver/config_test.go b/receiver/purefareceiver/config_test.go index d22f08576ef9..3cdb05baaa67 100644 --- a/receiver/purefareceiver/config_test.go +++ b/receiver/purefareceiver/config_test.go @@ -62,6 +62,10 @@ func TestLoadConfig(t *testing.T) { assert.NoError(t, component.ValidateConfig(cfg)) assert.Equal(t, tt.expected, cfg) + + expected := factory.CreateDefaultConfig().(*Config) + + require.Equal(t, expected, cfg) }) } } diff --git a/receiver/purefareceiver/go.mod b/receiver/purefareceiver/go.mod index 91c1858112fa..88907c2fe9bf 100644 --- a/receiver/purefareceiver/go.mod +++ b/receiver/purefareceiver/go.mod @@ -13,6 +13,7 @@ require ( go.opentelemetry.io/collector/confmap v0.74.0 go.opentelemetry.io/collector/consumer v0.74.0 go.opentelemetry.io/collector/receiver v0.74.0 + go.uber.org/multierr v1.10.0 ) require ( @@ -134,7 +135,6 @@ require ( go.opentelemetry.io/otel/trace v1.14.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/goleak v1.2.1 // indirect - go.uber.org/multierr v1.10.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.7.0 // indirect golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect