forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processor/deltatocumulative] Adjust Config struct and MaxStreams val…
…idates (open-telemetry#31690) **Description:** The Config struct was changed from JSON to mapstructure to parse the configuration correctly. Additionally, the validation of MaxStreams was adjusted to consider values of 0. **Testing:** Unit tests were added for the config.go file.
- Loading branch information
1 parent
757ddd1
commit da8ab18
Showing
3 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package deltatocumulativeprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor" | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatocumulativeprocessor/internal/metadata" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
t.Parallel() | ||
|
||
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
id component.ID | ||
expected component.Config | ||
}{ | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "all"), | ||
expected: &Config{ | ||
MaxStale: 1 * time.Minute, | ||
MaxStreams: 10, | ||
}, | ||
}, | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "set-valid-max_stale"), | ||
expected: &Config{ | ||
MaxStale: 2 * time.Minute, | ||
MaxStreams: 0, | ||
}, | ||
}, | ||
{ | ||
id: component.NewIDWithName(metadata.Type, "set-valid-max_streams"), | ||
expected: &Config{ | ||
MaxStale: 5 * time.Minute, | ||
MaxStreams: 20, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.id.String(), func(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
|
||
sub, err := cm.Sub(tt.id.String()) | ||
require.NoError(t, err) | ||
require.NoError(t, component.UnmarshalConfig(sub, cfg)) | ||
|
||
assert.NoError(t, component.ValidateConfig(cfg)) | ||
assert.Equal(t, tt.expected, cfg) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
deltatocumulative/all: | ||
max_stale: 1m | ||
max_streams: 10 | ||
deltatocumulative/set-valid-max_stale: | ||
max_stale: 2m | ||
deltatocumulative/set-valid-max_streams: | ||
max_streams: 20 |