aliehsaeedii commented on code in PR #24321:
URL: https://github.com/apache/kafka/pull/24321#discussion_r4644447969


##########
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:
   `getCommittedOffsets` only keeps offsets for the topology's source and 
repartition topics, so stale offsets for other topics never reach 
`listOffsets`. Deleted or leaderless partitions are handled in #24193 
(KAFKA-21457), which filters them out before `listOffsets`.



##########
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:
   Agreed, empty groups can hit this now. #24193 (KAFKA-21457) adds exactly 
that: it runs `filterNoneLeaderPartitions` on `allTp` in `getOffsets` and 
prints `-` for those partitions. To avoid two PRs changing the same lines, I'd 
leave it to that PR and rebase whichever lands second.



##########
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:
   Done: `getOffsets` now passes the description to a new 
`getCommittedOffsets(StreamsGroupDescription)` overload, so the group is no 
longer described twice. The `groupId` variant stays for the reset and delete 
paths and delegates to it.



##########
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 leading newline matches `kafka-consumer-groups`, which prints the same 
notice to stderr as `"\nConsumer group '...' has no active members."`. Keeping 
the two tools consistent.



##########
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 {
+        String groupId = "group1";
+        TopicPartition tp = new TopicPartition("topic1", 0);
+        // Use a dedicated admin mock so the listOffsets verification below 
only sees this test's calls.
+        Admin adminClient = mock(KafkaAdminClient.class);

Review Comment:
   Kept `mock(KafkaAdminClient.class)` to match the rest of this test class, 
where `ADMIN_CLIENT` and the other tests mock it the same way.



##########
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:
   Added `testDescribeStableStreamsGroupIncludesCommittedUnassignedPartitions`: 
a Stable group whose only member owns `topic1-0`, plus a committed offset for 
`topic1-1`. It checks that `listOffsets` is asked for both partitions and that 
both rows are returned, and it fails if the committed partitions are not added.



##########
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:
   Fixed the javadoc. I'll also mention in the PR description that for 
`--describe --state` the notice moves from stdout to stderr and loses the 
`Error:` prefix.



##########
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:
   The parameter of `isGroupStateValid` is `numRows` and its javadoc says "the 
number of rows associated with the group", so offset rows is what it is meant 
to get; passing the member count was the odd one. `kafka-consumer-groups` also 
decides on the number of rows.



##########
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:
   Agreed. The rebalancing warning and a `NotReady` notice are part of 
KAFKA-21592, so I'll do them in that follow-up.



-- 
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]

Reply via email to