Skip to content

KAFKA-6123: Give client MetricsReporter auto-generated client.id#5383

Merged
cmccabe merged 8 commits into
apache:trunkfrom
KevinLiLu:KAFKA-6123
Oct 3, 2018
Merged

KAFKA-6123: Give client MetricsReporter auto-generated client.id#5383
cmccabe merged 8 commits into
apache:trunkfrom
KevinLiLu:KAFKA-6123

Conversation

@KevinLiLu

@KevinLiLu KevinLiLu commented Jul 18, 2018

Copy link
Copy Markdown
Contributor

The client's MetricsReporter class currently receives the client.id field only if the user has configured it. The auto-generated client.id is not passed to the MetricsReporter.

  • Give auto generated client.id as a config override to MetricsReporter (same way KAFKA-4756 handles it)

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

Hi @cmccabe @ijuma @junrao @guozhangwang ,

Can I get a review?

Thanks!

@cmccabe

cmccabe commented Jul 18, 2018

Copy link
Copy Markdown
Contributor

Hmm, does this require a KIP? I'm not sure...

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@cmccabe I wasn't sure about that either... This PR is to address an edge case where the client.id does not get passed to the MetricsReporter, as opposed to giving a completely new configuration.

@ijuma

ijuma commented Jul 20, 2018

Copy link
Copy Markdown
Member

This seems like a big fix to me, not sure a KIP is needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you check that the auto-generated client ID appears here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't you check KafkaConsumer#clientId? We could add a package-private accessor only to be used for testing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you check that the auto-generated client id appears here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See comment above ^

@cmccabe

cmccabe commented Jul 31, 2018

Copy link
Copy Markdown
Contributor

@ijuma : I guess you're right; we probably don't need a KIP for this. I left some comments here.

@omkreddy

omkreddy commented Aug 1, 2018

Copy link
Copy Markdown
Contributor

Can we also update other classes?

KafkaAdminClient.java
KafkaStreams.java
WorkerGroupMember.java

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@omkreddy We definitely should. Would you also recommend adding a package-private clientId getter in each of these client classes for testing purposes?

@omkreddy

omkreddy commented Aug 1, 2018

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Can't we update and reuse existing MockMetricsReporter class? just trying to avoid adding new class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

Ok, I have added the same logic to KafkaAdminClient, KafkaStreams, and WorkerGroupMember.

The producer & consumer unit tests currently just verify if the auto-generated prefix matches in the unit tests.

@omkreddy

omkreddy commented Aug 1, 2018

Copy link
Copy Markdown
Contributor

There is a checkstyle error

 Task :clients:checkstyleTest
07:23:27 [ant:checkstyle] [ERROR] /home/jenkins/jenkins-slave/workspace/kafka-pr-jdk8-scala2.11@2/clients/src/test/java/org/apache/kafka/test/MockMetricsReporter.java:53:79: Empty statement. [EmptyStatement]

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@cmccabe @omkreddy

I have added the package-private getters to KafkaProducer and KafkaConsumer so that the tests check the exact client ids now.

What do you guys think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should not be static. We might want to run unit tests in parallel.

@KevinLiLu KevinLiLu Aug 7, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I have pushed a new commit that addresses this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

generally in assertEquals, the thing being tested comes second. If there is an error message, the first thing appears as the "expected value"

@KevinLiLu KevinLiLu Aug 7, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, you're right. The thing being tested should be second.

@cmccabe

cmccabe commented Aug 10, 2018

Copy link
Copy Markdown
Contributor

LGTM. Thanks, @KevinLiLu

@cmccabe

cmccabe commented Aug 10, 2018

Copy link
Copy Markdown
Contributor

retest this please

1 similar comment
@KevinLiLu

Copy link
Copy Markdown
Contributor Author

retest this please

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@hachikuji @rajinisivaram @guozhangwang @ijuma

Can we get a committer to review/merge this?

Thanks @cmccabe for the review!

@harshach

Copy link
Copy Markdown

@KevinLiLu overall LGTM. +1 after addressing the minor nits.

@KevinLiLu

KevinLiLu commented Aug 23, 2018

Copy link
Copy Markdown
Contributor Author

@harshach Thanks for the comment! I have addressed the previous comments. Are there any additional changes needed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: please add protected keyword

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

protected gives more visibility than what's there now (package visibility) so not sure why we'd want to do that?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: please add protected keyword

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

protected gives more visibility than what's there now (package visibility) so not sure why we'd want to do that?

@harshach

Copy link
Copy Markdown

@KevinLiLu sorry I had drafted comments which weren't published earlier. Can you please take a look.

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

Hi @harshach , is there a particular reason the helper methods for testing should be set to protected?

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

Hi @lindong28 @hachikuji @rajinisivaram @guozhangwang , can we get a committer to review and close out this minor bug fix? Thanks~

@cmccabe

cmccabe commented Sep 28, 2018

Copy link
Copy Markdown
Contributor

Any objections to committing this fix and working on any follow-ups in a separate PR?

@lindong28

Copy link
Copy Markdown
Member

@cmccabe If the follow-up is related to whether we should have protected keyword, given that Harsha has not responded and there does not seem to be a reason for protected, I think we can just commit the patch and work on follow-ups in a separate PR if needed.

@cmccabe

cmccabe commented Oct 1, 2018

Copy link
Copy Markdown
Contributor

retest this please

@KevinLiLu

KevinLiLu commented Oct 1, 2018

Copy link
Copy Markdown
Contributor Author

@cmccabe @lindong28

Seeing an unrelated test failure in kafka.server.DynamicBrokerReconfigurationTest.testUncleanLeaderElectionEnable. And the JDK 8 test seems to be stuck.

Should I do a rebase with trunk? Looks like that test case may have been fixed in a more recent commit.

@cmccabe

cmccabe commented Oct 1, 2018

Copy link
Copy Markdown
Contributor

Yes, please. Let's rebase on trunk.

@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@cmccabe

Rebased and now the tests all pass!

@cmccabe

cmccabe commented Oct 3, 2018

Copy link
Copy Markdown
Contributor

Thanks, @KevinLiLu. LGTM.

@harshach, let's open a follow-on JIRA if there's any more fixups we should make.

Thanks, all.

@cmccabe
cmccabe merged commit a5335e7 into apache:trunk Oct 3, 2018
@KevinLiLu

Copy link
Copy Markdown
Contributor Author

@cmccabe

Thanks for the merge! Also, congrats on committer!

pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants