Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[chore] reuse the timer object when parsing #31802
Changes from 2 commits
069485b
1878d83
469b41c
bf139d6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 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?
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.
The code was doing this previously in the
NewTimeParser
path. Instead of creating a new struct, I just set the default here now.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.
I don't understand why though. The pattern we use elsewhere is to instantiate a default struct and then unmarshal into it.
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.
no, that's the only instance this occurs afaict? By patching this code open-telemetry/opentelemetry-collector#9750 works well.
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.
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.
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.
I see, in that case, since the default value is set earlier, we can safely remove the check.
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.
Looks like that didn't work: the registry works well to set default values, but because
TimeParser
is optional onhelper.ParserConfig
, it is nil by default, and since it's not initialized with default values, they don't get applied later on.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.
@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
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.
you are right, that's the right fix. I will try to get to it.