Skip to content

[cmd/mdatagen] Handle default values for configuration fields in generated code.#15018

Open
jkoronaAtCisco wants to merge 2 commits intoopen-telemetry:mainfrom
jkoronaAtCisco:mdatagen_config_default_values
Open

[cmd/mdatagen] Handle default values for configuration fields in generated code.#15018
jkoronaAtCisco wants to merge 2 commits intoopen-telemetry:mainfrom
jkoronaAtCisco:mdatagen_config_default_values

Conversation

@jkoronaAtCisco
Copy link
Copy Markdown
Contributor

Description

This PR extends mdatagen's config code generator to automatically produce createDefaultConfig() (and per-definition createDefaultXxx()) factory functions from default: values declared in the JSON Schema config.

Supported default types:

  • string → quoted Go string literal
  • string + format: duration → time package expression (e.g. 10time.Second, 1time.Hour + 30*time.Minute)
  • integer / number → numeric literal
  • boolean → true / false
  • x-optional: true fields → wrapped with configoptional.Some(...)
  • x-pointer: true fields → local variable + address-of
  • Nested struct definitions (inline objects, $ref, array-of-objects) → delegates to a createDefaultXxx() per definition

Currently not supported types: object, array (non-object items), date-time strings, x-customType fields, external $refs. Support to those types will be added in separate PRs.

Link to tracking issue

#14560

Testing

  1. Unit tests coverage
  2. Sample components updated

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.17%. Comparing base (6a56478) to head (2f587fb).

Files with missing lines Patch % Lines
cmd/mdatagen/internal/cfggen/generation.go 85.20% 21 Missing and 4 partials ⚠️
...datagen/internal/samplescraper/generated_config.go 0.00% 7 Missing ⚠️
...atagen/internal/samplereceiver/generated_config.go 0.00% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (80.00%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15018      +/-   ##
==========================================
- Coverage   91.22%   91.17%   -0.05%     
==========================================
  Files         697      697              
  Lines       44627    44807     +180     
==========================================
+ Hits        40710    40853     +143     
- Misses       2773     2806      +33     
- Partials     1144     1148       +4     

☔ 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.

@jkoronaAtCisco jkoronaAtCisco marked this pull request as ready for review March 27, 2026 17:12
@jkoronaAtCisco jkoronaAtCisco requested review from a team and dmitryax as code owners March 27, 2026 17:12
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.

1 participant