Skip to content

Ability to trigger auto rebalance on imbalance feature - #13037

Draft
ShubhamRwt wants to merge 3 commits into
strimzi:mainfrom
ShubhamRwt:autoRebalanceFeature
Draft

Ability to trigger auto rebalance on imbalance feature #13037
ShubhamRwt wants to merge 3 commits into
strimzi:mainfrom
ShubhamRwt:autoRebalanceFeature

Conversation

@ShubhamRwt

Copy link
Copy Markdown
Contributor

Type of change

  • New feature

Description

This PR implements the proposal auto-rebalance-on-imbalance. This feature allows the operator to trigger rebalance automatically in case their are some imbalance in the cluster

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Update documentation
  • Update CHANGELOG.md (if present)
  • Reference relevant issue(s) and close them after merging
  • Write tests
  • Make sure all tests pass
  • Try your changes inside a Kubernetes cluster, not just from unit tests
  • AI assistance was used to create this PR (see the Strimzi AI policy)

@snyk-io

snyk-io Bot commented Aug 7, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@scholzj scholzj added this to the 1.3.0 milestone Aug 7, 2026
Signed-off-by: ShubhamRwt <[email protected]>
@ppatierno

Copy link
Copy Markdown
Member

@ShubhamRwt can we get a green build before starting for an early review please? Failure are around the CruiseControlReconciler so maybe something to fix in the logic before taking a look. Thanks :-)

Signed-off-by: ShubhamRwt <[email protected]>
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.32295% with 133 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.05%. Comparing base (8721743) to head (d2bb3e8).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
.../assembly/KafkaAutoRebalanceImbalanceDetector.java 53.91% 38 Missing and 15 partials ⚠️
...rator/assembly/KafkaAutoRebalancingReconciler.java 76.22% 25 Missing and 9 partials ⚠️
...r/resource/cruisecontrol/CruiseControlApiImpl.java 50.00% 19 Missing and 12 partials ⚠️
...imzi/operator/common/metrics/AnomalyMetricKey.java 0.00% 10 Missing ⚠️
...urce/cruisecontrol/CruiseControlStateResponse.java 50.00% 1 Missing and 1 partial ⚠️
.../strimzi/operator/cluster/model/CruiseControl.java 50.00% 0 Missing and 1 partial ⚠️
...uster/operator/assembly/KafkaAssemblyOperator.java 0.00% 1 Missing ⚠️
...strimzi/operator/common/metrics/MetricsHolder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13037      +/-   ##
============================================
- Coverage     80.35%   80.05%   -0.31%     
- Complexity     6532     6594      +62     
============================================
  Files           343      346       +3     
  Lines         22731    23024     +293     
  Branches       3085     3117      +32     
============================================
+ Hits          18265    18431     +166     
- Misses         3253     3340      +87     
- Partials       1213     1253      +40     
Files with missing lines Coverage Δ
...r/assembly/KafkaAssemblyOperatorMetricsHolder.java 100.00% <100.00%> (ø)
...rator/assembly/KafkaRebalanceAssemblyOperator.java 82.13% <ø> (ø)
...perator/assembly/KafkaRebalanceConfigMapUtils.java 83.33% <100.00%> (ø)
...ator/resource/cruisecontrol/GoalViolationInfo.java 100.00% <100.00%> (ø)
.../strimzi/operator/cluster/model/CruiseControl.java 91.92% <50.00%> (-0.89%) ⬇️
...uster/operator/assembly/KafkaAssemblyOperator.java 84.11% <0.00%> (-0.37%) ⬇️
...strimzi/operator/common/metrics/MetricsHolder.java 30.18% <0.00%> (-0.59%) ⬇️
...urce/cruisecontrol/CruiseControlStateResponse.java 71.42% <50.00%> (-28.58%) ⬇️
...imzi/operator/common/metrics/AnomalyMetricKey.java 0.00% <0.00%> (ø)
...r/resource/cruisecontrol/CruiseControlApiImpl.java 69.25% <50.00%> (-6.06%) ⬇️
... and 2 more

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShubhamRwt

