Skip to content

Commit 7565af8

Browse files
[mdatagen] Fix invalid test code generation for conditionally_required enum attributes
When an attribute has requirement_level: conditionally_required and an enum type, the generated metrics_test.go was passing the enum constant directly (an integer) to With{Attr}MetricAttribute(), which expects a string. This caused compile errors in generated test code. Fix by introducing a getConditionalAttributeValue template helper that appends .String() to enum attribute constants, producing the correct string type. Also fix config.go.tmpl to only import "slices" when there are actually required attributes in reaggregation metrics, avoiding unused import compile errors. Add assertions for conditionally_required attributes in the reaggregation branch of metrics_test.go.tmpl so the generated tests verify their presence and value, matching the pattern used in the non-reaggregation branch. Add TestDeprecatedRecordMethods to exercise the deprecated MetricsBuilder.Record*DataPoint wrapper methods that exist for backward compatibility when metrics have entities. The existing test only exercised the entity builder path, leaving lines in generated_metrics.go uncovered and failing the Codecov patch coverage gate. Restore stdlib/third-party/local import group separation in generated files to satisfy impi linter rules. Regenerate sampleconnector and sampleentityreceiver fixtures. Resolves #14196 Signed-off-by: Kc Balusu <kcbalusu@meta.com>
1 parent 346b065 commit 7565af8

10 files changed

Lines changed: 135 additions & 34 deletions

File tree

cmd/mdatagen/internal/sampleconnector/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The metric will be become optional soon.
2828
| ---- | ----------- | ------ | ----------------- | ------------------- |
2929
| string_attr | Attribute with any string value. | Any Str | Recommended | - |
3030
| state | Integer attribute with overridden name. | Any Int | Recommended | - |
31-
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - |
31+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Conditionally Required | - |
3232
| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - |
3333
| map_attr | Attribute with a map value. | Any Map | Recommended | - |
3434
@@ -58,7 +58,7 @@ Monotonic cumulative sum int metric with string input_type enabled by default.
5858
| ---- | ----------- | ------ | ----------------- | ------------------- |
5959
| string_attr | Attribute with any string value. | Any Str | Recommended | - |
6060
| state | Integer attribute with overridden name. | Any Int | Recommended | - |
61-
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - |
61+
| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Conditionally Required | - |
6262
| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - |
6363
| map_attr | Attribute with a map value. | Any Map | Recommended | - |
6464

cmd/mdatagen/internal/sampleconnector/internal/metadata/generated_entity_metrics.go

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

cmd/mdatagen/internal/sampleconnector/internal/metadata/generated_entity_metrics_test.go

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

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

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

cmd/mdatagen/internal/sampleconnector/internal/metadata/generated_metrics_test.go

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

cmd/mdatagen/internal/sampleconnector/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ attributes:
9393
description: Attribute with a known set of string values.
9494
type: string
9595
enum: [red, green, blue]
96+
requirement_level: conditionally_required
9697

9798
map_attr:
9899
description: Attribute with a map value.

cmd/mdatagen/internal/sampleentityreceiver/internal/metadata/generated_metrics_test.go

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

0 commit comments

Comments
 (0)