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
[config] Deprecate config.UnmarshalConfig #9750
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9750 +/- ##
==========================================
- Coverage 91.67% 91.02% -0.65%
==========================================
Files 360 353 -7
Lines 16642 18633 +1991
==========================================
+ Hits 15256 16961 +1705
- Misses 1052 1347 +295
+ Partials 334 325 -9 ☔ View full report in Codecov by Sentry. |
0c0a748
to
311078f
Compare
Contrib tests fix: open-telemetry/opentelemetry-collector-contrib#31727 |
311078f
to
07fa33d
Compare
confmap/confmap.go
Outdated
@@ -37,7 +40,8 @@ func NewFromStringMap(data map[string]any) *Conf { | |||
// Conf represents the raw configuration map for the OpenTelemetry Collector. | |||
// The confmap.Conf can be unmarshalled into the Collector's config using the "service" package. | |||
type Conf struct { | |||
k *koanf.Koanf | |||
k *koanf.Koanf | |||
self any |
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.
Before I think we could call the same Conf
to unmarshal it on two different structs, but now it can only be used once, right? Is there any way we can restore that property? If not, is there a way where we can error out if we have already unmarshaled?
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 doesn't break your ability to use the same Conf
to unmarshal on two different structs. It stops recursive calls as part of unmarshaling from calling Unmarshal
on the same object twice.
ccbf4cc
to
f8f4fe6
Compare
This is a split of #9750 that tries to work around mapstructure, which wraps an error around a decoding error. In the case when an error is returned from a top level construct, we get a not so helpful message that says: ``` error decoding '': error running encode hook: marshaling error ``` With this change, the error is unwrapped, giving the following string representation: ``` error running encode hook: marshaling error ``` Because #9750 enforces going through mapstructure, it would change errors returned with this not-so-helpful preamble. Adding this removes the problem.
This change is required in preparation of #9750 This removes the call to `component.UnmarshalConfig` in preparation of its deprecation, and instead has the `Conf` object unmarshal itself into the `Config` struct.
51e5f78
to
dfa57f1
Compare
Can you add 'Fixes #7101' to the PR description? |
confmap/confmap.go
Outdated
for i := 0; i < to.Type().NumField(); i++ { | ||
// check embedded structs: | ||
f := to.Type().Field(i) | ||
if f.IsExported() && f.Anonymous && slices.Contains(strings.Split(f.Tag.Get("mapstructure"), ","), "squash") { |
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.
Why do we need to check for 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.
This is explained in the comment above: if the embedded struct is using the ,squash
value for the mapstructure
key, then this struct Unmarshal method should not be used as the main struct unmarshaling.
**Description:** This is a companion PR to handle recursive state of unmarshalers with open-telemetry/opentelemetry-collector#9750. Changing this behavior will allow the confmap.Conf object to recognize that it has already run the `Unmarshal` method on the struct, and run the mapstructure decoding of fields.
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
429f386
to
4445cc4
Compare
4445cc4
to
05a0d08
Compare
Description:
This PR removes the top level if/else in
component.UnmarshalConfig
, handling recursive state in the confmap.Conf object instead.This PR deprecates
component.UnmarshalConfig
in favor of calling directlyUnmarshal
on the confmap.Conf object.Link to tracking Issue:
Fixes #7102
Fixes #7101