You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "brandboat (via GitHub)" <gi...@apache.org> on 2025/01/13 16:22:34 UTC
[PR] KAFKA-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
brandboat opened a new pull request, #18510:
URL: https://github.com/apache/kafka/pull/18510
related to https://issues.apache.org/jira/browse/KAFKA-18409
ShareGroupStateMessageFormatter should extend ApiMessageFormatter in order to have a consistent handling of records of coordinators.
### 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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2765814925
> @brandboat It looks like https://github.com/apache/kafka/pull/18510/files#r2019007145 has not been addressed yet. Could you please address it?
My apologies, I've replaced all long string in the test with text blocks.
--
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] (WIP) KAFKA-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2753884551
> @brandboat We have merged https://github.com/apache/kafka/pull/18695. We can proceed with your PR. Please ping me when the PR is ready for review.
Thanks for the heads-up, I'll handle this ASAP!
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2612952667
@brandboat What do you think about this one: https://github.com/apache/kafka/pull/18695?
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r1914066204
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -79,5 +79,5 @@ public void writeTo(ConsumerRecord<byte[], byte[]> consumerRecord, PrintStream o
}
protected abstract JsonNode readToKeyJson(ByteBuffer byteBuffer);
- protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
-}
+ protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion);
Review Comment:
Yes, I've thought about that before, but that means we need to add below methods to `ApiMessageFormatter.java`.
```java
protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
protected JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion) {
return readToValueJson(byteBuffer);
}
```
But doing that means I need to override two methods in ShareGroupStateMessageFormatter.java, particularly readToValueJson(ByteBuffer byteBuffer). This method will essentially be a dummy method, which feels somewhat awkward to implement, so I decided to add an extra parameter to it instead.
```java
@Override
protected JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion) {
short valueVersion = byteBuffer.getShort();
return readToSnapshotMessageValue(byteBuffer, keyVersion, valueVersion)
.map(logValue -> transferValueMessageToJsonNode(logValue, valueVersion))
.orElseGet(() -> new TextNode(UNKNOWN));
}
@Override
protected JsonNode readToValueJson(ByteBuffer byteBuffer) {
return null;
}
```
Or you have other ideas? Let me know if you'd like any further adjustments!
--
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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r2019674728
##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/share/ShareGroupStateMessageFormatterTest.java:
##########
@@ -164,12 +164,16 @@ private static Stream<Arguments> exceptions() {
Arguments.of(
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_KEY).array(),
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_UPDATE_VALUE).array(),
- new RuntimeException("non-nullable field stateBatches was serialized as null")
+ new RuntimeException("Could not read record at offset 0 due to: " +
+ "Could not read record with version 0 from value's buffer due to: " +
+ "non-nullable field stateBatches was serialized as null.")
),
Arguments.of(
MessageUtil.toVersionPrefixedByteBuffer((short) 1, SHARE_UPDATE_KEY).array(),
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_VALUE).array(),
- new RuntimeException("non-nullable field stateBatches was serialized as null")
+ new RuntimeException("Could not read record at offset 0 due to: " +
+ "Could not read record with version 0 from value's buffer due to: " +
+ "non-nullable field stateBatches was serialized as null.")
)
);
}
Review Comment:
Thank you! I've addressed all the comments!
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r1915175546
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -79,5 +79,5 @@ public void writeTo(ConsumerRecord<byte[], byte[]> consumerRecord, PrintStream o
}
protected abstract JsonNode readToKeyJson(ByteBuffer byteBuffer);
- protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
-}
+ protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion);
Review Comment:
Not sure if this is a good idea, perhaps we can wait for others opinion.
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r1913502873
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -38,7 +38,7 @@ public abstract class ApiMessageFormatter implements MessageFormatter {
private static final String DATA = "data";
private static final String KEY = "key";
private static final String VALUE = "value";
- static final String UNKNOWN = "unknown";
+ public static final String UNKNOWN = "unknown";
Review Comment:
I think we should use the modifier `protected`.
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -79,5 +79,5 @@ public void writeTo(ConsumerRecord<byte[], byte[]> consumerRecord, PrintStream o
}
protected abstract JsonNode readToKeyJson(ByteBuffer byteBuffer);
- protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
-}
+ protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion);
Review Comment:
Since the `keyVersion` parameter is only used by the `ShareGroupStateMessageFormatter` class, we should refactor this to make the method less abstract. Instead of requiring all subclasses to implement the keyVersion parameter, we could:
1. Move keyVersion out of the abstract definition
2. Provide a default implementation in the base class
WDYT?
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2614556536
> @brandboat What do you think about this one: https://github.com/apache/kafka/pull/18695?
I think this is a better approach. The entire refactor looks great to me. I'll hold off on this PR until #18695 is merged. Thank you for letting me know!
--
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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2765707668
@brandboat It looks like https://github.com/apache/kafka/pull/18510/files#r2019007145 has not been addressed yet. Could you please address it?
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "m1a2st (via GitHub)" <gi...@apache.org>.
m1a2st commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r1914925979
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -79,5 +79,5 @@ public void writeTo(ConsumerRecord<byte[], byte[]> consumerRecord, PrintStream o
}
protected abstract JsonNode readToKeyJson(ByteBuffer byteBuffer);
- protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
-}
+ protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion);
Review Comment:
I propose changing the `JsonNode readToValueJson` signature to accept a `ConsumerRecord<byte[], byte[]>`parameter. This would standardize the method signature across all subclasses. WDYT?
```
protected JsonNode readToValueJson(ConsumerRecord<byte[], byte[]> consumerRecord)
```
--
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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac merged PR #18510:
URL: https://github.com/apache/kafka/pull/18510
--
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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2761854496
Gentle ping @dajac, CI passed, could you take a look when you are available? Thank you!
--
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] (WIP) KAFKA-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on PR #18510:
URL: https://github.com/apache/kafka/pull/18510#issuecomment-2753880538
@brandboat We have merged https://github.com/apache/kafka/pull/18695. We can proceed with your PR. Please ping me when the PR is ready for review.
--
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-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter [kafka]
Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r2019012548
##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/share/ShareGroupStateMessageFormatterTest.java:
##########
@@ -164,12 +164,16 @@ private static Stream<Arguments> exceptions() {
Arguments.of(
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_KEY).array(),
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_UPDATE_VALUE).array(),
- new RuntimeException("non-nullable field stateBatches was serialized as null")
+ new RuntimeException("Could not read record at offset 0 due to: " +
+ "Could not read record with version 0 from value's buffer due to: " +
+ "non-nullable field stateBatches was serialized as null.")
),
Arguments.of(
MessageUtil.toVersionPrefixedByteBuffer((short) 1, SHARE_UPDATE_KEY).array(),
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_VALUE).array(),
- new RuntimeException("non-nullable field stateBatches was serialized as null")
+ new RuntimeException("Could not read record at offset 0 due to: " +
+ "Could not read record with version 0 from value's buffer due to: " +
+ "non-nullable field stateBatches was serialized as null.")
)
);
}
Review Comment:
Could we remove `testShareGroupStateMessageFormatter`? We have it in the parent class now.
##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/share/ShareGroupStateMessageFormatterTest.java:
##########
@@ -137,23 +137,23 @@ private static Stream<Arguments> parameters() {
Arguments.of(
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_KEY).array(),
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_VALUE).array(),
- "{\"key\":{\"version\":0,\"data\":{\"groupId\":\"gs1\",\"topicId\":\"gtb2stGYRk-vWZ2zAozmoA\",\"partition\":0}},\"value\":{\"version\":0,\"data\":{\"snapshotEpoch\":0,\"stateEpoch\":1,\"leaderEpoch\":20,\"startOffset\":50,\"stateBatches\":[{\"firstOffset\":100,\"lastOffset\":200,\"deliveryState\":1,\"deliveryCount\":10},{\"firstOffset\":201,\"lastOffset\":210,\"deliveryState\":2,\"deliveryCount\":10}]}}}"
+ "{\"key\":{\"type\":0,\"data\":{\"groupId\":\"gs1\",\"topicId\":\"gtb2stGYRk-vWZ2zAozmoA\",\"partition\":0}},\"value\":{\"version\":0,\"data\":{\"snapshotEpoch\":0,\"stateEpoch\":1,\"leaderEpoch\":20,\"startOffset\":50,\"stateBatches\":[{\"firstOffset\":100,\"lastOffset\":200,\"deliveryState\":1,\"deliveryCount\":10},{\"firstOffset\":201,\"lastOffset\":210,\"deliveryState\":2,\"deliveryCount\":10}]}}}"
Review Comment:
nit: Would it be possible to use the new test blocks like we did for the other formatters?
--
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-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter [kafka]
Posted by "brandboat (via GitHub)" <gi...@apache.org>.
brandboat commented on code in PR #18510:
URL: https://github.com/apache/kafka/pull/18510#discussion_r1914032613
##########
tools/src/main/java/org/apache/kafka/tools/consumer/ApiMessageFormatter.java:
##########
@@ -38,7 +38,7 @@ public abstract class ApiMessageFormatter implements MessageFormatter {
private static final String DATA = "data";
private static final String KEY = "key";
private static final String VALUE = "value";
- static final String UNKNOWN = "unknown";
+ public static final String UNKNOWN = "unknown";
Review Comment:
Sure, thanks.
--
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