Skip to content

Conversation

@pavolloffay
Copy link
Member

@pavolloffay pavolloffay commented Dec 5, 2025

Description

This PR adds collector component JSON schema generation to OCB

      --generate-schema    Experimental: Whether builder should generate JSON schemas for component configs (default false)

Example schema generation is here: open-telemetry/opentelemetry-collector-releases#1299

  The schema generator uses static analysis (not runtime reflection) to analyze Go component packages and generate JSON schemas for their configuration types.

  Architecture

  ┌─────────────────────────────────────────────────────────────────┐
  │                    GenerateAndCompile()                         │
  │                  internal/builder/main.go                       │
  └─────────────────────────┬───────────────────────────────────────┘
                            │ if cfg.GenerateSchema
                            ▼
  ┌─────────────────────────────────────────────────────────────────┐
  │                    GenerateSchemas()                            │
  │  - Creates PackageAnalyzer & SchemaGenerator                    │
  │  - Iterates over Extensions, Receivers, Processors, etc.        │
  │  - Calls generator.GenerateSchema() for each component          │
  └─────────────────────────┬───────────────────────────────────────┘
                            ▼
  ┌─────────────────────────────────────────────────────────────────┐
  │                internal/schemagen/                              │
  ├─────────────────────────────────────────────────────────────────┤
  │  analyzer.go    │ Loads packages, finds Config types via AST   │
  │  generator.go   │ Converts Go types → JSON Schema              │
  │  comments.go    │ Extracts doc comments for descriptions       │
  └─────────────────────────────────────────────────────────────────┘

#14288 is alternative solution which adds the schema generation to mdatagen

Link to tracking issue

Fixes #9769

Testing

Documentation

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 81.32075% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.01%. Comparing base (2e5bb6d) to head (73ebdfd).
⚠️ Report is 81 commits behind head on main.

Files with missing lines Patch % Lines
cmd/builder/internal/schemagen/generator.go 75.20% 44 Missing and 18 partials ⚠️
cmd/builder/internal/schemagen/analyzer.go 81.35% 11 Missing and 11 partials ⚠️
cmd/builder/internal/builder/main.go 65.90% 8 Missing and 7 partials ⚠️

❌ Your patch status has failed because the patch coverage (81.32%) 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   #14261      +/-   ##
==========================================
- Coverage   92.15%   92.01%   -0.15%     
==========================================
  Files         668      672       +4     
  Lines       41513    42045     +532     
==========================================
+ Hits        38257    38687     +430     
- Misses       2219     2284      +65     
- Partials     1037     1074      +37     

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

@pavolloffay pavolloffay marked this pull request as ready for review December 5, 2025 19:44
@pavolloffay pavolloffay requested a review from a team as a code owner December 5, 2025 19:44
@pavolloffay pavolloffay requested a review from atoulme December 5, 2025 19:44
@pavolloffay pavolloffay marked this pull request as draft December 8, 2025 11:37
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 10, 2025

CodSpeed Performance Report

Merging #14261 will not alter performance

Comparing pavolloffay:ocb-component-schema (73ebdfd) with main (b31ddb9)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 59 untouched
⏩ 20 skipped1

Footnotes

  1. 20 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
@pavolloffay pavolloffay marked this pull request as ready for review December 15, 2025 17:21
@niwoerner
Copy link
Member

Food for thought: We could think about capturing the default values of the config through calling the CreateDefaultConfig function and reflecting the values of it.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added Stale and removed Stale labels Jan 6, 2026
@pavolloffay pavolloffay closed this Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve otel collector configuration w/ JSON schema

2 participants