-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9130: KIP-518 Allow listing consumer groups per state #8238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
88e7a0c
143514c
badbc1a
b243a61
145b689
a0247b0
4bed4d3
d6102e8
5854e56
1f032e7
499b15b
56f839a
5e18e5c
acb64f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,22 +17,30 @@ | |
|
|
||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| import org.apache.kafka.common.ConsumerGroupState; | ||
|
|
||
| /** | ||
| * A listing of a consumer group in the cluster. | ||
| */ | ||
| public class ConsumerGroupListing { | ||
| private final String groupId; | ||
| private final boolean isSimpleConsumerGroup; | ||
| private final Optional<ConsumerGroupState> state; | ||
|
|
||
| /** | ||
| * Create an instance with the specified parameters. | ||
| * | ||
| * @param groupId Group Id | ||
| * @param isSimpleConsumerGroup If consumer group is simple or not. | ||
| * @param state The state of the consumer group | ||
| */ | ||
| public ConsumerGroupListing(String groupId, boolean isSimpleConsumerGroup) { | ||
| public ConsumerGroupListing(String groupId, boolean isSimpleConsumerGroup, Optional<ConsumerGroupState> state) { | ||
| this.groupId = groupId; | ||
| this.isSimpleConsumerGroup = isSimpleConsumerGroup; | ||
| this.state = state; | ||
|
mimaison marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: usually we would write this is |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -49,11 +57,49 @@ public boolean isSimpleConsumerGroup() { | |
| return isSimpleConsumerGroup; | ||
| } | ||
|
|
||
| /** | ||
| * Consumer Group state | ||
| */ | ||
| public Optional<ConsumerGroupState> state() { | ||
| return state; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "(" + | ||
| "groupId='" + groupId + '\'' + | ||
| ", isSimpleConsumerGroup=" + isSimpleConsumerGroup + | ||
| ", state=" + state + | ||
| ')'; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(groupId, isSimpleConsumerGroup, state); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) | ||
| return true; | ||
| if (obj == null) | ||
| return false; | ||
| if (getClass() != obj.getClass()) | ||
| return false; | ||
| ConsumerGroupListing other = (ConsumerGroupListing) obj; | ||
| if (groupId == null) { | ||
| if (other.groupId != null) | ||
| return false; | ||
| } else if (!groupId.equals(other.groupId)) | ||
| return false; | ||
| if (isSimpleConsumerGroup != other.isSimpleConsumerGroup) | ||
| return false; | ||
| if (state == null) { | ||
| if (other.state != null) | ||
| return false; | ||
| } else if (!state.equals(other.state)) | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,11 @@ | |
|
|
||
| package org.apache.kafka.clients.admin; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.kafka.common.ConsumerGroupState; | ||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
|
||
| /** | ||
|
|
@@ -26,4 +31,30 @@ | |
| */ | ||
| @InterfaceStability.Evolving | ||
| public class ListConsumerGroupsOptions extends AbstractOptions<ListConsumerGroupsOptions> { | ||
|
|
||
| private Set<ConsumerGroupState> states = Collections.emptySet(); | ||
|
|
||
| /** | ||
| * Only groups in these states will be returned by listConsumerGroups() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth adding a comment about broker compatibility with this API.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you address this comment? |
||
| * If not set, all groups are returned with their states | ||
| */ | ||
| public ListConsumerGroupsOptions inStates(Set<ConsumerGroupState> states) { | ||
| this.states = (states == null) ? Collections.emptySet() : new HashSet<>(states); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * All groups with their states will be returned by listConsumerGroups() | ||
| */ | ||
| public ListConsumerGroupsOptions inAnyState() { | ||
|
mimaison marked this conversation as resolved.
Outdated
|
||
| this.states = Collections.emptySet(); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the list of States that are requested or empty if no states have been specified | ||
| */ | ||
| public Set<ConsumerGroupState> states() { | ||
| return states; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,9 @@ | |
| // Starting in version 2, on quota violation, brokers send out responses before throttling. | ||
| // | ||
| // Version 3 is the first flexible version. | ||
| "validVersions": "0-3", | ||
| // | ||
| // Version 4 adds the GroupState field (KIP-518). | ||
| "validVersions": "0-4", | ||
| "flexibleVersions": "3+", | ||
| "fields": [ | ||
| { "name": "ThrottleTimeMs", "type": "int32", "versions": "1+", "ignorable": true, | ||
|
|
@@ -34,7 +36,9 @@ | |
| { "name": "GroupId", "type": "string", "versions": "0+", "entityType": "groupId", | ||
| "about": "The group ID." }, | ||
| { "name": "ProtocolType", "type": "string", "versions": "0+", | ||
| "about": "The group protocol type." } | ||
| "about": "The group protocol type." }, | ||
| { "name": "GroupState", "type": "string", "versions": "4+", "nullableVersions": "0+", "ignorable": true, "default": "null", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional to use nullable versions 0+? I'm surprised the generator doesn't fail. |
||
| "about": "The group state name." } | ||
| ]} | ||
| ] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.