Skip to content

Commit d64ca1b

Browse files
committed
Consumer Group Lag: Don't emit metrics if state::dead
A group which has transitioned to dead does not need metrics; ensure metrics are only emmitted when state is not dead by checking the state in setup_metrics(), and set_state where all transitions pass through. This avoids making requests for partition offsets when not necessary. Signed-off-by: Ben Pope <[email protected]>
1 parent cd545a6 commit d64ca1b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/v/kafka/server/group.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ model::record_batch make_tx_fence_batch(
268268
return make_tx_batch(
269269
batch_type, group::fence_control_record_version, pid, std::move(cmd));
270270
}
271+
272+
bool need_lag_metrics(group_state s) { return s != group_state::dead; };
273+
271274
} // namespace
272275

273276
group_state group::set_state(group_state s) {
@@ -279,6 +282,9 @@ group_state group::set_state(group_state s) {
279282
s);
280283
vlog(_ctxlog.trace, "Changing state from {} to {}", _state, s);
281284
_state_timestamp = model::timestamp::now();
285+
if (need_lag_metrics(s) != need_lag_metrics(_state)) {
286+
setup_metrics();
287+
}
282288
return std::exchange(_state, s);
283289
}
284290

@@ -3630,7 +3636,7 @@ void group::setup_metrics() {
36303636
_probe.deregister_group_metrics();
36313637
}
36323638

3633-
if (_enable_group_metrics().consumer_lag) {
3639+
if (_enable_group_metrics().consumer_lag && need_lag_metrics(_state)) {
36343640
_probe.register_consumer_lag_metrics(_id);
36353641
} else {
36363642
_probe.deregister_consumer_lag_metrics();

0 commit comments

Comments
 (0)