-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Should ConfigValidator be in confmap? #11524
Comments
Is it correct to say from a component developer perspective it doesn't matter where it lives? |
Yes, but if we want to use confmap in other places like I said in |
I agree |
I don't have a strong opinion on this (which makes me lean slightly into "leave it as it is") |
Today I believe that |
Thinking about this again, I feel like it makes sense to move this to |
@bogdandrutu If we were to move this, what would we do with |
Do we even need |
@dmitryax Here are the places where this is used: https://github.com/search?q=org%3Aopen-telemetry+language%3AGo+component.ValidateConfig&type=code There are a lot of usages that could be avoided/converted, but I am not confident that we would be able to remove all of them. |
We discussed this issue during the stability SIG meeting of 1/6 and came up with the following suggestions:
|
I'll submit a PR to move validation stuff to |
@bogdandrutu @atoulme @dmitryax would adding support for https://github.com/go-playground/validator be a breaking change? Config validation is an important part of collector 1.0 and the Validator interface is a sufficient solution. I think we could move forward with our Validator interface for 1.0 and add support for https://github.com/go-playground/validator as a feature add after. |
Thinking about If we must move
Component also defines the public // Config defines the configuration for the various elements of collector or agent.
type Config struct {
// Receivers is a map of ComponentID to Receivers.
Receivers map[component.ID]component.Config `mapstructure:"receivers"`
// Exporters is a map of ComponentID to Exporters.
Exporters map[component.ID]component.Config `mapstructure:"exporters"`
// Processors is a map of ComponentID to Processors.
Processors map[component.ID]component.Config `mapstructure:"processors"`
// Connectors is a map of ComponentID to connectors.
Connectors map[component.ID]component.Config `mapstructure:"connectors"`
// Extensions is a map of ComponentID to extensions.
Extensions map[component.ID]component.Config `mapstructure:"extensions"`
Service service.Config `mapstructure:"service"`
} I agree that if Here is what I propose we do to move forward without any experimental packages.
This plan leaves |
I think we can build a shim with a ConfigValidator impl that calls out to Validator as part of a POC to see what the end user experience is. |
#12027 is open for the validator POC. |
I ran into an issue today while implementing validation in the Unmarshal. While it does work for invoking the This is because |
There is also an issues when components implement custom Unmarshal functions. For example, the otlpreceiver implements a custom unmarshaller than requires that the user have set receivers:
otlp: the collector should fail validation. The custom unmarshaller first calls |
I was able to work around the custom unmarshal issue by updating the cases in the reflective This means the components validate function may get executed multiple times. I believe that is safe. |
Created #12031 to add |
…#12102) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Updates `component.ValidateConfig` to recurse through the entire config object by checking for `ConfigValidator` implementations of structs that are under interfaces. Right now `ValidateConfig` stops at things like `component.Config` which themselves can't implement `component.ValidateConfig` because `callValidateIfPossible` can only see the interface and not the concrete type before this change. <!-- Issue number if applicable --> #### Link to tracking issue Replaces #12058. Works toward #11524. Co-authored-by: Evan Bradley <evan-bradley@users.noreply.github.com>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Builds on #12224 and starts the move of config validation from component to confmap. We can keep this in `xconfmap` while we determine whether to add the ability to validate using struct field tags. I think this has the following advantages: 1. Everything configuration-related is now in confmap instead of split between confmap and component. 2. We can share things like the mapstructure tag and config key separator as constants between unmarshaling and validation without creating dependencies between confmap and component. ~The one uncertainty this creates is what to do with `component.Config`, which would now be used as a thin alias for `any` without any meaningful usage in component.~ <!-- Issue number if applicable --> #### Link to tracking issue Fixes #11524
Is your feature request related to a problem? Please describe.
Currently the
ConfigValidator
is part of thecomponent
package, and for example inmdatagen
where we use confmap it is a bit strange to depend on thecomponent.ConfigValidator
for config validation.Describe the solution you'd like
Provide the configuration
Validator
as part of theconfmap
repository, and probably make it part ofConf.Unmarshal
(configurable) to also do validation.Describe alternatives you've considered
Leave where it is right now.
The text was updated successfully, but these errors were encountered: