KAFKA-6123: Give client MetricsReporter auto-generated client.id#5383
Conversation
|
Hi @cmccabe @ijuma @junrao @guozhangwang , Can I get a review? Thanks! |
|
Hmm, does this require a KIP? I'm not sure... |
|
@cmccabe I wasn't sure about that either... This PR is to address an edge case where the |
|
This seems like a big fix to me, not sure a KIP is needed. |
There was a problem hiding this comment.
Can you check that the auto-generated client ID appears here?
There was a problem hiding this comment.
It is loosely checking the auto-generated client ID by checking for the prefix producer-. This is because there are many other tests that create clients without specifying the client.id, which increments the static CONSUMER_CLIENT_ID_SEQUENCE and PRODUCER_CLIENT_ID_SEQUENCE. This is problematic as the auto-generated client ID value then depends on the order of test execution.
There are no getters/setters for this client ID sequence so it is not easy to test for exact auto-generated client ID.
I see two options here:
(1) Make all other tests set a client ID
We could make all other tests set the client.id field so that the auto-generated client ID will be suffixed with -1 (producer-1, consumer-1). All future tests would have to follow this and set client ids to ensure these tests always pass (if tests are not always executed in the same order, then we could get into a bad situation where it fails sometimes).
(2) Create getter methods to mock
We could create getter methods getConsumerClientIdSequence() and getProducerClientIdSequence() in KafkaConsumer and KafkaProducer, and mock them in the unit tests. This will allow us to check for the exact value.
Thoughts? @ijuma
There was a problem hiding this comment.
Can't you check KafkaConsumer#clientId? We could add a package-private accessor only to be used for testing.
There was a problem hiding this comment.
There is no clientId getter currently, but it would indeed be easier if we had a package-private accessor for testing.
Would there be any point in exposing this getter as public?
There was a problem hiding this comment.
Good question. I can't think of any right now (maybe someone else can?) so I would lean towards keeping it package-private for now.
There was a problem hiding this comment.
Can you check that the auto-generated client id appears here?
There was a problem hiding this comment.
See comment above ^
|
@ijuma : I guess you're right; we probably don't need a KIP for this. I left some comments here. |
|
Can we also update other classes? |
|
@omkreddy We definitely should. Would you also recommend adding a package-private clientId getter in each of these client classes for testing purposes? |
|
Since it is a similar change across all classes, I am not sure if we need tests for all classes. KafkaProducer/Consumer test cases may be sufficient. but let others take a call. |
There was a problem hiding this comment.
nit: Can't we update and reuse existing MockMetricsReporter class? just trying to avoid adding new class.
|
Ok, I have added the same logic to The producer & consumer unit tests currently just verify if the auto-generated prefix matches in the unit tests. |
|
There is a checkstyle error |
There was a problem hiding this comment.
This should not be static. We might want to run unit tests in parallel.
There was a problem hiding this comment.
Good point. I have pushed a new commit that addresses this.
There was a problem hiding this comment.
generally in assertEquals, the thing being tested comes second. If there is an error message, the first thing appears as the "expected value"
There was a problem hiding this comment.
When using assert, the first parameter is expected and second parameter is actual right? In this case, we are testing that the MetricsReporter's client.id will match the correct (expected) client id from the client. The client is the one generating the client.id, and the MetricsReporter needs to receive it correctly.
producer.getClientId() should be first and MockMetricsReporter.clientId should be second?
There was a problem hiding this comment.
Sorry, you're right. The thing being tested should be second.
|
LGTM. Thanks, @KevinLiLu |
|
retest this please |
1 similar comment
|
retest this please |
|
@hachikuji @rajinisivaram @guozhangwang @ijuma Can we get a committer to review/merge this? Thanks @cmccabe for the review! |
|
@KevinLiLu overall LGTM. +1 after addressing the minor nits. |
|
@harshach Thanks for the comment! I have addressed the previous comments. Are there any additional changes needed? |
There was a problem hiding this comment.
protected gives more visibility than what's there now (package visibility) so not sure why we'd want to do that?
There was a problem hiding this comment.
protected gives more visibility than what's there now (package visibility) so not sure why we'd want to do that?
|
@KevinLiLu sorry I had drafted comments which weren't published earlier. Can you please take a look. |
|
Hi @harshach , is there a particular reason the helper methods for testing should be set to protected? |
|
Hi @lindong28 @hachikuji @rajinisivaram @guozhangwang , can we get a committer to review and close out this minor bug fix? Thanks~ |
|
Any objections to committing this fix and working on any follow-ups in a separate PR? |
|
@cmccabe If the follow-up is related to whether we should have |
|
retest this please |
|
Seeing an unrelated test failure in Should I do a rebase with trunk? Looks like that test case may have been fixed in a more recent commit. |
|
Yes, please. Let's rebase on trunk. |
|
Rebased and now the tests all pass! |
|
Thanks, @KevinLiLu. LGTM. @harshach, let's open a follow-on JIRA if there's any more fixups we should make. Thanks, all. |
|
Thanks for the merge! Also, congrats on committer! |
The client's
MetricsReporterclass currently receives theclient.idfield only if the user has configured it. The auto-generatedclient.idis not passed to theMetricsReporter.client.idas a config override toMetricsReporter(same way KAFKA-4756 handles it)Committer Checklist (excluded from commit message)