Skip to content

Commit

Permalink
[receiver/purefa] Add validate on config components (#17449)
Browse files Browse the repository at this point in the history
* Add validate on config components

Signed-off-by: dgoscn <[email protected]>

* Add changelog

* Update receiver/purefareceiver/config.go

* [receiver/purefa] Add enhancement on validate config

* Revert "[receiver/purefa] Add enhancement on validate config"

This reverts commit d4ab00772c99284993e4153d8ce1d143efdab35b.

* [receiver/purefa] Add golang conventions for error messages

* [receiver/purefa] Add the correct error check validate

* [receiver/purefa] Add the correct error check validate syntax

* [receiver/purefa] Correct unexpected error on config file

* [receiver/purefa] Missing go mod execution after make gotidy

---------

Signed-off-by: dgoscn <[email protected]>
Co-authored-by: Bogdan Drutu <[email protected]>
  • Loading branch information
dgoscn and Bogdan Drutu authored Mar 29, 2023
1 parent e6f10a6 commit 4243ffc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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

0 comments on commit 4243ffc

Please sign in to comment.