Skip to content
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

[kafka] Add option to supply destination topic through context #34503

Merged
merged 13 commits into from
Sep 17, 2024

Conversation

tylerbenson
Copy link
Member

Description:

Add option to get destination topic from context. This allows for upstream connectors to control the destination without polluting the data being written.

Link to tracking Issue:
Fixes #34432

Testing:
Added unit tests.

Documentation:
Updated the component readme with the added setting.

@tylerbenson tylerbenson requested a review from a team August 7, 2024 21:52
@tylerbenson tylerbenson changed the title Add option to get destination topic from context Add option to supply destination topic through context Aug 8, 2024
@tylerbenson tylerbenson marked this pull request as draft August 12, 2024 13:48
@tylerbenson tylerbenson marked this pull request as ready for review August 12, 2024 17:52
@pavolloffay
Copy link
Member

@codeboten can we move this PR forward?

mx-psi
mx-psi previously requested changes Aug 30, 2024
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to block this at the last minute but I don't think we should add an allowlist exception for this. Arbitrary Go API for building packages should be either in internal (if meant only for Collector contrib components) or in pkg (if meant also for external components, in which case I would like to have an example of which external component is going to use this)

exporter/kafkaexporter/topic/kafka_exporter_ctx.go Outdated Show resolved Hide resolved
@mx-psi
Copy link
Member

mx-psi commented Sep 2, 2024

To make CI pass so I can merge this PR you need to run make crosslink and add back the component to .github/CODEOWNERS

Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I want to encourage passing metadata via context, in my experience it has not lead to a good time and often caused more issues than what it attempts to solve.

I also think this could create non deterministic behaviour (from a user's perspective) where data is being routed to topics that don't exist or conditions of which the data is routed to a topic do not make sense.

I would prefer users using the routing connector and having several kafka exporters that is very clearly configured and understood how data is being routed and delivered.

@MovieStoreGuy
Copy link
Contributor

MovieStoreGuy commented Sep 3, 2024

I am not blocking this PR because it appears there is some interest in having some form of dynamic routing configuration, but this is not the way I suggest it should done.

@brettbuddin
Copy link

brettbuddin commented Sep 4, 2024

@MovieStoreGuy I mostly agree with you. The situation is a bit tricky for us, because we write our own custom components for Gateway Collectors that run in a multi-tenanted fashion. Due to the breadth of tenant scope and broker/topic structure it's not reasonable for everything to be explicitly declarative via configuration.

In a perfect world we'd derive a topic name and print it into the telemetry attributes and leverage that value using existing component capabilities. However, we see the topic name as an internal detail and not something we want to expose to tenants via the database (post-ingestion). This is the best option we've come up with so far, because the Collector component architecture doesn't provide a mechanism for agent-local metadata propagation other than telemetry data or context.Context. That's a reasonable design decision to make for most situations, and if our use case is far enough out-of-bounds we can find other ways of dealing with it.

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MovieStoreGuy Could you take a look at the comments above?

@jpkrohling jpkrohling changed the title Add option to supply destination topic through context [kafka] Add option to supply destination topic through context Sep 6, 2024
@tylerbenson
Copy link
Member Author

Following up here. @pavolloffay @mx-psi @codeboten anything else I need to do?

@MovieStoreGuy
Copy link
Contributor

@MovieStoreGuy I mostly agree with you. The situation is a bit tricky for us, because we write our own custom components for Gateway Collectors that run in a multi-tenanted fashion. Due to the breadth of tenant scope and broker/topic structure it's not reasonable for everything to be explicitly declarative via configuration.

Yeah, I get where you're coming from. I also think this problem isn't strictly limited to Kafka, you still have the same problem with something like OTLP exporter as an example if you wanted to include some amount of auth/meta data.

In a perfect world we'd derive a topic name and print it into the telemetry attributes and leverage that value using existing component capabilities. However, we see the topic name as an internal detail and not something we want to expose to tenants via the database (post-ingestion). This is the best option we've come up with so far, because the Collector component architecture doesn't provide a mechanism for agent-local metadata propagation other than telemetry data or context.Context. That's a reasonable design decision to make for most situations, and if our use case is far enough out-of-bounds we can find other ways of dealing with it.

The approach does go against the recommendations of go design paradigms suggest where Context isn't recommended to be used for business logic, however, I can see why we'd need it.

I am happy to approve this, but once there is a notion of supporting tenancy, I'd like for this approach to be deprecated in favour of what is to come, does that sound reasonable to you?

@tylerbenson
Copy link
Member Author

I am happy to approve this, but once there is a notion of supporting tenancy, I'd like for this approach to be deprecated in favour of what is to come, does that sound reasonable to you?

I'm fine with that. I took this path because there wasn't another option for passing data along that wasn't embedded in the exportable data.

# Conflicts:
#	cmd/otelcontribcol/go.mod
#	exporter/kafkaexporter/go.mod
#	receiver/kafkareceiver/go.mod
@tylerbenson
Copy link
Member Author

I merged from main and resolved the conflicts.
The failing test doesn't look related to my change here.

@mx-psi mx-psi merged commit c1e2df6 into open-telemetry:main Sep 17, 2024
155 of 156 checks passed
@github-actions github-actions bot added this to the next release milestone Sep 17, 2024
@tylerbenson tylerbenson deleted the tyler/kafka branch September 17, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Kafka exporter to select topic from context
8 participants