Skip to content

Conversation

Yunyung
Copy link
Collaborator

@Yunyung Yunyung commented Sep 11, 2025

  • Improve the docs for Record Headers.
  • Add integration tests to verify that the order of headers in a record
    is preserved when producing and consuming.
  • Add unit tests for RecordHeaders.java.

Reviewers: Ken Huang [email protected], Hong-Yi Chen
[email protected], Chia-Ping Tsai [email protected]

@github-actions github-actions bot added triage PRs from the community clients small Small PRs labels Sep 11, 2025
@Yunyung Yunyung changed the title KAFKA-19644: Enhance the documentation for producer headers KAFKA-19644: Enhance the documentation for producer headers and integration tests Sep 11, 2025
Copy link
Contributor

@apalan60 apalan60 left a comment

Choose a reason for hiding this comment

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

@Yunyung
Thanks for the patch, I just left a minor comment for your consideration.

headerKey: String
headerValueLength: varint
Value: byte[]</code></pre>
<p>The key of a record header is guaranteed to be non-null, while the value of a record header may be null. The order of headers in a record is preserved when producing and consuming.</p>
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 comments to the public API Header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@github-actions github-actions bot removed the triage PRs from the community label Sep 12, 2025
Comment on lines 198 to 210
@ClusterTest
public void testClassicConsumerHeadersOrderPreserved() throws Exception {
testHeadersOrderPreserved(Map.of(
GROUP_PROTOCOL_CONFIG, GroupProtocol.CLASSIC.name().toLowerCase(Locale.ROOT)
));
}

@ClusterTest
public void testAsyncConsumerHeadersOrderPreserved() throws Exception {
testHeadersOrderPreserved(Map.of(
GROUP_PROTOCOL_CONFIG, GroupProtocol.CONSUMER.name().toLowerCase(Locale.ROOT)
));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you move testClassicConsumerHeadersOrderPreserved and testAsyncConsumerHeadersOrderPreserved methods under the testHeaders test and group the related ones together?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@Yunyung
Copy link
Collaborator Author

Yunyung commented Sep 12, 2025

Thanks for the review, all! Updated based on the comments.

package org.apache.kafka.common.header;

/**
* The key of a header is guaranteed to be non-null, while the value of a header may be null.
Copy link
Member

Choose a reason for hiding this comment

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

Please add the comments to each method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Thanks.

@chia7712
Copy link
Member

the flaky is traced by KAFKA-7542

}

@Test
public void testAddHeadersPreserveOder() {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Oder -> Order

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

* @param key to return the headers for; must not be null.
* @return all headers for the given key, in the order they were added in, if NO headers are present an empty iterable is returned.
*/
Iterable<Header> headers(String key);
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 documents and ut for the Iterable#remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Thanks!

@github-actions github-actions bot removed the small Small PRs label Sep 19, 2025

/**
* Returns all headers for the given key, in the order they were added in, if present.
* The returned iterators {@link org.apache.kafka.common.utils.AbstractIterator#remove()} always throws {@link UnsupportedOperationException}.
Copy link
Member

Choose a reason for hiding this comment

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

AbstractIterator is not a public API. Perhaps we could just state the Iterable#remove is unsupported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Updated.

@chia7712 chia7712 merged commit 57e9f98 into apache:trunk Sep 20, 2025
26 checks passed
jim0987795064 pushed a commit to jim0987795064/kafka that referenced this pull request Sep 25, 2025
…ation tests (apache#20524)

- Improve the docs for Record Headers.
- Add integration tests to verify that the order of headers in a record
is preserved when producing and consuming.
- Add unit tests for RecordHeaders.java.

Reviewers: Ken Huang <[email protected]>, Hong-Yi Chen
 <[email protected]>, 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.

4 participants