Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Apr 11, 2024
1 parent 8efb38f commit d054b0e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 60 deletions.
1 change: 1 addition & 0 deletions cmd/mdatagen/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
go.opentelemetry.io/collector/confmap v0.98.0
go.opentelemetry.io/collector/confmap/provider/fileprovider v0.98.0
go.opentelemetry.io/collector/consumer v0.98.0
go.opentelemetry.io/collector/filter v0.0.0-00010101000000-000000000000
go.opentelemetry.io/collector/pdata v1.5.0
go.opentelemetry.io/collector/receiver v0.98.0
go.opentelemetry.io/collector/semconv v0.98.0
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ none_set:
enabled: false
string.resource.attr_to_be_removed:
enabled: false
filter_set:
filter_set_include:
metrics:
default.metric:
enabled: true
default.metric.to_be_removed:
enabled: true
metric.input_type:
enabled: true
optional.metric:
enabled: true
optional.metric.empty_unit:
Expand All @@ -72,63 +74,68 @@ filter_set:
enabled: true
optional.resource.attr:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "optional.resource.attr-val"
- regexp: ".*"
slice.resource.attr:
enabled: true
string.enum.resource.attr:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "one"
- regexp: ".*"
string.resource.attr:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "string.resource.attr-val"
- regexp: ".*"
string.resource.attr_disable_warning:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "string.resource.attr_disable_warning-val"
- regexp: ".*"
string.resource.attr_remove_warning:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "string.resource.attr_remove_warning-val"
- regexp: ".*"
string.resource.attr_to_be_removed:
enabled: true
exclude:
- strict: "non-existent"
- regexp: "non-existent"
include:
- strict: "non-existent"
- regexp: "non-existent"
- strict: "string.resource.attr_to_be_removed-val"
- regexp: ".*"
filter_set_exclude:
metrics:
default.metric:
enabled: true
default.metric.to_be_removed:
enabled: true
metric.input_type:
enabled: true
optional.metric:
enabled: true
optional.metric.empty_unit:
enabled: true
resource_attributes:
map.resource.attr:
enabled: true
optional.resource.attr:
enabled: true
exclude:
- strict: "optional.resource.attr-val"
slice.resource.attr:
enabled: true
string.enum.resource.attr:
enabled: true
exclude:
- strict: "one"
string.resource.attr:
enabled: true
exclude:
- strict: "string.resource.attr-val"
string.resource.attr_disable_warning:
enabled: true
exclude:
- strict: "string.resource.attr_disable_warning-val"
string.resource.attr_remove_warning:
enabled: true
exclude:
- strict: "string.resource.attr_remove_warning-val"
string.resource.attr_to_be_removed:
enabled: true
exclude:
- strict: "string.resource.attr_to_be_removed-val"
21 changes: 13 additions & 8 deletions cmd/mdatagen/templates/metrics_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (
testSetDefault testConfigCollection = iota
testSetAll
testSetNone
testSetFilter
testSetFilterInclude
testSetFilterExclude
)

func TestMetricsBuilder(t *testing.T) {
Expand All @@ -41,8 +42,12 @@ func TestMetricsBuilder(t *testing.T) {
configSet: testSetNone,
},
{
name: "filter_set",
configSet: testSetFilter,
name: "filter_set_include",
configSet: testSetFilterInclude,
},
{
name: "filter_set_exclude",
configSet: testSetFilterExclude,
},
}
for _, test := range tests {
Expand All @@ -57,7 +62,7 @@ func TestMetricsBuilder(t *testing.T) {
expectedWarnings := 0
{{- range $name, $metric := .Metrics }}
{{- if and $metric.Enabled $metric.Warnings.IfEnabled }}
if test.configSet == testSetDefault || test.configSet == testSetAll || test.configSet == testSetFilter {
if test.configSet == testSetDefault || test.configSet == testSetAll || test.configSet == testSetFilterInclude || test.configSet == testSetFilterExclude {
assert.Equal(t, "[WARNING] `{{ $name }}` should not be enabled: {{ $metric.Warnings.IfEnabled }}", observedLogs.All()[expectedWarnings].Message)
expectedWarnings++
}
Expand All @@ -69,15 +74,15 @@ func TestMetricsBuilder(t *testing.T) {
}
{{- end }}
{{- if $metric.Warnings.IfConfigured }}
if test.configSet == testSetAll || test.configSet == testSetNone || test.configSet == testSetFilter {
if test.configSet == testSetAll || test.configSet == testSetNone || test.configSet == testSetFilterInclude || test.configSet == testSetFilterExclude {
assert.Equal(t, "[WARNING] `{{ $name }}` should not be configured: {{ $metric.Warnings.IfConfigured }}", observedLogs.All()[expectedWarnings].Message)
expectedWarnings++
}
{{- end }}
{{- end }}
{{- range $name, $attr := .ResourceAttributes }}
{{- if and $attr.Enabled $attr.Warnings.IfEnabled }}
if test.configSet == testSetDefault || test.configSet == testSetAll || test.configSet == testSetFilter {
if test.configSet == testSetDefault || test.configSet == testSetAll || test.configSet == testSetFilterInclude || test.configSet == testSetFilterExclude {
assert.Equal(t, "[WARNING] `{{ $name }}` should not be enabled: {{ $attr.Warnings.IfEnabled }}", observedLogs.All()[expectedWarnings].Message)
expectedWarnings++
}
Expand All @@ -89,7 +94,7 @@ func TestMetricsBuilder(t *testing.T) {
}
{{- end }}
{{- if $attr.Warnings.IfConfigured }}
if test.configSet == testSetAll || test.configSet == testSetNone || test.configSet == testSetFilter {
if test.configSet == testSetAll || test.configSet == testSetNone || test.configSet == testSetFilterInclude || test.configSet == testSetFilterExclude {
assert.Equal(t, "[WARNING] `{{ $name }}` should not be configured: {{ $attr.Warnings.IfConfigured }}", observedLogs.All()[expectedWarnings].Message)
expectedWarnings++
}
Expand Down Expand Up @@ -126,7 +131,7 @@ func TestMetricsBuilder(t *testing.T) {
{{- end }}
metrics := mb.Emit(WithResource(res))

if test.configSet == testSetNone {
if test.configSet == testSetNone || test.configSet == testSetFilterExclude {
assert.Equal(t, 0, metrics.ResourceMetrics().Len())
return
}
Expand Down
23 changes: 20 additions & 3 deletions cmd/mdatagen/templates/testdata/config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ none_set:
enabled: false
{{- end }}
{{- end }}
filter_set:
filter_set_include:
{{- if .Metrics }}
metrics:
{{- range $name, $_ := .Metrics }}
Expand All @@ -43,10 +43,27 @@ filter_set:
{{ $name }}:
enabled: true
{{- if eq $attr.Type.String "Str" }}
exclude:
- strict: {{ $attr.TestValue }}
include:
- regexp: ".*"
{{- end }}
{{- end }}
{{- end }}
filter_set_exclude:
{{- if .Metrics }}
metrics:
{{- range $name, $_ := .Metrics }}
{{ $name }}:
enabled: true
{{- end }}
{{- end }}
{{- if .ResourceAttributes }}
resource_attributes:
{{- range $name, $attr := .ResourceAttributes }}
{{ $name }}:
enabled: true
{{- if eq $attr.Type.String "Str" }}
exclude:
- strict: {{ $attr.TestValue }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion filter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ require (
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
6 changes: 4 additions & 2 deletions filter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d054b0e

Please sign in to comment.