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
[processor/transform] Add support for flat configuration style #37444
base: main
Are you sure you want to change the base?
[processor/transform] Add support for flat configuration style #37444
Changes from all commits
e7e44e7
68f2056
aa14b21
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.
It's currently being set programmatically, and does not allow users to configure it on their configurations (https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/37444/files#diff-1e527186a992bb04852a9e8cd6fe43ef611d0e071360c4e40a1432a30efc1d38R89).
That's a conservative approach to keep the behavior the same, but there's no technical reason to not allow it.
if you folks also think it might be useful, we could make this setting available, so users would be able to control which statement's groups are using the shared cache.
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.
Lets be opinionated and hide it for now. Config support can be added later.
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.
Can we unexport it and/or remove the mapstructure tags? That would mean the unmarshal function doesn't have to worry about users trying to set 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.
TBH, I couldn't find a clean solution for this field, so I ended up with this approach, considering there's a possibility of making this setting available to users in the future.
Given we're still relying on
mapstructure
to unmarshal the configuration, unexporting this field would require both, a custom unmarshalling function forcommon.ContextStatements
to set the field value, and some mechanism to pass this information down from thetransformprocessor.Config
Unmarshal function (which is the one who knows its value). Unexported fields are ignored by mapstructure as it's not possible to set their values using reflection.I was able to unexport it and make it work by passing the extra
shared_cache
key here (as it's currently doing), and an extraconfmap.WithIgnoreUnused()
option here (otherwisemapstructure
returns an error), then with that key in the conf map, we just need to read it and set the field value on thecommon.ContextStatements
unmarshaller function. The problem with this approach is that invalid keys are not validated anymore, and we would need to validate them manually, which IMO, is not ideal.Finally, another option would be removing the
mapstructure
tag and keep it exported, so we wouldn't need to worry about users trying to set it on their configurations. To set it internally, we would need to use reflection, as I initially implemented on the draft (see 498f9b1).Do you have any thoughts or ideas on how to work it around?
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 was hoping that since we're using a custom unmarshaller we it could be the definitive source of whether that value should be true or false. In my head we'd be able to identify if the user is using the flat style and then set
c.sharedCache
ourselves in the Unmarshall func.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.
Here is an example of the otlpreceiver doing something similar: https://github.com/open-telemetry/opentelemetry-collector/blob/2447a81885fc580860860bd6a8768422a70c99f8/receiver/otlpreceiver/config.go#L63-L90
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.
Looking at the implementation again, really any time we're doing
map[string]any
manipulation in the Unmarshall function it would be great to work directly on thec *Config
if we can.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.
We're still relying on
mapstructure
to unmarshall the configuration, the current logic is only normalizing the flat configuration style yaml map so it can be properly unmarshalled as it was configured using the structured configuration style. That's why we're manipulatingmap[string]any
values instead of theConfig
struct.In that case it has a 1:1 relation, the yaml config map is compatible with the target structure, so it can call
conf.Unmarshal
on the very beginning as it's doing. It does not apply to us, as the flat configuration styles is not compatible with theConfig
struct.If we move some code around, we can unexport the field and have a hybrid approach without using reflection. After calling
conf.Unmarshal
, we can iterate over the context statements setting thesharedCache
value. For that, we would need to put bothtransformprocessor.Config
andcommon.ContextStatements
into the same package, which I guess wouldn't be an issue.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.
ya something like this sounds like a good idea to try.