m1a2st commented on code in PR #20064: URL: https://github.com/apache/kafka/pull/20064#discussion_r2173644698
########## tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java: ########## @@ -631,7 +635,34 @@ else if (logEndOffsetResult.getValue() instanceof OffsetsUtils.Ignore) return null; throw new IllegalStateException("Unknown LogOffset subclass: " + logEndOffsetResult.getValue()); - }).collect(Collectors.toList()); + }).toList(); + + // prepare data for partitions without leaders + List<PartitionAssignmentState> noneLeaderAssignments = nonLeaderTopicPartitions.stream() + .map(tp -> getDescribePartitionResult.apply(tp, Optional.empty())).toList(); + + // concat the data and then sort them + return Stream.concat(existLeaderAssignments.stream(), noneLeaderAssignments.stream()) + .sorted(Comparator.<PartitionAssignmentState, String>comparing( + state -> state.topic.orElse(""), String::compareTo) + .thenComparingInt(state -> state.partition.orElse(-1))) + .collect(Collectors.toList()); + } + + private Set<TopicPartition> filterNoneLeaderPartitions(List<TopicPartition> topicPartitions) { + // collect all topics + Set<String> topics = topicPartitions.stream().map(TopicPartition::topic).collect(Collectors.toSet()); Review Comment: I don't think we need to convert it to a set here, since AdminClient.describeTopics doesn’t handle duplicate topic names anyway https://github.com/apache/kafka/blob/a5a54dc32b41a791646feee579207323c02ffa5b/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L2320 ########## tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java: ########## @@ -1053,6 +1054,63 @@ public void testDescribeNonOffsetCommitGroup(ClusterInstance clusterInstance) th } } + /** + * The config `OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG` needs to be set to a value greater than 1 to ensure the + * normal invocation of APIs such as `FIND_COORDINATOR` when a broker has shutdown + */ + @ClusterTest(brokers = 3, serverProperties = {@ClusterConfigProperty(key = OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")}) + public void testDescribeConsumerGroupWithoutLeaders(ClusterInstance clusterInstance) throws Exception { + int brokerNum = 3; + this.clusterInstance = clusterInstance; + + // define topic and group, then send 5 records to each partition + String topic = TOPIC_PREFIX + UUID.randomUUID(); + String group = GROUP_PREFIX + UUID.randomUUID(); + clusterInstance.createTopic(topic, brokerNum, (short) 1); + for (int i = 0; i < brokerNum; i++) { + sendRecords(topic, i, 5); + } + + // append the command + List<String> cgcArgs = new ArrayList<>(List.of("--bootstrap-server", clusterInstance.bootstrapServers(), "--describe", "--group", group, "--all-topics")); Review Comment: ```suggestion List<String> cgcArgs = List.of("--bootstrap-server", clusterInstance.bootstrapServers(), "--describe", "--group", group, "--all-topics"); ``` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org