Repository navigation
[coordinator] Add rebalance progress and outcome metrics - #4373
heyallencao wants to merge 1 commit into
Conversation
morazow
left a comment
There was a problem hiding this comment.
Thanks @heyallencao 🚀
Added minor nits
Thanks for the review, @morazow! All three comments are addressed. The 18 targeted rebalance tests and style checks pass. |
|
Perfect! Another suggestion: Could we give the rebalance metrics the same lifetime as the coordinator process? We could introduce a Then each This would avoid resetting counters and unregistering/re-registering metrics on leadership changes, and remove the need for a separate RebalanceMetricGroup:
Rough structure as below: public class RebalanceMetrics {
private final Counter rebalancesCompleted = new ThreadSafeSimpleCounter();
// ...
/** The manager of the current leader term, or null while this server is not the leader. */
private volatile @Nullable RebalanceManager current;
public RebalanceMetrics(MetricGroup metricGroup) {
metricGroup.counter(MetricNames.REBALANCES_COMPLETED_TOTAL, rebalancesCompleted);
// ...
metricGroup.gauge(
MetricNames.REBALANCE_BUCKETS_PENDING,
() -> readCurrent(RebalanceManager::pendingBucketCount));
// ...
}
private long readCurrent(ToLongFunction<RebalanceManager> read) {
RebalanceManager manager = current;
return manager == null ? 0L : read.applyAsLong(manager);
}
void bind(RebalanceManager manager) {
current = manager;
}
void unbind(RebalanceManager manager) {
// a late close from an ended term must not detach the manager that replaced it
if (current == manager) {
current = null;
}
}
}RebalanceManager then takes What do you think about this? The initial ticket wanted per leader term, but that would be misleading: counters are not monotonic and readers could not tell a leader reset from a real drop. |
morazow
left a comment
There was a problem hiding this comment.
Thanks @heyallencao 🚀
I have added couple improvements 🤝 Then should be good to go!
|
Thanks @morazow! I have addressed all six suggestions:
I also did another self-review. All 19 |
|
Thanks @heyallencao! Looks good 🚀 |
affo
left a comment
There was a problem hiding this comment.
Hello! Amazing contribution! Thank you!
I have a question, with HA enabled, how does a standby keeps up with the old state of metrics?
For example, if the count is 5, a new standby would start from 0 right?
Is this a wanted semantic? So, one see that coordinator ID is different and no problem?
Or we expect this metric to stay consistent through time and we should store that in ZK?
If so, I think the state can be gathered already from ZK as per #3985
Thanks for raising this. These counters are scoped to each coordinator process. A standby reports its own accumulated counts, which are zero if it has never processed a rebalance. When it becomes leader, it does not inherit the previous leader's counts. A process restart also resets its counters. This is the intended per-process semantic, so these metrics do not provide a cluster-wide cumulative total that remains continuous across coordinators. The existing persisted rebalance state is not sufficient to reconstruct such a total accurately. If a cluster-wide cumulative total is needed, I think it should be defined as a separate metric contract, with its persistence semantics made explicit. |
affo
left a comment
There was a problem hiding this comment.
@heyallencao what you say makes sense, metrics are indeed scoped on a per-pod basis, so there is no chance to mis-interpret them 🤝
thanks |
|
Hi @morazow @affo, thanks again for reviewing and approving this PR. I've merged current main into the branch in 75ca530, resolved the coordinator test-helper conflict, and updated the constructor-failure regression test to retain the remote storage configuration now required by main. Local validation with JDK 17 and Maven 3.9.14:
Could you please take another look and help move this toward merge? The new GitHub Actions runs also conclude |
|
Thanks @heyallencao, this looks good to me. LGTM 🚀 One small optional suggestion, since metric names become hard to change once dashboards depend on them: all the other new metrics start with "rebalance", but the in-flight bucket duration doesn't. Something like Happy to merge as is if you'd rather keep it. |
|
Thanks @polyzos! Agreed — I've renamed the metric to Local validation passed: all 19 The previous revision's core Java CI, connectors, documentation, and license checks passed. The Python 3.9 integration job failed before running tests because Thanks again for the review! |
|
@morazow @affo The latest update merges the current |
|
@heyallencao thanks for the great contribution, I am going to raise attention to committers to land this 🤝 |
Thanks! |
|
Thanks @heyallencao! The changes look good to me. One request before merging: could you remove the new Mockito usage in RebalanceManagerTest? The project prefers real objects or small Testing* implementations. The test class already builds a real event processor you can reuse, and a minimal recording registry would cover the register/unregister checks. Optional nit: the new metrics table in the docs leaves out the Scope/Infix columns that the other tables have. Thanks! |
Thanks for the review. Both comments are addressed in commit 47ef219: Removed Mockito from RebalanceManagerTest — metric registration is now verified with a minimal hand-written RecordingMetricRegistry, and the remaining mock(CoordinatorEventProcessor) calls are replaced with real processors built via the existing buildCoordinatorEventProcessor() helper. |
|
@heyallencao LGTM 👍 Please rebase so we can merge. |
47ef219 to
ed98c3c
Compare
@polyzos Thanks for the review! Rebased onto the latest main — conflicts Verified locally: RebalanceManagerTest 19/19 passed, spotless + checkstyle |
Expose coordinator process metrics for concurrent bucket migrations, timeout reconciliation, and persisted rebalance outcomes. Generated-by: OpenAI Codex
c9d77fb to
095f575
Compare
|
Hi @polyzos, @morazow, and @affo, thanks again for the review! It’s been a while since the last update, and changes on main brought back a few conflicts. I’ve resolved them and verified the changes locally. The earlier CI runs expired while waiting for approval. If you have time soon, could you take another look and help approve the new CI runs? It’d be great to wrap this up while the branch is up to date. Thanks! |
Purpose
Closes #4055.
Expose coordinator-level metrics for monitoring rebalance progress, duration, and outcomes without polling the Admin API.
Brief change log
RebalanceMetrics, owned byCoordinatorMetricGroup. Retain the existing coordinator scope without additional table or bucket labels.RebalanceManagerinstartup()and unbind it on close. Counters survive leadership changes, while gauges return zero on standby.Outcome semantics
A round with any failed or timed-out buckets increments the failure counter. The existing Admin API's
COMPLETEDstatus means that execution has finished, not necessarily that every bucket succeeded; this PR does not change that API behavior.An empty plan counts as a successful round. The cancellation counter increments only when a running rebalance is canceled; repeated cancellation does not increment it again.
Leadership changes and recovery
Counters accumulate across all leader terms served by the same coordinator process and reset only when that process restarts. They remain unchanged on standby and are not transferred between coordinator processes.
Bucket-outcome gauges include only results observed in the current leader term. They remain available after completion or cancellation within that term and are cleared when the next round is registered. All gauges return zero on standby. Since per-bucket outcomes are not persisted, recovering an already finished round leaves the bucket-outcome gauges at zero and does not increment round counters. This avoids reporting historical failures as successes. These zeros mean that no outcomes were observed in the current term, not that the historical round had no failures.
Tests
RebalanceManagerTesttests and bothRebalanceManagerITCaseintegration tests, plus coordinator lifecycle/election and metric-group tests.git diff --checkpassed.API and Format
No changes to public client APIs, RPC messages, persisted rebalance task format, or rebalance execution semantics.
This adds monitoring metrics. Their process-scoped lifetime and recovery behavior are documented.
Documentation
Add a Rebalance Metrics section to the monitoring documentation, describing metric names, types, meanings, and behavior during leadership changes and task recovery.