-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for partition based scaling on the kafka scaler #6558
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 support for partition based scaling on the kafka scaler #6558
Conversation
a548ac9 to
c46e703
Compare
|
@dttung2905 @zroubalik , you are the Kafka experts xD |
dttung2905
left a comment
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.
Thank you very much for this PR. Personally, I like the direction this PR is heading to. Just 1 small comment for my understanding
|
/run-e2e kafka |
|
@zroubalik Any thoughts on the PR? |
c46e703 to
a7ad359
Compare
|
Force pushed a rebase |
|
/run-e2e kafka |
|
Would it be possible to add this functionality to the experimental kafka trigger as well? |
Yeah I could take a look at it. |
b18b0d1 to
56e8e43
Compare
|
/run-e2e kafka |
|
@rickbrouwer I don't see the logs for the failed test. Can you share how I can see them? |
Of course! https://github.com/kedacore/keda/actions/runs/15666250049/job/44131008541#step:9:1886 |
56e8e43 to
41591d7
Compare
@rickbrouwer The tests now pass with a rebase. Could it be possible it was a flake? |
zroubalik
left a comment
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.
@patelvp could you please fix conflicts and fix the static checks? I will trigger the e2e tests then.
Thanks!
41591d7 to
2eef3fc
Compare
|
@patelvp there is still an issue in the static checks |
2eef3fc to
ad2c2d9
Compare
|
/run-e2e kafka |
|
Looking at the test failures |
ad2c2d9 to
36603f3
Compare
|
Okay, I tried the test locally. It took me a while to figure out that our corporate VPN was blocking some image pulls for the test to run correctly. The fix was an indentation issue in the test template! |
|
/run-e2e kafka |
|
@rickbrouwer @zroubalik Should be good to review. Hoping I can make it in the next release so I don't have to keep maintaining this PR |
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.
Pull Request Overview
This PR adds support for partition-based scaling to the Kafka scaler through a new ensureEvenDistributionOfPartitions property. When enabled, this feature ensures that the number of Kafka consumer pods aligns with factors of the topic's partition count to guarantee even partition distribution across consumers.
Key changes include:
- Addition of the
ensureEvenDistributionOfPartitionsconfiguration option to both Kafka and Apache Kafka scalers - Implementation of mathematical logic to calculate appropriate scaling factors based on partition counts
- Comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/scalers/kafka_scaler.go | Implements core logic for partition-based scaling and factor calculation |
| pkg/scalers/apache_kafka_scaler.go | Adds the new configuration option to Apache Kafka scaler |
| pkg/scalers/kafka_scaler_test.go | Adds comprehensive unit tests for metadata parsing and factor calculations |
| pkg/scalers/apache_kafka_scaler_test.go | Updates test data structures to include new configuration option |
| tests/scalers/kafka/kafka_test.go | Adds integration tests for the new scaling behavior |
| tests/scalers/apache_kafka/apache_kafka_test.go | Adds integration tests for Apache Kafka scaler |
| CHANGELOG.md | Documents the new feature addition |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@patelvp could you please check the review comments? |
|
yes. imo, once all the comments are addresssed, it should be good to merge |
|
@patelvp could you please resolve the comments so we can include this PR into the next release |
I will get to this today |
36603f3 to
1e8412a
Compare
Scaling kafka consumers should be done in factors of partition count on the topic. This is to ensure that the partitions are evenly spread across all consumers. If the paritions are not evenly spread we run the risk of some partitions being consumed faster than other. This PR adds a new property on the kafka scaler `ensureEvenDistributionOfPartitions`. When this property is set to true the scaler ensure that the number of pods are always evenly spread across the number of topics on the partition. Signed-off-by: Vishal Patel <[email protected]>
1e8412a to
315364c
Compare
|
@zroubalik Should be good now! |
|
/run-e2e kafka |
…#6558) Scaling kafka consumers should be done in factors of partition count on the topic. This is to ensure that the partitions are evenly spread across all consumers. If the paritions are not evenly spread we run the risk of some partitions being consumed faster than other. This PR adds a new property on the kafka scaler `ensureEvenDistributionOfPartitions`. When this property is set to true the scaler ensure that the number of pods are always evenly spread across the number of topics on the partition. Signed-off-by: Vishal Patel <[email protected]> Signed-off-by: Dmitriy Altuhov <[email protected]>
…#6558) Scaling kafka consumers should be done in factors of partition count on the topic. This is to ensure that the partitions are evenly spread across all consumers. If the paritions are not evenly spread we run the risk of some partitions being consumed faster than other. This PR adds a new property on the kafka scaler `ensureEvenDistributionOfPartitions`. When this property is set to true the scaler ensure that the number of pods are always evenly spread across the number of topics on the partition. Signed-off-by: Vishal Patel <[email protected]>
Issue: #2581
Scaling kafka consumers should be done in factors of partition count on the topic. This is to ensure that the partitions are evenly spread across all consumers. If the paritions are not evenly spread we run the risk of some partitions being consumed faster than other. This PR adds a new property on the kafka scaler
ensureEvenDistributionOfPartitions. When this property is set to true the scaler ensure that the number of pods are always evenly spread across the number of topics on the partition.Checklist
Fixes #2581
QA:

Tested this locally by pushing an image on a local kind cluster. Kafka consumer and producers are outside the cluster to get granual and quick control over production and consumption rate.
Plotted the pod count and kafka partition lag onto grafana.