From 9e7e9a8ff6fab103defec6acbb06a2588977f2e4 Mon Sep 17 00:00:00 2001 From: Chirag Wadhwa Date: Thu, 1 May 2025 20:11:41 +0530 Subject: [PATCH] MINOR: printing share group describe result in sorted order (#19599) This PR sorts the information that is printed when kafka-share-groups.sh --describe is used Reviewers: Andrew Schofield --- .../tools/consumer/group/ShareGroupCommand.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java b/tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java index cfe3fee5812..7d53514a250 100644 --- a/tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java +++ b/tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java @@ -44,6 +44,7 @@ import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -426,7 +427,12 @@ public class ShareGroupCommand { private void printOffsets(TreeMap>> offsets, boolean verbose) { offsets.forEach((groupId, tuple) -> { - Collection offsetsInfo = tuple.getValue(); + Collection offsetsInfo = tuple.getValue().stream() + .sorted(Comparator + .comparing((SharePartitionOffsetInformation info) -> info.topic) + .thenComparingInt(info -> info.partition)) + .toList(); + String fmt = printOffsetFormat(groupId, offsetsInfo, verbose); if (verbose) { @@ -496,7 +502,10 @@ public class ShareGroupCommand { descriptions.forEach((groupId, description) -> { int groupLen = Math.max(15, groupId.length()); int maxConsumerIdLen = 15, maxHostLen = 15, maxClientIdLen = 15; - Collection members = description.members(); + Collection members = description.members() + .stream() + .sorted(Comparator.comparing(ShareMemberDescription::consumerId)) + .toList(); if (maybePrintEmptyGroupState(groupId, description.groupState(), description.members().size())) { for (ShareMemberDescription member : members) { maxConsumerIdLen = Math.max(maxConsumerIdLen, member.consumerId().length());