Skip to content
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

[confmap] Remove top level lock when considering struct as Unmarshalers. #9862

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Mar 27, 2024

This is a slice of #9750 focusing on removing the top level lock on unmarshaling structs.

@atoulme atoulme requested a review from a team as a code owner March 27, 2024 06:08
@atoulme atoulme changed the title Remove top level block Remove top level lock when considering struct as Unmarshalers. Mar 27, 2024
@atoulme atoulme changed the title Remove top level lock when considering struct as Unmarshalers. [confmap] Remove top level lock when considering struct as Unmarshalers. Mar 27, 2024
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.53%. Comparing base (ae83654) to head (9afa5ef).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9862      +/-   ##
==========================================
- Coverage   91.54%   91.53%   -0.01%     
==========================================
  Files         360      360              
  Lines       16695    16699       +4     
==========================================
+ Hits        15284    15286       +2     
- Misses       1074     1075       +1     
- Partials      337      338       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

confmap/confmap_test.go Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap_test.go Show resolved Hide resolved
@atoulme
Copy link
Contributor Author

atoulme commented Apr 1, 2024

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

I think I finally understood this! I filed #9879 separately that adds two confmap tests. I would want to merge that one and #9861 first if that makes sense to you.

confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
confmap/confmap_test.go Show resolved Hide resolved
confmap/confmap.go Outdated Show resolved Hide resolved
@mx-psi
Copy link
Member

mx-psi commented Apr 2, 2024

It would also be interesting to try and reproduce the failing contrib test on a unit test here, so we can work on it. The offending Unmarshal function is here https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/e4c5b51ec0e24ca163bcb64d944455577f90a09f/pkg/stanza/operator/helper/time.go#L49

mx-psi added a commit that referenced this pull request Apr 2, 2024
**Description:** Adds two tests to confmap to test some edge cases

**Link to tracking Issue:** Written while reviewing #9862
@atoulme
Copy link
Contributor Author

atoulme commented Apr 3, 2024

It would also be interesting to try and reproduce the failing contrib test on a unit test here, so we can work on it. The offending Unmarshal function is here https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/e4c5b51ec0e24ca163bcb64d944455577f90a09f/pkg/stanza/operator/helper/time.go#L49

added a skipped test here: TestRecursiveUnmarshaling

@atoulme
Copy link
Contributor Author

atoulme commented Apr 3, 2024

If you want a foolproof solution, we might have to do something a little more drastic. We might need to keep a hashset of all pointers of unmarshaler methods ever called, to make sure we don't run into cycles.

@mx-psi
Copy link
Member

mx-psi commented Apr 3, 2024

If you want a foolproof solution, we might have to do something a little more drastic. We might need to keep a hashset of all pointers of unmarshaler methods ever called, to make sure we don't run into cycles.

I guess we can forbid what the stanza package does instead. Do you think there is a benefit to being able to do what stanza does? I can't see any advantage right now

@atoulme
Copy link
Contributor Author

atoulme commented Apr 4, 2024

No, I don't see any advantage, except maybe if you're trying to unmarshal and set all values on the struct atomically. Even then, this is a corner case. I think we're ok.

confmap/confmap_test.go Outdated Show resolved Hide resolved
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

I am okay with the current approach, I guess we should document the limitation about nested unmarshalling before merging, but I think we can go with this.

cc @open-telemetry/collector-approvers, I would appreciate a second pair of eyes since this is somewhat subtle. Even if this is ready before, I will wait at least until Monday to merge to give others some time to review.

@atoulme
Copy link
Contributor Author

atoulme commented Apr 21, 2024

One more PR in contrib needed: open-telemetry/opentelemetry-collector-contrib#32577

djaglowski pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Apr 22, 2024
**Description:**
Update contrib to match core with the latest changes that are needed for
open-telemetry/opentelemetry-collector#9862
atoulme and others added 6 commits April 23, 2024 21:17
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
atoulme and others added 9 commits April 23, 2024 21:17
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
@atoulme
Copy link
Contributor Author

atoulme commented Apr 25, 2024

The last contrib issue is solved by open-telemetry/opentelemetry-collector-contrib#32660. Unfortunately, I couldn't find a good way to fix this - in effect, a breaking change.

Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Looks good to me, I think this is probably the cleanest solution given the current state of things.

@@ -41,6 +41,10 @@ func NewFromStringMap(data map[string]any) *Conf {
// The confmap.Conf can be unmarshalled into the Collector's config using the "service" package.
type Conf struct {
k *koanf.Koanf
// If true, upon unmarshaling do not call the Unmarshal function on the struct
// if it implements Unmarshaler and is the top-level struct.
// This avoids running into a circular dependency.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should define what the circular dependency is here. I think calling out the potential for an infinite recursion caused by Unmarshaler.Unmarshal and Conf.Unmarshal calling each other would probably be a good mention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting for reviews
Development

Successfully merging this pull request may close these issues.

None yet

4 participants