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/podman] remove config Validate call on start #33555

Merged
merged 10 commits into from
Jul 11, 2024
19 changes: 16 additions & 3 deletions receiver/podmanreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)

tests := []struct {
id component.ID
expected component.Config
expectedErr error
id component.ID
expected component.Config
expectedErrMsg string
}{
{
id: component.NewIDWithName(metadata.Type, ""),
Expand Down Expand Up @@ -54,6 +54,14 @@ func TestLoadConfig(t *testing.T) {
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
},
{
id: component.NewIDWithName(metadata.Type, "empty_endpoint"),
expectedErrMsg: "config.Endpoint must be specified",
},
{
id: component.NewIDWithName(metadata.Type, "invalid_collection_interval"),
expectedErrMsg: `config.CollectionInterval must be specified; "collection_interval": requires positive value`,
},
}

for _, tt := range tests {
Expand All @@ -65,6 +73,11 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)
require.NoError(t, sub.Unmarshal(cfg))

if tt.expectedErrMsg != "" {
assert.EqualError(t, component.ValidateConfig(cfg), tt.expectedErrMsg)
return
}

assert.NoError(t, component.ValidateConfig(cfg))
assert.Equal(t, tt.expected, cfg)
})
Expand Down
5 changes: 0 additions & 5 deletions receiver/podmanreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ func createMetricsReceiver(
}

func (r *metricsReceiver) start(ctx context.Context, _ component.Host) error {
err := r.config.Validate()
if err != nil {
return err
}

podmanClient, err := r.clientFactory(r.set.Logger, r.config)
if err != nil {
return err
Expand Down
8 changes: 1 addition & 7 deletions receiver/podmanreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ func TestErrorsInStart(t *testing.T) {
assert.NotNil(t, recv)
err := recv.start(context.Background(), componenttest.NewNopHost())
require.Error(t, err)
assert.Equal(t, "config.Endpoint must be specified", err.Error())

recv = newMetricsReceiver(receivertest.NewNopSettings(), &Config{Endpoint: "someEndpoint"}, nil)
assert.NotNil(t, recv)
err = recv.start(context.Background(), componenttest.NewNopHost())
require.Error(t, err)
assert.Equal(t, "config.CollectionInterval must be specified", err.Error())
assert.Equal(t, `unable to create connection. "" is not a supported schema`, err.Error())
}

func TestScraperLoop(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions receiver/podmanreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ podman_stats/all:
endpoint: http://example.com/
collection_interval: 2s
timeout: 20s
podman_stats/empty_endpoint:
endpoint: ""
podman_stats/invalid_collection_interval:
collection_interval: 0s