Skip to content

MINOR: Invoke share group rebalance sensor. #20006

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

Merged
merged 5 commits into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
import static org.apache.kafka.coordinator.group.classic.ClassicGroupState.STABLE;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.CLASSIC_GROUP_COMPLETED_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.CONSUMER_GROUP_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.SHARE_GROUP_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.STREAMS_GROUP_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.modern.consumer.ConsumerGroupMember.hasAssignedPartitionsChanged;
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.convertToStreamsGroupTopologyRecord;
Expand Down Expand Up @@ -2610,6 +2611,7 @@ private CoordinatorResult<Map.Entry<ShareGroupHeartbeatResponseData, Optional<In
groupEpoch += 1;
records.add(newShareGroupEpochRecord(groupId, groupEpoch, groupMetadataHash));
log.info("[GroupId {}] Bumped group epoch to {} with metadata hash {}.", groupId, groupEpoch, groupMetadataHash);
metrics.record(SHARE_GROUP_REBALANCES_SENSOR_NAME);
}

group.setMetadataRefreshDeadline(currentTimeMs + METADATA_REFRESH_INTERVAL_MS, groupEpoch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,12 @@ public GroupCoordinatorMetrics(MetricsRegistry registry, Metrics metrics) {

Sensor shareGroupRebalanceSensor = metrics.sensor(SHARE_GROUP_REBALANCES_SENSOR_NAME);
shareGroupRebalanceSensor.add(new Meter(
metrics.metricName("rebalance-rate",
metrics.metricName("share-group-rebalance-rate",
METRICS_GROUP,
"The rate of share group rebalances",
SHARE_GROUP_PROTOCOL_TAG, Group.GroupType.SHARE.toString()),
metrics.metricName("rebalance-count",
"The rate of share group rebalances"),
metrics.metricName("share-group-rebalance-count",
METRICS_GROUP,
"The total number of share group rebalances",
SHARE_GROUP_PROTOCOL_TAG, Group.GroupType.SHARE.toString())));
"The total number of share group rebalances")));

Sensor streamsGroupRebalanceSensor = metrics.sensor(STREAMS_GROUP_REBALANCES_SENSOR_NAME);
streamsGroupRebalanceSensor.add(new Meter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
import static org.apache.kafka.coordinator.group.classic.ClassicGroupState.STABLE;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.CLASSIC_GROUP_COMPLETED_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.CONSUMER_GROUP_REBALANCES_SENSOR_NAME;
import static org.apache.kafka.coordinator.group.metrics.GroupCoordinatorMetrics.SHARE_GROUP_REBALANCES_SENSOR_NAME;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -19699,6 +19700,7 @@ public void testShareGroupHeartbeatOnConsumerGroup() {
.setMemberId(Uuid.randomUuid().toString())
.setMemberEpoch(1)
.setSubscribedTopicNames(List.of("foo", "bar"))));
verify(context.metrics, times(0)).record(SHARE_GROUP_REBALANCES_SENSOR_NAME);
}

@Test
Expand Down Expand Up @@ -19785,6 +19787,7 @@ public void testShareGroupHeartbeatOnStreamsGroup() {
.setGroupId(groupId)
.setMemberEpoch(0)
.setSubscribedTopicNames(List.of("foo", "bar"))));
verify(context.metrics, times(0)).record(SHARE_GROUP_REBALANCES_SENSOR_NAME);
}

@Test
Expand Down Expand Up @@ -22306,6 +22309,7 @@ public void testShareGroupHeartbeatInitializeOnPartitionUpdate() {
);

assertEquals(Map.of(t1Uuid, Set.of(0, 1), t2Uuid, Set.of(0, 1)), context.groupMetadataManager.initializedShareGroupPartitions(groupId));
verify(context.metrics, times(2)).record(SHARE_GROUP_REBALANCES_SENSOR_NAME);
}

@Test
Expand Down Expand Up @@ -22415,6 +22419,7 @@ public void testShareGroupHeartbeatPersisterRequestWithInitializing() {
2,
true
);
verify(context.metrics, times(2)).record(SHARE_GROUP_REBALANCES_SENSOR_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,8 @@ public void testMetricNames() {
"group-count",
GroupCoordinatorMetrics.METRICS_GROUP,
Map.of("protocol", Group.GroupType.SHARE.toString())),
metrics.metricName(
"rebalance-rate",
GroupCoordinatorMetrics.METRICS_GROUP,
Map.of("protocol", Group.GroupType.SHARE.toString())),
metrics.metricName(
"rebalance-count",
GroupCoordinatorMetrics.METRICS_GROUP,
Map.of("protocol", Group.GroupType.SHARE.toString())),
metrics.metricName("share-group-rebalance-rate", GroupCoordinatorMetrics.METRICS_GROUP),
metrics.metricName("share-group-rebalance-count", GroupCoordinatorMetrics.METRICS_GROUP),
metrics.metricName(
"share-group-count",
GroupCoordinatorMetrics.METRICS_GROUP,
Expand Down Expand Up @@ -304,16 +298,14 @@ public void testGlobalSensors() {

shard.record(SHARE_GROUP_REBALANCES_SENSOR_NAME, 50);
assertMetricValue(metrics, metrics.metricName(
"rebalance-rate",
"share-group-rebalance-rate",
GroupCoordinatorMetrics.METRICS_GROUP,
"The rate of share group rebalances",
"protocol", "share"
"The rate of share group rebalances"
), 5.0 / 3.0);
assertMetricValue(metrics, metrics.metricName(
"rebalance-count",
"share-group-rebalance-count",
GroupCoordinatorMetrics.METRICS_GROUP,
"The total number of share group rebalances",
"protocol", "share"
"The total number of share group rebalances"
), 50);

shard.record(STREAMS_GROUP_REBALANCES_SENSOR_NAME, 50);
Expand Down