Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Mar 27, 2024
1 parent 55c94aa commit 59a4e27
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.

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 }}

0 comments on commit 59a4e27

Please sign in to comment.