Validate the controller config.#849
Conversation
| } | ||
|
|
||
| // WithConfigValidation is a function that enables the validation of the config. | ||
| func WithConfigValidation() option { |
There was a problem hiding this comment.
nit: maybe change the func to take an enabled bool argument. This often makes it easier for callers that need to construct the config dynamically. Without the bool arg, they have to dynamically assembly a list of []option values (can they even do that if the type is unexported?) and do some branches. With the bool arg it's as simple as WithConfigValidation(*validationFlag == true) (example).
There was a problem hiding this comment.
I assumed that users would either always want configuration validation or never — but not switch dynamically.
As you pointed out, since it’s not possible to have a list of []option (which is quite limiting), I introduced a validation bool to cover the use case you mentioned.n
|
Why do this as an option? I would run validation all the time. |
Currently, validation only occurs if WithConfigValidation(true) is explicitly set. By default, no validation is performed. In practice, validation is triggered in main.go within this repository, as well as in our repository. This is why I believe providing it as a configurable feature adds value.
Could you expand a bit on this point? |
|
What I mean is that if we move validation check into this controller, I don't see the need to increase the package's complexity by adding an option. I would just run the validation. |
As the idea is to remove main.go and integrate with OTel collector, I think, the focus should be how this change would fit best in the OTel collector concept. |
That makes sense, if adding a minor potential breaking change is acceptable to you. @florianl: Do you have any objections to always validating the config? |
|
This is still under heavy development, and we don't even have releases yet. So there's no notion of breaking changes 😉 |
| // Handle nil errors | ||
| if err != nil || tt.wantError != nil { | ||
| require.ErrorAs(t, err, &tt.wantError) | ||
| } |
There was a problem hiding this comment.
Sorry for the back and forth.
But this condition doesn't seem valid. It only checks if there is no error and we expect one.
What if there is an error and we don't expect any?
| // Handle nil errors | |
| if err != nil || tt.wantError != nil { | |
| require.ErrorAs(t, err, &tt.wantError) | |
| } | |
| if tt.wantError == nil { | |
| require.NoError(t, err) | |
| } else { | |
| require.ErrorAs(t, err, &tt.wantError) | |
| } |
There was a problem hiding this comment.
What if there is an error and we don't expect any?
if there is an error err != nil is true and so require.ErrorAs(t, err, &tt.wantError) is run.
There was a problem hiding this comment.
I don't think this function is intended to be called by component authors, as it is being called for each component during collector setup: https://github.com/open-telemetry/opentelemetry-collector/blob/v0.137.0/otelcol/config.go#L49
Indeed, the Validate call was removed from all collector contrib components during open-telemetry/opentelemetry-collector-contrib#33498
Wdyt of adding the component.Config interface type assertion for the receiver's Config structure and test the validation with component.ValidateConfig instead? (example https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/35199/files)
|
@rogercoll : This is an interesting idea. I can think of two solutions to add a
I am open to implement any of these solutions (Or another one), but as there were quite a lot of back and forth, I would like every reviewers to be agreed before starting the implementation. Any preferences between cc @dmathieu |
|
I think following what the core collector components are doing is always better. |
|
@dmathieu Any preference between solution |
|
I would go with option 2 to avoid copying things even more. |
|
As none of the code in this PR will be keep, close this PR in favor of #859 |
Description
This PR adds an option to validate the controller config.
EDIT: Always validate the config.
Alternative implementation:
Here is an alternative implementation:
collector.Configinto thecontrollerConfigcollector.Configtocontroller.Config. Replace this code bycontroller.Configtocollector.Config.