Skip to content

Add Config json schema generation#1017

Merged
MrAlias merged 46 commits intoopen-telemetry:mainfrom
coralogix:nimrodavni78/config-json-schema
Feb 20, 2026
Merged

Add Config json schema generation#1017
MrAlias merged 46 commits intoopen-telemetry:mainfrom
coralogix:nimrodavni78/config-json-schema

Conversation

@NimrodAvni78
Copy link
Copy Markdown
Contributor

@NimrodAvni78 NimrodAvni78 commented Dec 16, 2025

Fixes #973
Resolve #53

Automatically generates json schema for config struct, with enum values, deprecated warnings and comments as descriptions

also validates in CI that json schema is the same

@NimrodAvni78 NimrodAvni78 requested a review from a team as a code owner December 16, 2025 13:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 0% with 145 lines in your changes missing coverage. Please review.
✅ Project coverage is 1.92%. Comparing base (ede9606) to head (c2ba4db).

Files with missing lines Patch % Lines
pkg/config/ebpf_tracer.go 0.00% 26 Missing ⚠️
pkg/appolly/services/attr_glob.go 0.00% 19 Missing ⚠️
pkg/appolly/services/attr_regex.go 0.00% 19 Missing ⚠️
pkg/obi/network_cfg.go 0.00% 15 Missing ⚠️
pkg/appolly/services/export.go 0.00% 14 Missing ⚠️
pkg/export/feature.go 0.00% 14 Missing ⚠️
pkg/obi/config.go 0.00% 14 Missing ⚠️
pkg/appolly/services/criteria.go 0.00% 7 Missing ⚠️
pkg/appolly/services/samplerconfig.go 0.00% 6 Missing ⚠️
pkg/export/otel/metrics.go 0.00% 3 Missing ⚠️
... and 5 more

❗ There is a different number of reports uploaded between BASE (ede9606) and HEAD (c2ba4db). Click for more details.

HEAD has 8 uploads less than BASE
Flag BASE (ede9606) HEAD (c2ba4db)
unittests 1 0
integration-test 9 2
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #1017       +/-   ##
==========================================
- Coverage   43.52%   1.92%   -41.61%     
==========================================
  Files         305     240       -65     
  Lines       32864   28168     -4696     
==========================================
- Hits        14305     542    -13763     
- Misses      17639   27571     +9932     
+ Partials      920      55      -865     
Flag Coverage Δ
integration-test 0.00% <0.00%> (-21.69%) ⬇️
integration-test-arm 0.00% <0.00%> (ø)
k8s-integration-test 2.35% <0.00%> (-0.02%) ⬇️
oats-test 0.00% <0.00%> (ø)
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@mariomac mariomac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good initiative!

Comment thread pkg/config/ebpf_tracer.go Outdated
Comment on lines +29 to +34
ContextPropagationDisabledText = "disabled"
ContextPropagationAllText = "all"
ContextPropagationHeadersText = "headers"
ContextPropagationHTTPText = "http"
ContextPropagationTCPText = "tcp"
ContextPropagationIPOptionsText = "ip"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit confusing that some "ContextPropagation..." variables are integers and others are strings.

I'd rename these variables to StrContextPropagation, for example.

Also, make them private if they are going to be only used here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to making private.

Comment thread cmd/obi-schema/main.go
@@ -0,0 +1,363 @@
// Copyright The OpenTelemetry Authors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this belongs to this repo, as it looks pretty generic. Are there any project ins the open-telemetry ecosystem doing that? Maybe its worth to move this somewhere later if that can be reused?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i couldn't find it in projects like otel-collector, maybe we can make it something that can be reused
im not familiar with how other otel projects manage schema.
maybe @MrAlias you have more insight?

@itsCheithanya
Copy link
Copy Markdown
Contributor

itsCheithanya commented Dec 17, 2025

@NimrodAvni78 Looks great! I see the generated schema does list the accepted values for fields that are validated against a specific set of allowed values when those are defined as constants or enums, but it does not do so when the validation is performed via a method on a struct.

For example, Discovery.Instrument.Metadata should only accept values like:

k8s_namespace
k8s_pod_name
k8s_deployment_name
k8s_replicaset_name
k8s_daemonset_name
k8s_statefulset_name
k8s_job_name
k8s_cronjob_name
k8s_owner_name
k8s_container_name

(as defined in attr_regex.go (https://github.com/open-telemetry/opentelemetry-ebpf-instrumentation/blob/v0.3.0/pkg/appolly/services/attr_regex.go#L19) ), but the schema does not currently reflect this.

Similarly, if a struct field is validated by a method (for example, a custom Validate() or IsValid() method that restricts accepted values), it would be very helpful if the schema could include those accepted values (e.g., as an enum or with a description), so users and tooling know what is valid.

@NimrodAvni78
Copy link
Copy Markdown
Contributor Author

@itsCheithanya yeah you are right, generally the more we can embed into the typing of the config we can generate it automatically, and there are other types here which still missing their valid options in the schema. alternatively we can also add some manual implementation of JsonSchema for the target type and provided the schema ourself (like i did with ContextPropagationMode.

this can also be improved as we go, since refactoring big parts of the config is a lot of work

for this example of attr_regex i will try to see which approach works best and add it

@itsCheithanya
Copy link
Copy Markdown
Contributor

itsCheithanya commented Dec 17, 2025

@NimrodAvni78 https://github.com/itsCheithanya/opentelemetry-ebpf-instrumentation/blob/f5edac2114cad288ee315019ddee3e15a62ed677/pkg/appolly/services/attr_glob.go check this if it can be be of any help

@NimrodAvni78
Copy link
Copy Markdown
Contributor Author

thanks @itsCheithanya
i did something really similar and didnt notice this comment :)
i think this now describes the metadata better, also added some other improvments like adding the environment variable matching the config + adding annotations to other fields

@NimrodAvni78
Copy link
Copy Markdown
Contributor Author

also noticed the field is actually inlined and not under another field called metadata, so i also fixed that

Comment thread docs/config-schema.json
Comment thread cmd/obi-schema/main.go
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing tests demonstrating schema generation correctness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add some testing

@NimrodAvni78
Copy link
Copy Markdown
Contributor Author

NimrodAvni78 commented Jan 29, 2026

if a struct field is validated by a method (for example, a custom Validate() or IsValid() method that restricts accepted values), it would be very helpful if the schema could include those accepted values (e.g., as an enum or with a description), so users and tooling know what is valid.

+1 to this.

Since validate is a function with custom logic its sometimes really hard to automatically infer from it what are the accepted values, i did some manual work on some complex structs that added custom JsonSchema implementation to reflect the validation process, but unfortunately i dont think we can do some mapping automatically. ideally what we need is to model our typing to only accept valid values (tried to do for most types), so then validation and schema will be aligned.

@NimrodAvni78 NimrodAvni78 force-pushed the nimrodavni78/config-json-schema branch 2 times, most recently from 841da66 to 53c606c Compare February 1, 2026 10:54
@NimrodAvni78 NimrodAvni78 force-pushed the nimrodavni78/config-json-schema branch from 70a8add to d1d4366 Compare February 1, 2026 12:25
@NimrodAvni78 NimrodAvni78 force-pushed the nimrodavni78/config-json-schema branch from 6a87721 to 4d2f0d8 Compare February 2, 2026 12:10
@NimrodAvni78 NimrodAvni78 requested a review from MrAlias February 2, 2026 13:23
Copy link
Copy Markdown
Contributor

@antonjim-te antonjim-te left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments/questions :)

Comment thread docs/config-schema.json Outdated
}
],
"title": "Agent Type Interface",
"description": "Specifies which interface should the agent pick the IP address from in order to report it in the AgentIP field on each flow. Accepted values are: external, local, or name:\u003cinterface name\u003e (e.g. name:eth0)."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the generated JSON currently escapes < / > in descriptions (e.g., name:\u003cinterface name\u003e).

Can we try to avoid HTML escaping? or were they expected?

Comment thread docs/config-schema.json Outdated
"tcp"
]
},
"type": "array",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not parsed as an array, it is parsed a comma-separated

parts := strings.Split(str, ",")

is something wrong here?

Comment thread pkg/config/ebpf_tracer.go

// Convenience aliases
ContextPropagationAll = ContextPropagationHeaders | ContextPropagationTCP
ContextPropagationAll = ContextPropagationHeaders | ContextPropagationTCP
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it expected that All does not contain IP in the description it says "All contains all the methods"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its intentional to be removed by default
see #1001

…son-schema

# Conflicts:
#	Makefile
#	pkg/export/otel/otelcfg/config_metrics.go
#	pkg/export/otel/otelcfg/config_traces.go
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 51.32924% with 238 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.72%. Comparing base (155505c) to head (68cd9c5).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/obi-schema/main.go 62.79% 111 Missing and 17 partials ⚠️
pkg/config/ebpf_tracer.go 19.23% 21 Missing ⚠️
pkg/obi/network_cfg.go 0.00% 15 Missing ⚠️
pkg/appolly/services/export.go 0.00% 14 Missing ⚠️
pkg/export/feature.go 0.00% 14 Missing ⚠️
pkg/obi/config.go 0.00% 14 Missing ⚠️
pkg/appolly/services/attr_glob.go 52.63% 9 Missing ⚠️
pkg/appolly/services/attr_regex.go 52.63% 9 Missing ⚠️
pkg/appolly/services/criteria.go 0.00% 7 Missing ⚠️
pkg/internal/transform/route/harvest/harvester.go 33.33% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1017       +/-   ##
===========================================
+ Coverage   19.54%   43.72%   +24.18%     
===========================================
  Files         242      308       +66     
  Lines       28138    33426     +5288     
===========================================
+ Hits         5499    14615     +9116     
+ Misses      21987    17872     -4115     
- Partials      652      939      +287     
Flag Coverage Δ
integration-test 21.78% <1.60%> (+0.07%) ⬆️
integration-test-arm 0.00% <0.00%> (ø)
integration-test-vm-x86_64-5.15.152 ?
integration-test-vm-x86_64-6.10.6 ?
k8s-integration-test 2.34% <0.00%> (-0.02%) ⬇️
oats-test 0.00% <0.00%> (ø)
unittests 44.55% <53.30%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MrAlias MrAlias merged commit b905642 into open-telemetry:main Feb 20, 2026
52 checks passed
@MrAlias MrAlias added this to the v0.6.0 milestone Feb 23, 2026
@MrAlias MrAlias mentioned this pull request Mar 5, 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.

Need comprehensive documentation for OBI config file fields Create JSON Schema of the refactored configuration

6 participants