lucasbru commented on code in PR #24321:
URL: https://github.com/apache/kafka/pull/24321#discussion_r4643431192
##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -430,8 +430,8 @@ private void printStates(StreamsGroupDescription
description, boolean verbose) {
private void printOffsets(StreamsGroupDescription description, boolean
verbose) throws ExecutionException, InterruptedException {
Map<TopicPartition, OffsetsInfo> offsets = getOffsets(description);
- if (isGroupStateValid(description.groupState(),
description.members().size())) {
- maybePrintEmptyGroupState(description.groupId(),
description.groupState());
+ maybePrintEmptyGroupState(description.groupId(),
description.groupState());
+ if (isGroupStateValid(description.groupState(), offsets.size())) {
Review Comment:
This now counts offset rows instead of members. That matches
kafka-consumer-groups, but a group with members and no offset rows (e.g. stuck
in NOT_READY because a source topic is missing) used to print at least the
header and now prints nothing at all. Is that intended? If so, a stderr hint
for NOT_READY might help so the empty output is not confusing.
##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -462,6 +462,14 @@ Map<TopicPartition, OffsetsInfo>
getOffsets(StreamsGroupDescription description)
for (StreamsGroupMemberDescription memberDescription : members) {
allTp.addAll(getTopicPartitions(memberDescription.assignment().activeTasks(),
description));
}
+ // Also include partitions that have committed offsets but are not
assigned to any member,
+ // e.g., when the group is empty, so that their committed offsets
are still shown.
+ Map<TopicPartition, OffsetAndMetadata> committedOffsets =
getCommittedOffsets(description.groupId());
+ committedOffsets.forEach((tp, offsetAndMetadata) -> {
+ if (offsetAndMetadata != null) {
+ allTp.add(tp);
Review Comment:
With this, describing an empty group can now fail entirely if one of its
committed partitions has no leader: listOffsets retries until the API timeout
and `all().get()` throws, so none of the other partitions get shown. Before,
only assigned partitions were looked up, so empty groups did not hit this.
kafka-consumer-groups filters out leaderless partitions before calling
listOffsets (`filterNoneLeaderPartitions` in GroupOffsetsResetter). Could we do
the same here?
##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -1064,7 +1072,7 @@ private static void maybePrintEmptyGroupState(String
group, GroupState state) {
if (state == GroupState.DEAD) {
printError("Streams group '" + group + "' does not exist.",
Optional.empty());
} else if (state == GroupState.EMPTY) {
- printError("Streams group '" + group + "' has no active
members.", Optional.empty());
+ System.err.println("\nStreams group '" + group + "' has no
active members.");
Review Comment:
The javadoc of this method still says it prints an error message, but the
empty case is now a notice on stderr. Also worth mentioning in the description
that for `--describe --state` this message moves from stdout to stderr and
loses the `Error:` prefix, since that is the one mode where the output changes
for existing users.
##########
tools/src/test/java/org/apache/kafka/tools/streams/StreamsGroupCommandTest.java:
##########
@@ -342,6 +343,71 @@ public void testDescribeStreamsGroupsGetOffsets() throws
Exception {
service.close();
}
+ @Test
+ public void testDescribeEmptyStreamsGroupShowsCommittedOffsets() throws
Exception {
Review Comment:
Could we also cover a non-empty group? The change also adds
committed-but-unassigned partitions for running groups, and
testDescribeStreamsGroupsGetOffsets cannot catch that since it stubs
listOffsets with `anyMap()`. A Stable group with one assigned partition plus
one extra committed partition would pin it.
##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -462,6 +462,14 @@ Map<TopicPartition, OffsetsInfo>
getOffsets(StreamsGroupDescription description)
for (StreamsGroupMemberDescription memberDescription : members) {
allTp.addAll(getTopicPartitions(memberDescription.assignment().activeTasks(),
description));
}
+ // Also include partitions that have committed offsets but are not
assigned to any member,
+ // e.g., when the group is empty, so that their committed offsets
are still shown.
+ Map<TopicPartition, OffsetAndMetadata> committedOffsets =
getCommittedOffsets(description.groupId());
Review Comment:
Not new in this PR, but getCommittedOffsets describes the group again just
to get the source topics, although we already have `description` here. Now that
its result also decides which rows are shown, maybe pass the description in?
The groupId variant could stay for the reset path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]