Add Config json schema generation#1017
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ContextPropagationDisabledText = "disabled" | ||
| ContextPropagationAllText = "all" | ||
| ContextPropagationHeadersText = "headers" | ||
| ContextPropagationHTTPText = "http" | ||
| ContextPropagationTCPText = "tcp" | ||
| ContextPropagationIPOptionsText = "ip" |
There was a problem hiding this comment.
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.
| @@ -0,0 +1,363 @@ | |||
| // Copyright The OpenTelemetry Authors | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
|
@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, (as defined in Similarly, if a struct field is validated by a method (for example, a custom |
|
@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 this can also be improved as we go, since refactoring big parts of the config is a lot of work for this example of |
|
@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 |
|
thanks @itsCheithanya |
|
also noticed the field is actually inlined and not under another field called metadata, so i also fixed that |
There was a problem hiding this comment.
This is missing tests demonstrating schema generation correctness.
There was a problem hiding this comment.
will add some testing
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. |
841da66 to
53c606c
Compare
70a8add to
d1d4366
Compare
6a87721 to
4d2f0d8
Compare
…son-schema # Conflicts: # go.mod # go.sum
antonjim-te
left a comment
There was a problem hiding this comment.
some comments/questions :)
| } | ||
| ], | ||
| "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)." |
There was a problem hiding this comment.
the generated JSON currently escapes < / > in descriptions (e.g., name:\u003cinterface name\u003e).
Can we try to avoid HTML escaping? or were they expected?
| "tcp" | ||
| ] | ||
| }, | ||
| "type": "array", |
There was a problem hiding this comment.
it is not parsed as an array, it is parsed a comma-separated
parts := strings.Split(str, ",")
is something wrong here?
|
|
||
| // Convenience aliases | ||
| ContextPropagationAll = ContextPropagationHeaders | ContextPropagationTCP | ||
| ContextPropagationAll = ContextPropagationHeaders | ContextPropagationTCP |
There was a problem hiding this comment.
is it expected that All does not contain IP in the description it says "All contains all the methods"
There was a problem hiding this comment.
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 Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…son-schema # Conflicts: # pkg/appolly/services/criteria.go
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