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

[chore] reuse the timer object when parsing #31802

Closed
wants to merge 4 commits into from

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Mar 18, 2024

Description:

This is a companion PR to handle recursive state of unmarshalers with open-telemetry/opentelemetry-collector#9750.

By reusing the same struct when parsing its contents, we can avoid running into an infinite loop.

Comment on lines 54 to 56
if t.LayoutType == "" {
t.LayoutType = StrptimeKey
}
Copy link
Member

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 set default values in the unmarshaller? If we need this one then why not others? Maybe this is just a matter of test cases creating the default config consistently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code was doing this previously in the NewTimeParser path. Instead of creating a new struct, I just set the default here now.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why though. The pattern we use elsewhere is to instantiate a default struct and then unmarshal into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, that's the only instance this occurs afaict? By patching this code open-telemetry/opentelemetry-collector#9750 works well.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is a well established pattern throughout the repo to create a default config and then unmarshal into them. For pkg/stanza operators, it is somewhat cryptic but is handled here where we've basically looked up a factory for the specific operator and asked it for a new (default) config. I don't think we should be handling default values here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, in that case, since the default value is set earlier, we can safely remove the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like that didn't work: the registry works well to set default values, but because TimeParser is optional on helper.ParserConfig, it is nil by default, and since it's not initialized with default values, they don't get applied later on.

Copy link
Member

Choose a reason for hiding this comment

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

@atoulme Can't we do the trick from https://github.com/open-telemetry/opentelemetry-collector/blob/c72092e00151ce8e4cfef32c73b3a80d54076278/receiver/otlpreceiver/config.go#L68-L70 ? That is, set the configuration, but remove it during unmarshaling if the key is not set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, that's the right fix. I will try to get to it.

@atoulme
Copy link
Contributor Author

atoulme commented Apr 8, 2024

We're stuck on #31802 (comment)

@open-telemetry open-telemetry deleted a comment from github-actions bot Apr 8, 2024
@atoulme
Copy link
Contributor Author

atoulme commented Apr 19, 2024

Closing in favor of #32568

@atoulme atoulme closed this Apr 19, 2024
djaglowski pushed a commit that referenced this pull request Apr 20, 2024
**Description:**
Fix unmarshaling of TimeParser to conserve initial settings before
unmarshaling.

**Link to tracking Issue:**
Fixes #32169

**Testing:**
Added the test from the issue.

For @mx-psi I could not make it so we would apply
#31802 (comment)
because `TimeParser` is reused on all operators, and therefore it
becomes contentious to patch all over the place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants