AndrewJSchofield commented on code in PR #19508: URL: https://github.com/apache/kafka/pull/19508#discussion_r2076227818
########## clients/src/main/java/org/apache/kafka/common/requests/ListGroupsRequest.java: ########## @@ -50,8 +53,19 @@ public ListGroupsRequest build(short version) { "v" + version + ", but we need v4 or newer to request groups by states."); } if (!data.typesFilter().isEmpty() && version < 5) { - throw new UnsupportedVersionException("The broker only supports ListGroups " + - "v" + version + ", but we need v5 or newer to request groups by type."); + // Types filter is supported by brokers with version 4.0.0 or later. Older brokers only support + // classic groups, so listing consumer groups on an older broker does not need to use a types filter. + // If the types filter is only for consumer and classic, or just classic groups, it can be safely omitted. + // This allows a modern admin client to list consumer groups on older brokers in a straightforward way. + HashSet<String> typesCopy = new HashSet<>(data.typesFilter()); + boolean containedClassic = typesCopy.remove(GroupType.CLASSIC.toString()); + boolean containedConsumer = typesCopy.remove(GroupType.CONSUMER.toString()); + if (!typesCopy.isEmpty() || (!containedClassic && containedConsumer)) { Review Comment: I do know that `ListGroupsRequest.TypesFilter` and `ListGroupsResponse.GroupType` were introduced together and, as you correctly pointed out, they were introduced in 3.8. My point is that if you connect to a broker which is too old to support the TypesFilter and GroupType, you cannot control which types of groups it returns, nor distinguish between different types of group. It's classic groups only. For a pre-3.8 broker: * `ListGroupsOptions.withTypes(List.of(GroupType.CLASSIC, GroupType.CONSUMER))` will return classic groups. This is the same as `ListGroupsOptions.forConsumerGroups())`. The lack of TypesFilter is no problem. * `ListGroupsOptions.withTypes(List.of(GroupType.CLASSIC))` will return classic groups, because it doesn't know any other types. The lack of TypesFilter is no problem. * `ListGroupsOptions.withType(List.of(GroupType.CONSUMER))` will throw `UnsupportedVersionException`. The user has explicitly requested only `GroupType.CONSUMER` and that cannot be expressed without a TypesFilter. There is a tiny outlier for 3.7 brokers with KIP-848 EA enabled. Even those didn't support TypesFilter or GroupType. All groups would have appeared to be classic groups. So, I think the above 3 cases are as good as can be expected. Modern consumer groups would be reported as classic groups, because the RPC response was not able to distinguish. -- 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