-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add helpers to construct connector.*Router
s for tests
#7673
Add helpers to construct connector.*Router
s for tests
#7673
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #7673 +/- ##
==========================================
- Coverage 91.14% 91.10% -0.04%
==========================================
Files 298 299 +1
Lines 14912 14942 +30
==========================================
+ Hits 13591 13613 +22
- Misses 1045 1051 +6
- Partials 276 278 +2
☔ View full report in Codecov by Sentry. |
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.
Generally looks good to me. Just a couple nits.
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.
LGTM.
@bogdandrutu, do you care to review this?
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 changes to all signal types.
connector/connectortest/router.go
Outdated
} | ||
|
||
// WithTracesSink adds a consumer to a connector.TracesRouter | ||
func WithTracesSink(id component.ID, sink *consumertest.TracesSink) TracesRouterTestOption { |
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 not just WithTraces
and accept a consumer.Traces
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.
This was my suggestion. The idea was to limit the usefulness of the TracesRouter to tests only.
If we accept any consumer.Traces
, then we might want to just export fanoutconsumer and let people build routers directly.
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.
May not be a bad idea (not the whole fanoutconsumer
) only the router part correct? You don't need the fanoutconsumer.NewLogs
.
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.
Is there any reason why someone would need to create a router other than for testing purposes?
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 propose we expose additional functionality later, if it proves necessary.
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.
@bogdandrutu, WDYT?
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.
This looks good to me, happy to merge once @bogdandrutu's confirmed his feedback has been addressed
b749609
to
cb6a3c5
Compare
Alternative that I have in my mind is: Make
Main idea is that we don't expect alternative implementation of the interface, and we also solve the inconsistency between 1 vs multiple pipelines. Another benefit is that right now we will have 2 implementations of the interface (test and non-test). |
I like the idea of being more explicit about what is being provided to the factory funcs but I think this signature implies that all connectors are routers and forces all connector authors to work with this new struct. Many (maybe most) connectors should not be concerned with routing and only need a "consumer.Traces" like all other pipeline components. The other problem is that this would be a breaking change to the What if instead, we define a set of factory funcs specifically for routers? e.g. Another option is:
|
I'm struggling to pick a clear winner between these options. I agree with @djaglowski that passing a router into the factory will be confusing for connectors that do not do routing (which is probably the majority use case). I like the option where we keep the factory functions as is, but always pass in a fanoutconsumer or the status quo. In both cases we'll need expose the necessary types for tests. I'm not completely opposed to adding additional factory functions for routers, but I think we still end up in the same situation where the connector internals will need to decide which factory function to call, likely based on the number of consumers (as it is today). If we can agree on an approach, I'd be happy to see the work through. |
This is my preferred approach. It's simple, non-breaking, and solves both problems. @bogdandrutu, can we move forward with this? |
Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com>
cb6a3c5
to
2a8230c
Compare
the too few pipelines issue was resolved by open-telemetry#7840
2a8230c
to
b7c6238
Compare
@bogdandrutu, if you get a chance, could you take another look at this. It goes along with #7840 and solves all of the issues I ran into in open-telemetry/opentelemetry-collector-contrib#21498. |
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.
This should be merged in my opinion.
/easycla |
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 believe all the concerns were addressed w/ the discussion around #7840 and this PR from last week's SIG call.
**Description:** This PR introduces a connector version of the routing processor. It currently supports routing based on resource attributes OTTL statements only. Context based routing will be added later in a followup PR. There are two issues regarding fanout consumers that are being addressed in the core repo. * The routing connector needs to be a consumer in multiple pipelines (the routing processor can route to a single exporter). * Will be resolved by: open-telemetry/opentelemetry-collector#7840 * We need the ability to create connector routers to facilitate testing. I had to temporarily copy the fanoutconsumer package into the routing connector codebase due to package visibility issues. * Will be resolved by: open-telemetry/opentelemetry-collector#7673 We can address these issues as the relevant PRs land on the core repo. cc: @djaglowski, @jpkrohling, @kovrus **Link to tracking Issue:** #19738 **Testing:** Unit / manual **Documentation:** The readme has been ported from the routing processor --------- Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com> Co-authored-by: Ruslan Kovalov <ruslan.kovalov@grafana.com>
Description:
This PR adds helpers to
connectortest
to aid the construction ofconnector.*Router
s for testing connectors. This was implemented based on @djaglowski's comment here, with some slight modifications. I found it more ergonomic to pass the sink into theWithTracesSink
(and similar) options. You usually want a handle on the sink after creating the router. While it's possible to get the sink out of the router after the fact, it's a little cumbersome.These helpers will be useful for open-telemetry/opentelemetry-collector-contrib#21498 and future connectors that need use of routers.
For example, here is a test with the consumer passed in:
The same test having to extract the consumer out after the fact:
Link to tracking Issue:
#7672
Testing:
Unit tests
Documentation:
Source code comments