Skip to content

Commit

Permalink
Change cumulative to delta conversion to drop initial value (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien authored Aug 8, 2024
1 parent 55a3d88 commit dcc2f33
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
4 changes: 2 additions & 2 deletions translator/tocwconfig/sampleConfig/complete_linux_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
cumulativetodelta/jmx:
exclude:
match_type: ""
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
2 changes: 1 addition & 1 deletion translator/tocwconfig/sampleConfig/delta_config_linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ processors:
match_type: ""
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
2 changes: 1 addition & 1 deletion translator/tocwconfig/sampleConfig/jmx_config_linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
match_type: ""
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
filter/jmx:
error_mode: propagate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ processors:
- diskio_iops_in_progress
include:
match_type: ""
initial_value: 0
initial_value: 2
max_staleness: 0s
ec2tagger:
ec2_instance_tag_keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import (
)

const (
// Match types are in internal package from contrib
// Match types are in an internal package from contrib
// Strict is the FilterType for filtering by exact string matches.
strict = "strict"
// InitialValue types are in an internal package
// 2 is the int value for the enum
initialValueDrop = 2
)

var (
Expand Down Expand Up @@ -74,7 +77,7 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
}

cfg := t.factory.CreateDefaultConfig().(*cumulativetodeltaprocessor.Config)

cfg.InitialValue = initialValueDrop
excludeMetrics := t.getExcludeMetrics(conf)
if len(excludeMetrics) != 0 {
cfg.Exclude.MatchType = strict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/confmap"

Expand All @@ -18,47 +19,50 @@ func TestTranslator(t *testing.T) {
cdpTranslator := NewTranslator(common.WithName("test"), WithDiskIONetKeys())
require.EqualValues(t, "cumulativetodelta/test", cdpTranslator.ID().String())
testCases := map[string]struct {
input map[string]interface{}
want *cumulativetodeltaprocessor.Config
input map[string]any
want map[string]any
wantErr error
}{
"GenerateDeltaProcessorConfigWithCPU": {
input: map[string]interface{}{
"metrics": map[string]interface{}{
"metrics_collected": map[string]interface{}{
"cpu": map[string]interface{}{},
input: map[string]any{
"metrics": map[string]any{
"metrics_collected": map[string]any{
"cpu": map[string]any{},
},
},
},
wantErr: &common.MissingKeyError{ID: cdpTranslator.ID(), JsonKey: fmt.Sprint(diskioKey, " or ", netKey)},
},
"GenerateDeltaProcessorConfigWithNet": {
input: map[string]interface{}{
"metrics": map[string]interface{}{
"metrics_collected": map[string]interface{}{
"net": map[string]interface{}{},
input: map[string]any{
"metrics": map[string]any{
"metrics_collected": map[string]any{
"net": map[string]any{},
},
},
},
want: &cumulativetodeltaprocessor.Config{
Include: cumulativetodeltaprocessor.MatchMetrics{},
Exclude: cumulativetodeltaprocessor.MatchMetrics{},
want: map[string]any{
"initial_value": "drop",
},
},
"GenerateDeltaProcessorConfigWithDiskIO": {
input: map[string]interface{}{
"metrics": map[string]interface{}{
"metrics_collected": map[string]interface{}{
"diskio": map[string]interface{}{},
input: map[string]any{
"metrics": map[string]any{
"metrics_collected": map[string]any{
"diskio": map[string]any{},
},
},
},
want: &cumulativetodeltaprocessor.Config{
Include: cumulativetodeltaprocessor.MatchMetrics{},
Exclude: cumulativetodeltaprocessor.MatchMetrics{Metrics: []string{"iops_in_progress", "diskio_iops_in_progress"}},
want: map[string]any{
"exclude": map[string]any{
"match_type": "strict",
"metrics": []string{"iops_in_progress", "diskio_iops_in_progress"},
},
"initial_value": "drop",
},
},
}
factory := cumulativetodeltaprocessor.NewFactory()
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
conf := confmap.NewFromStringMap(testCase.input)
Expand All @@ -68,8 +72,10 @@ func TestTranslator(t *testing.T) {
require.NotNil(t, got)
gotCfg, ok := got.(*cumulativetodeltaprocessor.Config)
require.True(t, ok)
require.Equal(t, testCase.want.Include.Metrics, gotCfg.Include.Metrics)
require.Equal(t, testCase.want.Exclude.Metrics, gotCfg.Exclude.Metrics)
wantCfg := factory.CreateDefaultConfig()
wantConf := confmap.NewFromStringMap(testCase.want)
require.NoError(t, wantConf.Unmarshal(&wantCfg))
assert.Equal(t, wantCfg, gotCfg)
}
})
}
Expand Down

0 comments on commit dcc2f33

Please sign in to comment.