Skip to content

KAFKA-18616; Refactor Tools's ApiMessageFormatter #18695

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

Merged
merged 10 commits into from
Mar 26, 2025
Merged

Conversation

dajac
Copy link
Member

@dajac dajac commented Jan 24, 2025

This patch refactors the ApiMessageFormatter to follow what we have done in #18688.

Reviewers: Chia-Ping Tsai [email protected]

@dajac dajac added the do-not-merge PRs that are only open temporarily and should not be merged label Jan 24, 2025
@github-actions github-actions bot added the tools label Jan 24, 2025
@dajac
Copy link
Member Author

dajac commented Jan 24, 2025

@chia7712 What do you think about doing something like this?

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder whether we should strengthen the version validation in the CoordinatorRecordSerdes.

If the version of the value record bumps in the future, formatters that lack version checks may print incorrect data. In such cases, throwing an accurate exception would be more appropriate.

@dajac
Copy link
Member Author

dajac commented Jan 30, 2025

This makes me wonder whether we should strengthen the version validation in the CoordinatorRecordSerdes.

If the version of the value record bumps in the future, formatters that lack version checks may print incorrect data. In such cases, throwing an accurate exception would be more appropriate.

@chia7712 I agree. I opened #18749 to address it.

@dajac dajac requested a review from chia7712 March 24, 2025 12:32
@dajac
Copy link
Member Author

dajac commented Mar 24, 2025

@chia7712 I finally had the time to update this one. Could you take another look when you get a chance?

@dajac dajac changed the title (WIP) KAFKA-18616; Refactor Tools's ApiMessageFormatter KAFKA-18616; Refactor Tools's ApiMessageFormatter Mar 24, 2025
@dajac dajac removed the do-not-merge PRs that are only open temporarily and should not be merged label Mar 24, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dajac thanks for this patch. overall LGTM

JsonNode dataNode = readToKeyJson(ByteBuffer.wrap(key));
json
.putObject(KEY)
.put(TYPE, record.key().apiKey())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShareGroupStateMessageFormatter use "version" rather than "type", but I guess we fix it in the follow-up by refactoring ShareGroupStateMessageFormatter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. We will it in #18510.

import static java.util.Collections.emptyMap;
import static org.junit.jupiter.api.Assertions.assertEquals;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it used to speedup those tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to allow using a non-static method in @MethodSource.


@ParameterizedTest
@MethodSource("parameters")
public void testMessageFormatter(byte[] keyBuffer, byte[] valueBuffer, String expectedOutput) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add unit test for UnknownRecordTypeException?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I added test cases to the concrete classes.

@dajac
Copy link
Member Author

dajac commented Mar 26, 2025

@chia7712 Thanks for your comments. I just addressed them.

@dajac dajac requested a review from chia7712 March 26, 2025 07:51
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dajac dajac merged commit b6adec4 into apache:trunk Mar 26, 2025
24 checks passed
@dajac dajac deleted the KAFKA-18616 branch March 26, 2025 10:12
ShivsundarR pushed a commit to ShivsundarR/kafka that referenced this pull request Mar 26, 2025
This patch refactors the `ApiMessageFormatter` to follow what we have
done in apache#18688.

Reviewers: Chia-Ping Tsai <[email protected]>
janchilling pushed a commit to janchilling/kafka that referenced this pull request Apr 4, 2025
This patch refactors the `ApiMessageFormatter` to follow what we have
done in apache#18688.

Reviewers: Chia-Ping Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants