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


##########
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:
   `isGroupStateValid` is now being called with `offsets.size()` instead of a 
member count, which changes the meaning of the method parameter and makes the 
control flow harder to reason about (and easier to misuse elsewhere). Consider 
introducing a dedicated predicate for printing offsets (e.g., 
`shouldPrintOffsets(state, offsets)`), or refactor `isGroupStateValid` to 
accept a clearly-named argument (or additional boolean) that distinguishes 
member-count validation from offset-row validation.



##########
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:
   By adding all committed-offset partitions into `allTp`, the subsequent 
`listOffsets(...).all().get()` calls can now fail the entire `--describe 
--offsets` output if any committed partition refers to a topic/partition that 
no longer exists (common with stale offsets). Consider handling `listOffsets` 
per-partition (or filtering to known topology/source topics) so unknown/deleted 
topic partitions don’t abort the whole describe; instead, print committed 
offset with blank/unknown log-end and lag (or skip with a clear indicator).



##########
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 (`\"\\n...\"`) introduces an extra blank line on stderr, 
which can make CLI output harder to parse and can be surprising in scripts. 
Prefer printing without the leading newline and manage spacing at the call site 
if needed.



##########
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:
   The test is mocking the concrete `KafkaAdminClient` class even though the 
variable is typed as `Admin`. Prefer mocking the `Admin` interface directly 
(e.g., `mock(Admin.class)`) to reduce coupling to a specific implementation and 
make the test more resilient to internal refactors.



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