Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/purefa] Add validate on config components #17449

17 changes: 17 additions & 0 deletions .chloggen/purefa-receiver-missing-config-code.yaml
Original file line number Diff line number Diff line change
@@ -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:
23 changes: 21 additions & 2 deletions receiver/purefareceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions receiver/purefareceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
2 changes: 1 addition & 1 deletion receiver/purefareceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down