-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Static validation of improper connector usage in config files during dry-run #12681
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
Static validation of improper connector usage in config files during dry-run #12681
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #12681 +/- ##
==========================================
- Coverage 91.55% 91.55% -0.01%
==========================================
Files 481 481
Lines 26391 26420 +29
==========================================
+ Hits 24162 24188 +26
- Misses 1766 1768 +2
- Partials 463 464 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…dry runs Signed-off-by: sudipto baral <[email protected]>
Signed-off-by: sudipto baral <[email protected]>
Signed-off-by: sudipto baral <[email protected]>
Signed-off-by: sudipto baral <[email protected]>
18bab32
to
bf9fe79
Compare
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.
minor comments, otherwise LGTM
Factories: nopFactories, | ||
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-invalid-connector-use.yaml")}), | ||
}, | ||
expectedErr: `connector "nop/connector1" used as exporter in [logs/in2] pipeline but not used in any supported receiver pipeline`, |
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.
could you add another case on connector being used in receivers but not in exporters?
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.
added new tests
service/service_test.go
Outdated
|
||
err := ValidateConnectors(connectorCfg, pipelinesCfg, connectorsFactories) | ||
require.Error(t, err) | ||
assert.Equal(t, "connector \"nop/connector1\" used as exporter in [logs/in2] pipeline but not used in any supported receiver pipeline", err.Error()) |
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.
same here
Signed-off-by: sudipto baral <[email protected]>
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't we just instantiate the graph as usual and check for an error?
In my opinion adding special code paths for validation unnecessarily complicates an already complex package. Instantiating the graph should be a low cost and repeatable operation which returns verbose errors if the graph is invalid. |
Yes, I agree, If we instantiate the graph we will also be able to surface cycle errors which is not possible to capture in this approach. |
I am suggesting that we instantiate the graph only, not the service. |
Hi @djaglowski, could you please take a look at PR #12712, this PR uses the graph.Build() method to surface configuration errors during the dry run. |
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description As described in [#8721](#8721), the current `validate` command cannot capture improper connector usage errors during a dry run. One proposed solution _(as mentioned in [this comment](#8721 (comment) is to surface configuration errors by instantiating the service during the dry run. However, reviewers preferred statically verifying the errors over instantiating the service (see the [PR #12488 comments](#12488)). The validation logic for connectors is located in the [`service/internal/graph`](https://github.com/open-telemetry/opentelemetry-collector/blob/1daa315455d02bac90185027878d858ba08a0f07/service/internal/graph) package. In the discussion of [PR #12681](#12681), it was concluded that instantiating the graph is the better approach (see [this comment](#12681 (comment))). Finally, this PR uses the `graph.Build()` method to surface configuration errors during the dry run. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #8721 #12535 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: sudipto baral <[email protected]>
As @djaglowski suggested, let's use #12488 I think I was not sure about how much we start, but we only create the components, not start them. |
Description
As described in #8721, the current
validate
command cannot capture improper connector usage errors during a dry run.One possible solution (as mentioned in this comment) is to surface configuration errors by instantiating the service during a dry run. However, reviewers indicated that statically verifying the errors is preferable to instantiating the service (see the PR
#12488 comments).
Currently, the validation logic for connectors is embedded in the
service/internal/graph
package. This PR extracts the relevant validation logic and uses it duringdry-run
to statically validate connector configurations.Link to tracking issue
Fixes #8721