Copy link
Copy Markdown
Contributor Author

@ppatierno All the tests seems to be passing now

@ppatierno ppatierno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ShubhamRwt I had a first quick pass but it needs more detailed review.

"been changed to match the specified default goals.");
// If the user has not explicitly configured anomaly detection goals, default them to the default anomaly detection goals
if (configuration.getConfigOption(CruiseControlConfigurationParameters.ANOMALY_DETECTION_CONFIG_KEY.toString()) == null) {
configuration.setConfigOption(CruiseControlConfigurationParameters.ANOMALY_DETECTION_CONFIG_KEY.toString(), CRUISE_CONTROL_DEFAULT_ANOMALY_DETECTION_GOALS);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why the previous logic changed so heavily. Weren't we checking that anomaly detection goals should be in the default goals as well otherwise CC fails on startup? I see this logic now removed.

private Map<String, ResourceRequirements> kafkaBrokerResources;
// needed to take information for the auto-rebalancing on scaling via Cruise Control
private Set<Integer> scalingDownBlockedNodes;
Set<Integer> scalingDownBlockedNodes;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not private anymore?

* @return Future with boolean indicating if rebalance should be triggered
*/
public CompletionStage<Boolean> shouldTriggerRebalance(Instant detectionDate) {
String configMapName = reconciliation.name() + KafkaAutoRebalancingReconciler.AUTO_REBALANCE_IMBALANCE_TRACKER_SUFFIX;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can avoid this additional variable.

"RackAwareGoal",
"MinTopicLeadersPerBrokerGoal",
"ReplicaCapacityGoal",
"DiskCapacityGoal"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we have these hard-coded here, should we have them somewhere in the Cruise Control api classes, IIRC we have some default constants there?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was referring to CruiseControlConfiguration.CRUISE_CONTROL_DEFAULT_ANOMALY_DETECTION_GOALS

.onComplete(v -> kafkaStatus.setAutoRebalance(kafkaAutoRebalanceStatus));
}

return Future.<Boolean>fromCompletionStage(imbalanceDetector.validateTemplateGoals())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this pattern of using fromCompletionStage motsly everywhere when you have calls coming from the detector. I think it means that all detector methods are badly declared returning a CompletionStage while they should return a CompletableFuture instead.

return kafkaRebalance.getStatus();
}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove this blank line, so this file won't change :-)

.withParameter(CruiseControlParameters.JSON, "true")
.withParameter(CruiseControlParameters.FETCH_COMPLETE, "true");
.withParameter(CruiseControlParameters.JSON, "true")
.withParameter(CruiseControlParameters.FETCH_COMPLETE, "true");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why this change? Even for the others below, why changing the indentation? I think something different in your IDE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I have some formatting filter in my IDE, I will fix these

} else if (ex.getCause() instanceof RuntimeException) {
return (RuntimeException) ex.getCause();
} else {
// Wrap checked exceptions (like IOException) in RuntimeException

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the comment says wrapping into RuntimeException but the code is wrapping into CruiseControlRetriableConnectionException.

*
* @return Future which completes when the check is done
*/
private Future<Void> maybeCheckForImbalance(ScalingNodes scalingNodes, KafkaStatus kafkaStatus) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get why the check for imbalance method needs the scalingNodes. I think this could be handled outside of it within the reconcile? I don't expect this method to call maybeRebalance internally by providing the scalingNodes. I don't have a solution right now to provide but maybe we could re-arrange the code to be more understandable.

"RackAwareGoal",
"MinTopicLeadersPerBrokerGoal",
"ReplicaCapacityGoal",
"DiskCapacityGoal"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was referring to CruiseControlConfiguration.CRUISE_CONTROL_DEFAULT_ANOMALY_DETECTION_GOALS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants