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

[mdatagen] Fix metric tests on boolean attributes #11169

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/fix-mdatagen-metrics-bool-attr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix incorrect generation of metric tests with boolean attributes.

# One or more tracking issues or pull requests related to the change
issues: [11169]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
1 change: 1 addition & 0 deletions cmd/mdatagen/internal/samplereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ metrics:
| ---- | ----------- | ------ |
| string_attr | Attribute with any string value. | Any Str |
| boolean_attr | Attribute with a boolean value. | Any Bool |
| boolean_attr2 | Another boolean attribute, with a different test value. | Any Bool |

### optional.metric.empty_unit

Expand Down

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

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

14 changes: 9 additions & 5 deletions cmd/mdatagen/internal/samplereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ resource_attributes:

map.resource.attr:
description: Resource attribute with a map value.
type: map
type: map
enabled: true

string.resource.attr_disable_warning:
description: Resource attribute with any string value.
type: string
enabled: true
enabled: true
warnings:
if_enabled_not_set: This resource_attribute will be disabled by default soon.

string.resource.attr_remove_warning:
description: Resource attribute with any string value.
type: string
enabled: false
enabled: false
warnings:
if_configured: This resource_attribute is deprecated and will be removed soon.

string.resource.attr_to_be_removed:
description: Resource attribute with any string value.
type: string
enabled: true
enabled: true
warnings:
if_enabled: This resource_attribute is deprecated and will be removed soon.

Expand All @@ -86,6 +86,10 @@ attributes:
description: Attribute with a boolean value.
type: bool

boolean_attr2:
description: Another boolean attribute, with a different test value.
type: bool

slice_attr:
description: Attribute with a slice value.
type: slice
Expand Down Expand Up @@ -114,7 +118,7 @@ metrics:
unit: "1"
gauge:
value_type: double
attributes: [string_attr, boolean_attr]
attributes: [string_attr, boolean_attr, boolean_attr2]
warnings:
if_configured: This metric is deprecated and will be removed soon.

Expand Down
9 changes: 8 additions & 1 deletion cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ func TestLoadMetadata(t *testing.T) {
},
FullName: "boolean_attr",
},
"boolean_attr2": {
Description: "Another boolean attribute, with a different test value.",
Type: ValueType{
ValueType: pcommon.ValueTypeBool,
},
FullName: "boolean_attr2",
},
"slice_attr": {
Description: "Attribute with a slice value.",
Type: ValueType{
Expand Down Expand Up @@ -190,7 +197,7 @@ func TestLoadMetadata(t *testing.T) {
Gauge: &gauge{
MetricValueType: MetricValueType{pmetric.NumberDataPointValueTypeDouble},
},
Attributes: []attributeName{"string_attr", "boolean_attr"},
Attributes: []attributeName{"string_attr", "boolean_attr", "boolean_attr2"},
},
"optional.metric.empty_unit": {
Enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/metrics_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestMetricsBuilder(t *testing.T) {
attrVal, ok {{ if eq $i 0 }}:{{ end }}= dp.Attributes().Get("{{ (attributeInfo $attr).Name }}")
assert.True(t, ok)
{{- if eq (attributeInfo $attr).Type.String "Bool"}}
assert.{{- if (attributeInfo $attr).TestValue }}True{{ else }}False{{- end }}(t, attrVal.{{ (attributeInfo $attr).Type }}()
assert.{{- if eq (attributeInfo $attr).TestValue "true" }}True{{ else }}False{{- end }}(t, attrVal.{{ (attributeInfo $attr).Type }}()
{{- else }}
assert.EqualValues(t, {{ (attributeInfo $attr).TestValue }}, attrVal.{{ (attributeInfo $attr).Type }}()
{{- end }}
Expand Down
Loading