[mdatagen] Fix invalid test generation for conditionally_required enum attributes#15029
Open
Krishnachaitanyakc wants to merge 3 commits intoopen-telemetry:mainfrom
Open
[mdatagen] Fix invalid test generation for conditionally_required enum attributes#15029Krishnachaitanyakc wants to merge 3 commits intoopen-telemetry:mainfrom
Krishnachaitanyakc wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
…d 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 the config.go.tmpl to only import "slices" when there are
actually required attributes in reaggregation metrics, avoiding unused import
compile errors.
Resolves open-telemetry#14196
Assisted-by: Claude Sonnet 4.6
Restore stdlib/third-party/local import group separation to satisfy impi linter rules.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an attribute has
requirement_level: conditionally_requiredand anenumtype,mdatagengenerated invalid test code. The generatedmetrics_test.gocalledWith{Attr}MetricAttribute(AttributeEnumAttrRed)— passing the enum constant (an integer) directly — butWith{Attr}MetricAttributeexpects astring. This caused a compile error in generated test code.Root cause: The
getAttributeValuetemplate helper returnsAttributeEnumAttrRed(the typed integer constant), which is correct for required attributes passed as positional arguments. But for conditionally_required attributes, theWith{X}MetricAttribute(string)option function expects a string, so.String()must be appended.Fix:
getConditionalAttributeValuetemplate helper inhelper.tmplthat appends.String()to enum constants, producing the correct string type.metrics_test.go.tmplto usegetConditionalAttributeValuein the two places that generateWith{Attr}MetricAttribute(...)calls for conditionally_required attributes.config.go.tmplto only import"slices"when there are actuallyrequiredattributes in reaggregation metrics (not just any reaggregation metrics), avoiding spurious unused-import compile errors.sampleconnectormetadata.yamlto markenum_attrasconditionally_requiredto cover this case in generated sample/test output.Resolves #14196