-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[component][componenttest] Add validation for config serialization #12912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
b11c31d to
e08944e
Compare
|
Could you add tests? (and fix the failing CI checks) |
I don't think this change requires changelog. |
|
I think it does require a changelog entry. This changes the behavior of a public method in a public package. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #12912 +/- ##
==========================================
+ Coverage 91.61% 91.63% +0.01%
==========================================
Files 505 505
Lines 28409 28429 +20
==========================================
+ Hits 26027 26051 +24
+ Misses 1873 1870 -3
+ Partials 509 508 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d299e9b to
7efced9
Compare
|
I have completed all the changes from my end, and the implementation is now ready for review. It should pass all CI checks successfully. Thank you for your patience. |
7286ad6 to
51c85aa
Compare
|
Please let me know if there's anything I might have missed in this PR or anything I can do to help expedite the review process. |
c775b48 to
596a7d3
Compare
|
@Dhruvit96 Sorry for the slow review, overall this looks good to me. Could you rebase? |
|
@evan-bradley I've rebased the branch, could you please have a look? |
|
I like the idea of checking whether a config struct can be marshalled and I think I think ultimately we should be okay since virtually all Collector binaries will need confmap anyway, but I want to make sure we're deliberate before we grow the transitive dependency list like this. @open-telemetry/collector-approvers any thoughts? |
|
From the 2025-05-21 SIG meeting: We think that since YAML is a superset of JSON, and confmap maintains close compatibility with YAML, we can get by with just testing JSON now to reduce the number of added dependencies. @Dhruvit96 Could you revise this PR so it only checks the output of |
|
Hi @evan-bradley, I've updated the PR to validate only JSON marshalling. However, this change did not reduce dependencies in any package other than the scrapertest. I agree with your point that YAML is a superset of JSON, and we might be able to rely on JSON validation alone. That said, since the dependency impact is similar, validating both JSON and YAML would make the testing more comprehensive. Could you please share your thoughts? |
| conf := confmap.New() | ||
| if err := conf.Marshal(config); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| configMap := conf.ToStringMap() | ||
|
|
||
| _, err := json.Marshal(configMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| conf := confmap.New() | |
| if err := conf.Marshal(config); err != nil { | |
| return err | |
| } | |
| configMap := conf.ToStringMap() | |
| _, err := json.Marshal(configMap) | |
| _, err := json.Marshal(config) |
If we remove marshaling with confmap, we should be able to only test JSON marshaling here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR introduces a generic safeguard to prevent panics during the marshalling of configuration maps. We observed that the OpenTelemetry Collector encountered panics when used in conjunction with the OpAMP extension. As identified in this comment, the root cause was a failure to marshal a configuration represented as a map[string]any.
Validating only the marshallability of structs does not address such scenarios, as marshalling errors in structs can often be resolved using the json:"-" tag. However, in the case of maps, resolving the issue requires the use of the mapstructure:"-" tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evan-bradley Based on the information provided above, could you please let me know the next steps?
|
Thanks @Dhruvit96. The dependency impact is coming from the use of |
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
77ea88e to
b12a992
Compare
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Description
This unit test enhancement ensures that the configuration can be serialized correctly.
Link to tracking issue
Fixes #12906