Skip to content

[cmd/mdatagen]Allow custom mapstructure tags for generated config struct fields#15157

Closed
jkoronaAtCisco wants to merge 1 commit intoopen-telemetry:mainfrom
jkoronaAtCisco:mdatagen_custom_config_tags
Closed

[cmd/mdatagen]Allow custom mapstructure tags for generated config struct fields#15157
jkoronaAtCisco wants to merge 1 commit intoopen-telemetry:mainfrom
jkoronaAtCisco:mdatagen_custom_config_tags

Conversation

@jkoronaAtCisco
Copy link
Copy Markdown
Contributor

Description

  • Adds a mapstructure field to the go_struct schema annotation, allowing schema authors to override the generated mapstructure struct tag for both allOf entries and named properties.
  • Without a custom tag, allOf entries still default to mapstructure:",squash" and properties use the property name — no change to existing behavior.
  • Enables use cases like the OTLP receiver pattern where an embedded struct should be exposed as a named field (e.g. mapstructure:"protocols") rather than squashed.

Example:

  config:
    type: object
    allOf:
      - $ref: protocols
        go_struct:
          mapstructure: "protocols"

Link to tracking issue

Fixes #15155

Testing

Covered change with corresponding unit tests

@jkoronaAtCisco jkoronaAtCisco requested review from a team and dmitryax as code owners April 20, 2026 12:11
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.31%. Comparing base (22a5e61) to head (d153f56).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15157      +/-   ##
==========================================
- Coverage   91.31%   91.31%   -0.01%     
==========================================
  Files         699      699              
  Lines       44939    44942       +3     
==========================================
+ Hits        41036    41037       +1     
- Misses       2759     2760       +1     
- Partials     1144     1145       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dmitryax
Copy link
Copy Markdown
Member

dmitryax commented Apr 20, 2026

This is not an intuitive user interface. We should not require any mapstructure tag customization for a simple grouping. I'd imagine this to be handled by something like this

  config:
    type: object
    properties:
      protocols:
        $ref: protocols

@jkoronaAtCisco
Copy link
Copy Markdown
Contributor Author

jkoronaAtCisco commented Apr 20, 2026

This is not an intuitive user interface. We should not require any mapstructure tag customization for a simple grouping. I'd imagine this to be handled by something like this

  config:
    type: object
    properties:
      protocols:
        $ref: protocols

@dmitryax
This schema would produce following go code:

type Config struct {
   Protocols Protocols `mapstructure:"protocols"`
}

but what we need to achieve is:

type Config struct {
  Protocols `mapstructure:"protocols"`
}

(This is real example from OTLP receiver component config)

So it's kind of mix:

  • Embedded struct in go
  • But named field in collector config

This is currently not possible with config schemas and mdatagen.

@dmitryax
Copy link
Copy Markdown
Member

type Config struct {
  Protocols `mapstructure:"protocols"`
}

this seems wrong to me. I've created #15178 to address that

@jkoronaAtCisco
Copy link
Copy Markdown
Contributor Author

This issue will be solved in the other way, as described #15155 (comment)

@jkoronaAtCisco jkoronaAtCisco deleted the mdatagen_custom_config_tags branch April 24, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cmd/mdatagen] Allow custom tags for generated config struct fields

2 participants