Skip to content

Commit 7c31dd5

Browse files
authored
[mdatagen] bug fix - reaggreagate_set test generation (#14441)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fixes reaggregation test generation when metrics have attributes with `requirement_level: required`. 1. **Config validation failure**: The generated `testdata/config.yaml` included `attributes: []` in the `reaggregate_set` section, but required attributes must always be present. This caused config validation to fail with an error like: ``` error decoding 'metrics': attributes [required_string_attr] are required for metric reaggregate.metric.with_required ``` **Fix**: Updated `config.yaml.tmpl` to use `requiredAttributes` helper to include required attributes in the `reaggregate_set` config instead of an empty array. 2. **Test assertion failure**: The generated `metrics_test.go` used different values for required attributes across data points, preventing them from merging during reaggregation. The test expected 1 data point but received 2. **Fix** - Updated `metrics_test.go.tmpl` to use the same value for required attributes across both data points in reaggregation tests, allowing them to merge correctly while still testing that non-required attributes are dropped. <!-- Issue number if applicable --> #### Link to tracking issue Fixes # <!--Describe what testing was performed and which tests were added.--> #### Testing - Added `required_string_attr` attribute and `reaggregate.metric.with_required` metric to `samplereceiver/metadata.yaml` to cover this scenario <!--Please delete paragraphs that you did not use before submitting.-->
1 parent ba17669 commit 7c31dd5

File tree

10 files changed

+296
-49
lines changed

10 files changed

+296
-49
lines changed

cmd/mdatagen/internal/loader_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ func TestLoadMetadata(t *testing.T) {
244244
FullName: "opt_in_bool_attr",
245245
RequirementLevel: AttributeRequirementLevelOptIn,
246246
},
247+
"required_string_attr": {
248+
Description: "A required attribute with a string value",
249+
Type: ValueType{
250+
ValueType: pcommon.ValueTypeStr,
251+
},
252+
FullName: "required_string_attr",
253+
RequirementLevel: AttributeRequirementLevelRequired,
254+
},
247255
},
248256
Metrics: map[MetricName]Metric{
249257
"default.metric": {
@@ -267,7 +275,7 @@ func TestLoadMetadata(t *testing.T) {
267275
"reaggregate.metric": {
268276
Signal: Signal{
269277
Enabled: true,
270-
Description: "Metric for testing spacial reaggregation",
278+
Description: "Metric for testing spatial reaggregation",
271279
Stability: Stability{Level: component.StabilityLevelBeta},
272280
Attributes: []AttributeName{"string_attr", "boolean_attr"},
273281
},
@@ -276,6 +284,18 @@ func TestLoadMetadata(t *testing.T) {
276284
MetricValueType: MetricValueType{pmetric.NumberDataPointValueTypeDouble},
277285
},
278286
},
287+
"reaggregate.metric.with_required": {
288+
Signal: Signal{
289+
Enabled: true,
290+
Description: "Metric for testing spatial reaggregation with required attributes",
291+
Stability: Stability{Level: component.StabilityLevelBeta},
292+
Attributes: []AttributeName{"required_string_attr", "string_attr", "boolean_attr"},
293+
},
294+
Unit: strPtr("1"),
295+
Gauge: &Gauge{
296+
MetricValueType: MetricValueType{pmetric.NumberDataPointValueTypeDouble},
297+
},
298+
},
279299
"system.cpu.time": {
280300
Signal: Signal{
281301
Enabled: true,

cmd/mdatagen/internal/samplereceiver/documentation.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Monotonic cumulative sum int metric with string input_type enabled by default.
6565
6666
### reaggregate.metric
6767
68-
Metric for testing spacial reaggregation
68+
Metric for testing spatial reaggregation
6969
7070
| Unit | Metric Type | Value Type | Stability |
7171
| ---- | ----------- | ---------- | --------- |
@@ -78,6 +78,22 @@ Metric for testing spacial reaggregation
7878
| string_attr | Attribute with any string value. | Any Str | Recommended |
7979
| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended |
8080
81+
### reaggregate.metric.with_required
82+
83+
Metric for testing spatial reaggregation with required attributes
84+
85+
| Unit | Metric Type | Value Type | Stability |
86+
| ---- | ----------- | ---------- | --------- |
87+
| 1 | Gauge | Double | Beta |
88+
89+
#### Attributes
90+
91+
| Name | Description | Values | Requirement Level |
92+
| ---- | ----------- | ------ | -------- |
93+
| required_string_attr | A required attribute with a string value | Any Str | Required |
94+
| string_attr | Attribute with any string value. | Any Str | Recommended |
95+
| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended |
96+
8197
### system.cpu.time
8298
8399
Monotonic cumulative sum int metric enabled by default.

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config.go

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config_test.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go

Lines changed: 141 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)