You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "AndrewJSchofield (via GitHub)" <gi...@apache.org> on 2024/11/06 17:29:43 UTC
[PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
AndrewJSchofield opened a new pull request, #17706:
URL: https://github.com/apache/kafka/pull/17706
This PR introduces the DescribeGroups v6 API as part of KIP-1043. This adds an error message for the described groups so that it is possible to get some context on the error. It also changes the behaviour for when the group ID cannot be found but returning error code GROUP_ID_NOT_FOUND rather than NONE.
The PR also contains the exploitation of the error message by the admin tools.
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #17706:
URL: https://github.com/apache/kafka/pull/17706#issuecomment-2463063889
> Thanks for the patch. I have two high level thoughts:
>
> * Should we update DescribeGroupsRequestTest to verify this change?
> * Should we also update the old group coordinator in order to be consistent? In the current state, if someone still uses it, v6 would still return the dead group instead of the error code. We may ignore it but it would make the API inconsistent. What do you think?
I think that's sensible. I will make those changes tomorrow.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #17706:
URL: https://github.com/apache/kafka/pull/17706#discussion_r1869766437
##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/ResetConsumerGroupOffsetTest.java:
##########
@@ -136,10 +136,6 @@ public void testResetOffsetsNotExistingGroup(ClusterInstance cluster) throws Exc
String[] args = buildArgsForGroup(cluster, group, "--all-topics", "--to-current", "--execute");
try (ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) {
- // Make sure we got a coordinator
- TestUtils.waitForCondition(
- () -> "localhost".equals(service.collectGroupState(group).coordinator.host()),
- "Can't find a coordinator");
Review Comment:
That's because `collectGroupState` fails for a non-existent group now. The `resetOffsets` method handles a non-existent group directly.
I'm going to do a little more work in this area since I'm not totally happy with the output from `kafka-consumer-groups.sh` when the group ID is a share group. It works but it's a bit scruffy.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac merged PR #17706:
URL: https://github.com/apache/kafka/pull/17706
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #17706:
URL: https://github.com/apache/kafka/pull/17706#issuecomment-2517574019
Test failure looks like a timeout for ShareConsumerTest waiting to shut down the broker.https://issues.apache.org/jira/browse/KAFKA-18154
There are 3 pending PRs which could be relevant here due to incorrect locking in the SharePartitionManager.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #17706:
URL: https://github.com/apache/kafka/pull/17706#issuecomment-2500865677
Test failure was due to a test which has been consistently failing and is being marked as flaky in https://github.com/apache/kafka/pull/17945.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on PR #17706:
URL: https://github.com/apache/kafka/pull/17706#issuecomment-2463037847
Thanks for the patch. I have two high level thoughts:
* Should we update DescribeGroupsRequestTest to verify this change?
* Should we also update the old group coordinator in order to be consistent? In the current state, if someone still uses it, v6 would still return the dead group instead of the error code. We may ignore it but it would make the API inconsistent. What do you think?
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #17706:
URL: https://github.com/apache/kafka/pull/17706#discussion_r1869581460
##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -1936,18 +1936,25 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
val expectedOperations = AclEntry.supportedOperations(ResourceType.GROUP)
assertEquals(expectedOperations, testGroupDescription.authorizedOperations())
- // Test that the fake group is listed as dead.
+ // Test that the fake group throws GroupIdNotFoundException
assertTrue(describeWithFakeGroupResult.describedGroups().containsKey(fakeGroupId))
- val fakeGroupDescription = describeWithFakeGroupResult.describedGroups().get(fakeGroupId).get()
-
- assertEquals(fakeGroupId, fakeGroupDescription.groupId())
- assertEquals(0, fakeGroupDescription.members().size())
- assertEquals("", fakeGroupDescription.partitionAssignor())
- assertEquals(GroupState.DEAD, fakeGroupDescription.groupState())
- assertEquals(expectedOperations, fakeGroupDescription.authorizedOperations())
+ try {
Review Comment:
nit: You may be able to use `assertFutureThrows` helper.
##########
clients/src/main/java/org/apache/kafka/clients/admin/internals/DescribeConsumerGroupsHandler.java:
##########
@@ -354,11 +356,18 @@ private void handleError(
case GROUP_ID_NOT_FOUND:
if (isConsumerGroupResponse) {
log.debug("`{}` request for group id {} failed because the group is not " +
- "a new consumer group. Will retry with `DescribeGroups` API.", apiName, groupId.idValue);
+ "a new consumer group. Will retry with `DescribeGroups` API. {}",
Review Comment:
nit: Do you think that printing the error message is necessary here and below?
##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java:
##########
@@ -535,34 +536,47 @@ Map<String, Map<TopicPartition, OffsetAndMetadata>> resetOffsets() {
switch (state) {
case "Empty":
case "Dead":
- Collection<TopicPartition> partitionsToReset = getPartitionsToReset(groupId);
- Map<TopicPartition, OffsetAndMetadata> preparedOffsets = prepareOffsetsToReset(groupId, partitionsToReset);
-
- // Dry-run is the default behavior if --execute is not specified
- boolean dryRun = opts.options.has(opts.dryRunOpt) || !opts.options.has(opts.executeOpt);
- if (!dryRun) {
- adminClient.alterConsumerGroupOffsets(
- groupId,
- preparedOffsets,
- withTimeoutMs(new AlterConsumerGroupOffsetsOptions())
- ).all().get();
- }
-
- result.put(groupId, preparedOffsets);
-
+ result.put(groupId, resetOffsetsForInactiveGroup(groupId));
break;
default:
printError("Assignments can only be reset if the group '" + groupId + "' is inactive, but the current state is " + state + ".", Optional.empty());
result.put(groupId, Collections.emptyMap());
}
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
+ } catch (InterruptedException ie) {
+ throw new RuntimeException(ie);
+ } catch (ExecutionException ee) {
+ if (ee.getCause() instanceof GroupIdNotFoundException) {
+ result.put(groupId, resetOffsetsForInactiveGroup(groupId));
+ } else {
+ throw new RuntimeException(ee);
+ }
}
});
return result;
}
+ Map<TopicPartition, OffsetAndMetadata> resetOffsetsForInactiveGroup(String groupId) {
Review Comment:
nit: private?
##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/ResetConsumerGroupOffsetTest.java:
##########
@@ -136,10 +136,6 @@ public void testResetOffsetsNotExistingGroup(ClusterInstance cluster) throws Exc
String[] args = buildArgsForGroup(cluster, group, "--all-topics", "--to-current", "--execute");
try (ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) {
- // Make sure we got a coordinator
- TestUtils.waitForCondition(
- () -> "localhost".equals(service.collectGroupState(group).coordinator.host()),
- "Can't find a coordinator");
Review Comment:
Why did you remove this one?
##########
core/src/test/scala/unit/kafka/coordinator/group/GroupCoordinatorTest.scala:
##########
@@ -3405,15 +3407,21 @@ class GroupCoordinatorTest {
@Test
def testDescribeGroupWrongCoordinator(): Unit = {
- val (error, _) = groupCoordinator.handleDescribeGroup(otherGroupId)
+ val (error, _, _) = groupCoordinator.handleDescribeGroup(otherGroupId, ApiKeys.DESCRIBE_GROUPS.latestVersion)
assertEquals(Errors.NOT_COORDINATOR, error)
}
@Test
def testDescribeGroupInactiveGroup(): Unit = {
- val (error, summary) = groupCoordinator.handleDescribeGroup(groupId)
+ val (error, errorMessage, summary) = groupCoordinator.handleDescribeGroup(groupId, 5)
assertEquals(Errors.NONE, error)
+ assertTrue(errorMessage.isEmpty)
assertEquals(GroupCoordinator.DeadGroup, summary)
+
+ val (errorV6, errorMessageV6, summaryV6) = groupCoordinator.handleDescribeGroup(groupId, 6)
+ assertEquals(Errors.GROUP_ID_NOT_FOUND, errorV6)
+ assertTrue(errorMessageV6.isDefined)
Review Comment:
nit: Should we verify the message too?
##########
core/src/test/scala/unit/kafka/server/DescribeGroupsRequestTest.scala:
##########
@@ -113,5 +113,48 @@ class DescribeGroupsRequestTest(cluster: ClusterInstance) extends GroupCoordinat
)
)
}
+
+ for (version <- 6 to ApiKeys.DESCRIBE_GROUPS.latestVersion(isUnstableApiEnabled)) {
+ assertEquals(
+ List(
+ new DescribedGroup()
+ .setGroupId("grp-1")
+ .setGroupState(ClassicGroupState.STABLE.toString)
+ .setProtocolType("consumer")
+ .setProtocolData("consumer-range")
+ .setMembers(List(
+ new DescribedGroupMember()
+ .setMemberId(memberId1)
+ .setGroupInstanceId(null)
+ .setClientId("client-id")
+ .setClientHost("/127.0.0.1")
+ .setMemberMetadata(Array(1, 2, 3))
+ .setMemberAssignment(Array(4, 5, 6))
+ ).asJava),
+ new DescribedGroup()
+ .setGroupId("grp-2")
+ .setGroupState(ClassicGroupState.COMPLETING_REBALANCE.toString)
+ .setProtocolType("consumer")
+ .setMembers(List(
+ new DescribedGroupMember()
+ .setMemberId(memberId2)
+ .setGroupInstanceId(null)
+ .setClientId("client-id")
+ .setClientHost("/127.0.0.1")
+ .setMemberMetadata(Array.empty)
+ .setMemberAssignment(Array.empty)
+ ).asJava),
+ new DescribedGroup()
+ .setGroupId("grp-unknown")
+ .setGroupState(ClassicGroupState.DEAD.toString) // Return DEAD group when the group does not exist.
+ .setErrorCode(Errors.GROUP_ID_NOT_FOUND.code())
+ .setErrorMessage("Group grp-unknown not found.")
Review Comment:
Instead of duplicating the code, I wonder if we could set those two fields based on the version. `.setErrorCode(if (version >= 6) error else null)`.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #17706:
URL: https://github.com/apache/kafka/pull/17706#discussion_r1870952660
##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -2642,17 +2645,25 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
val expectedOperations = AclEntry.supportedOperations(ResourceType.GROUP)
assertEquals(expectedOperations, testGroupDescription.authorizedOperations())
- // Test that the fake group is listed as dead.
+ // Test that the fake group throws GroupIdNotFoundException
assertTrue(describeWithFakeGroupResult.describedGroups().containsKey(fakeGroupId))
- val fakeGroupDescription = describeWithFakeGroupResult.describedGroups().get(fakeGroupId).get()
-
- assertEquals(fakeGroupId, fakeGroupDescription.groupId())
- assertEquals(0, fakeGroupDescription.members().size())
- assertEquals(GroupState.DEAD, fakeGroupDescription.groupState())
- assertNull(fakeGroupDescription.authorizedOperations())
+ try {
+ describeWithFakeGroupResult.describedGroups().get(fakeGroupId).get()
+ fail("Fake group should throw GroupIdNotFoundException")
+ } catch {
+ case e: ExecutionException =>
+ assertTrue(e.getCause.isInstanceOf[GroupIdNotFoundException])
+ }
- // Test that all() returns 2 results
- assertEquals(2, describeWithFakeGroupResult.all().get().size())
+ // Test that all() also throws GroupIdNotFoundException
+ try {
Review Comment:
ditto.
##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -2664,18 +2675,18 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
assertEquals(testGroupId, testGroupDescription.groupId)
assertEquals(consumerSet.size, testGroupDescription.members().size())
- // Describing a share group using describeConsumerGroups reports it as a DEAD consumer group
- // in the same way as a non-existent group
+ // Describing a share group using describeConsumerGroups reports it as a non-existent group
+ // but the error message is different
val describeConsumerGroupResult = client.describeConsumerGroups(Collections.singleton(testGroupId),
new DescribeConsumerGroupsOptions().includeAuthorizedOperations(true))
- assertEquals(1, describeConsumerGroupResult.all().get().size())
-
- val deadConsumerGroupDescription = describeConsumerGroupResult.describedGroups().get(testGroupId).get()
- assertEquals(testGroupId, deadConsumerGroupDescription.groupId())
- assertEquals(0, deadConsumerGroupDescription.members().size())
- assertEquals("", deadConsumerGroupDescription.partitionAssignor())
- assertEquals(ConsumerGroupState.DEAD, deadConsumerGroupDescription.state())
- assertEquals(expectedOperations, deadConsumerGroupDescription.authorizedOperations())
+ try {
Review Comment:
ditto.
##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -2209,18 +2205,25 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
val expectedOperations = AclEntry.supportedOperations(ResourceType.GROUP)
assertEquals(expectedOperations, testGroupDescription.authorizedOperations())
- // Test that the fake group is listed as dead.
+ // Test that the fake group throws GroupIdNotFoundException
assertTrue(describeWithFakeGroupResult.describedGroups().containsKey(fakeGroupId))
- val fakeGroupDescription = describeWithFakeGroupResult.describedGroups().get(fakeGroupId).get()
-
- assertEquals(fakeGroupId, fakeGroupDescription.groupId())
- assertEquals(0, fakeGroupDescription.members().size())
- assertEquals("", fakeGroupDescription.partitionAssignor())
- assertEquals(ConsumerGroupState.DEAD, fakeGroupDescription.state())
- assertEquals(expectedOperations, fakeGroupDescription.authorizedOperations())
+ try {
Review Comment:
Could we use `assertFutureThrows` here too?
##########
core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala:
##########
@@ -2642,17 +2645,25 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest {
val expectedOperations = AclEntry.supportedOperations(ResourceType.GROUP)
assertEquals(expectedOperations, testGroupDescription.authorizedOperations())
- // Test that the fake group is listed as dead.
+ // Test that the fake group throws GroupIdNotFoundException
assertTrue(describeWithFakeGroupResult.describedGroups().containsKey(fakeGroupId))
- val fakeGroupDescription = describeWithFakeGroupResult.describedGroups().get(fakeGroupId).get()
-
- assertEquals(fakeGroupId, fakeGroupDescription.groupId())
- assertEquals(0, fakeGroupDescription.members().size())
- assertEquals(GroupState.DEAD, fakeGroupDescription.groupState())
- assertNull(fakeGroupDescription.authorizedOperations())
+ try {
Review Comment:
ditto.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17550: DescribeGroups v6 exploitation [kafka]
Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on code in PR #17706:
URL: https://github.com/apache/kafka/pull/17706#discussion_r1869680802
##########
clients/src/main/java/org/apache/kafka/clients/admin/internals/DescribeConsumerGroupsHandler.java:
##########
@@ -354,11 +356,18 @@ private void handleError(
case GROUP_ID_NOT_FOUND:
if (isConsumerGroupResponse) {
log.debug("`{}` request for group id {} failed because the group is not " +
- "a new consumer group. Will retry with `DescribeGroups` API.", apiName, groupId.idValue);
+ "a new consumer group. Will retry with `DescribeGroups` API. {}",
Review Comment:
I think a debug log line is appropriate. There's a chance that diagnostics in this area might show something not quite right as users are migrating their clusters to the new protocol.
--
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-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org