dajac commented on code in PR #24071:
URL: https://github.com/apache/kafka/pull/24071#discussion_r4602076014


##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorShard.java:
##########
@@ -881,25 +881,37 @@ public CoordinatorResult<TxnOffsetCommitResponseData, 
CoordinatorRecord> commitT
     /**
      * Handles a ListGroups request.
      *
-     * @param statesFilter      The states of the groups we want to list.
-     *                          If empty, all groups are returned with their 
state.
-     *                          If invalid, no groups are returned.
-     * @param typesFilter       The types of the groups we want to list.
-     *                          If empty, all groups are returned with their 
type.
-     *                          If invalid, no groups are returned.
-     * @param committedOffset   A specified committed offset corresponding to 
this shard.
+     * @param statesFilter              The states of the groups we want to 
list.
+     *                                  If empty, all groups are returned with 
their state.
+     *                                  If invalid, no groups are returned.
+     * @param typesFilter               The types of the groups we want to 
list.
+     *                                  If empty, all groups are returned with 
their type.
+     *                                  If invalid, no groups are returned.
+     * @param requireCommittedOffsets   If true, only groups with at least one 
committed
+     *                                  offset are returned.
+     * @param committedOffset           A specified committed offset 
corresponding to this shard.
      * @return A list containing the ListGroupsResponseData.ListedGroup
      */
     public List<ListGroupsResponseData.ListedGroup> listGroups(
         List<String> statesFilter,
         List<String> typesFilter,
+        boolean requireCommittedOffsets,
         long committedOffset
     ) throws ApiException {
 
         Set<String> statesFilterSet = new HashSet<>(statesFilter);
         Set<String> typesFilterSet = new HashSet<>(typesFilter);
 
-        return groupMetadataManager.listGroups(statesFilterSet, 
typesFilterSet, committedOffset);
+        List<ListGroupsResponseData.ListedGroup> groups =
+            groupMetadataManager.listGroups(statesFilterSet, typesFilterSet, 
committedOffset);
+
+        if (!requireCommittedOffsets) {
+            return groups;
+        }
+
+        return groups.stream()
+            .filter(group -> 
offsetMetadataManager.hasCommittedOffsets(group.groupId(), committedOffset))
+            .toList();

Review Comment:
   The list of groups could be quite large so I would rather prefer if we could 
rather apply the filter where we apply the other filters too. We could either 
pass a predicate to `groupMetadataManager.listGroups` or pull the logic from 
`groupMetadataManager.listGroups` to this method so it can access both managers.



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