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

Adding support for Kafka partition key (based on OTEL attribute value) #29433

Open
nirb-s1 opened this issue Nov 21, 2023 · 10 comments
Open

Adding support for Kafka partition key (based on OTEL attribute value) #29433

nirb-s1 opened this issue Nov 21, 2023 · 10 comments
Labels
enhancement New feature or request exporter/kafka

Comments

@nirb-s1
Copy link

nirb-s1 commented Nov 21, 2023

Component(s)

exporter/kafka

Is your feature request related to a problem? Please describe.

Currently the kafka exporter doesn't provide a way to define a partition key at all which means that messages aren't orders in kafka topic if topic includes multiple partitions.

If also means that if metrics are re-send due to timeouts, we are required to handle duplications on consumer side instead of using kafka compaction on topic option which is also based on partition key.

Describe the solution you'd like

Define in kafka exporter configuration an attribute that will be used as partition key, if not set use the existing default behaviour.

Example:
Use attribute os.hostname as partition key, than all metrics of same hostname will arrive to same consumer eventually.

Describe alternatives you've considered

Without such capabilities, we are required to build dedup capabilities on consumer side

Additional context

No response

@nirb-s1 nirb-s1 added enhancement New feature or request needs triage New item requiring triage labels Nov 21, 2023
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@crobert-1
Copy link
Member

Hello @nirb-s1, from my understanding this sounds like a valid request.

The exporter is currently relying on the sarama package, which exposes this option. We'd simply add the specified partition when marshalling messages.

I don't have enough context to be able to answer to how to handle failures, so I'll have to defer to others there. I also don't have a lot of kafka experience in general, so the code owners may overrule what I've said here in case I've misunderstood something.

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Nov 28, 2023
@VihasMakwana
Copy link
Contributor

I'll have a crack at this. Will open up a PR soon.

@nirb-s1
Copy link
Author

nirb-s1 commented Dec 6, 2023

thanks @VihasMakwana for helping here, this will be highly appriciate and can save us tons of complexity and cost to handle de-duplication situations.

@nirb-s1
Copy link
Author

nirb-s1 commented Dec 6, 2023

btw, another idea / ask from this feature is to be able to use the metric timestamp in the partition key somehow so we can use Kafka topic compaction

Copy link
Contributor

github-actions bot commented Feb 5, 2024

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label Feb 5, 2024
@nirb-s1
Copy link
Author

nirb-s1 commented Feb 5, 2024

@VihasMakwana thanks for jumping on this, I see that it will be auto closed if no one will work on it, did you had a chance to check it?

@crobert-1 crobert-1 removed the Stale label Feb 5, 2024
@VihasMakwana
Copy link
Contributor

Hi, sorry about it.
I got busy with some other stuff at work.
Will work on it to finish what I started

@VihasMakwana VihasMakwana removed their assignment Mar 29, 2024
dmitryax pushed a commit that referenced this issue Apr 29, 2024
**Description:** Add resource attributes based partitioning for OTLP
metrics

In our backend we really need an ability to distribute metrics based on
resource attributes.
For this I added additional flag to the configuration.
Some code from traces partitioning by traceId reused.

Judging by issues, this feature is anticipated by several more people.

**Link to tracking Issue:**
[31675](#31675)

Additionally this feature was menioned in these issues:
[29433](#29433),
[30666](#30666)


**Testing:**
Added tests for hashing utility.
Added tests for marshalling and asserting correct keys and the number of
messages.
Tested locally with host metrics and chained OTLP metrics receiver.

**Documentation:** 
Changelog entry
Flag is added to the doc of KafkaExporter

---------

Co-authored-by: Curtis Robert <crobert@splunk.com>
rimitchell pushed a commit to rimitchell/opentelemetry-collector-contrib that referenced this issue May 8, 2024
…etry#31315)

**Description:** Add resource attributes based partitioning for OTLP
metrics

In our backend we really need an ability to distribute metrics based on
resource attributes.
For this I added additional flag to the configuration.
Some code from traces partitioning by traceId reused.

Judging by issues, this feature is anticipated by several more people.

**Link to tracking Issue:**
[31675](open-telemetry#31675)

Additionally this feature was menioned in these issues:
[29433](open-telemetry#29433),
[30666](open-telemetry#30666)


**Testing:**
Added tests for hashing utility.
Added tests for marshalling and asserting correct keys and the number of
messages.
Tested locally with host metrics and chained OTLP metrics receiver.

**Documentation:** 
Changelog entry
Flag is added to the doc of KafkaExporter

---------

Co-authored-by: Curtis Robert <crobert@splunk.com>
Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the Stale label May 29, 2024
@crobert-1 crobert-1 removed the Stale label May 29, 2024
@michpev
Copy link

michpev commented Jun 27, 2024

A question about this issue. The new attribute partition_metrics_by_resource_attributes still does not allow to select a specific way of determining keys, it will instead create a hash based on the resource attributes. Are there plans to add the ability to define the exact way in which the key will be derived from the message (like in the example provided in the original ask, with "os.hostname")?

The reason I need it is that in the project I'm working on, there is one place that receives info about some objects from various different sources (some of them don't use otel at all, though the ones that don't use sarama directly) and then does stuff based on the information it receives. However, that one place needs to be scaled into several pods, and each pod will have a consumer in a consumer group. We want to make sure that all messages about the same object will come to the same pod. So we wanted all places to send their messages with the key of the object's name (a unique identifier), and then they would all go into the same partition (sarama's default partitioner is a deterministic hash based on the key). But the current implementation doesn't allow for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request exporter/kafka
Projects
None yet
Development

No branches or pull requests

4 participants