Skip to content
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

KAFKA-6896: Add producer metrics exporting in KafkaStreams.java #4998

Merged
merged 1 commit into from
May 15, 2018

Conversation

abbccdda
Copy link
Contributor

We would like to also export the producer metrics from StreamThread just like consumer metrics, so that we could gain more visibility of stream application. The approach is to pass in the threadProducer into the StreamThread so that we could export its metrics in dynamic.

Note that this is a pure internal change that doesn't require a KIP, and in the future we also want to export admin client metrics. A followup KIP for admin client will be created once this is merged.

@abbccdda
Copy link
Contributor Author

@guozhangwang @mjsax Let me know your thoughts on this one. Thank you!

@mjsax
Copy link
Member

mjsax commented May 10, 2018

I think the change makes sense. However, we should have a corresponding JIRA. Furthermore, the PR would not be sufficient if EOS is enabled, because for EOS there is no thread producer but a producer per task.

Copy link
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

Could we add a unit test around KafkaStreams.metrics() to check that all the expected metrics are included?

final Map<MetricName, ? extends Metric> producerMetrics = producer.metrics();
result.putAll(producerMetrics);
} else {
log.info("producer is null in thread {}", toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Capitalize p.

@@ -387,6 +387,7 @@ public void setGlobalStateRestoreListener(final StateRestoreListener globalState
public Map<MetricName, ? extends Metric> metrics() {
final Map<MetricName, Metric> result = new LinkedHashMap<>();
for (final StreamThread thread : threads) {
result.putAll(thread.producerMetrics());
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the above TODO with only admin client left.

@@ -690,6 +693,7 @@ public StreamThread(final Time time,
this.log = logContext.logger(StreamThread.class);
this.rebalanceListener = new RebalanceListener(time, taskManager, this, this.log);
this.taskManager = taskManager;
this.producer = producer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... note that when EOS is turned on, each task will has its own producer client and the producer object passed in here will be null.

So I'd suggest update the following code in line 1224: when producer == null, try to iterate the owned tasks from the taskManager.activeTasks().values() and get its producer (it is private, so we may need to add a package private getter).

In this way for both EOS and non-EOS we will get the producer metrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense to me!

@abbccdda
Copy link
Contributor Author

@mjsax thank you for the suggestion! Will prepare a JIRA.

@abbccdda
Copy link
Contributor Author

@guozhangwang regarding the unit test on KafkaStreams, the issue is that current mock producer/consumer doesn't provide metrics map on call to metrics(). The solution I could think of is to define a class overwriting the MockProducer.metrics() so that we could pass in predefined metrics and get them back. Do you think that would be a little overkill?

@guozhangwang guozhangwang changed the title add producer metrics exporting in KafkaStreams.java MINOR: Add producer metrics exporting in KafkaStreams.java May 11, 2018
@guozhangwang guozhangwang changed the title MINOR: Add producer metrics exporting in KafkaStreams.java KAFKA-6896: Add producer metrics exporting in KafkaStreams.java May 11, 2018
@guozhangwang
Copy link
Contributor

@abbccdda I see... I think we can overwrite MockConsumer/MockProducer.metrics() but we do not need to return the full map of all metrics, but only a MockMetric, i.e. one metric object for each client.

If you think this change is too large, we can also do that in another JIRA.

@abbccdda
Copy link
Contributor Author

@guozhangwang thanks for the feedback. I added a helper function in the MockProducer to send back a mock metric. However, when EOS is on, we take metrics from task producers. I'm not sure how to test that, suggestion?

@mjsax
Copy link
Member

mjsax commented May 12, 2018

Build failed with checkstyle error.

@abbccdda
Copy link
Contributor Author

@mjsax thanks for the heads up!

@guozhangwang
Copy link
Contributor

@abbccdda I think for EOS the test coverage it a bit tricky as it needs the mock task manager to also return the assigned tasks. Let wait to put in into another PR (please add a TODO on producerMetricsVerificationWithoutEOS for adding this test case with EOS)

@abbccdda
Copy link
Contributor Author

@guozhangwang thanks for the tip. I have added the todo and now I will be focusing on fixing the build.

@abbccdda abbccdda force-pushed the only_producer branch 2 times, most recently from 6be6243 to 8c857b9 Compare May 15, 2018 16:31
@abbccdda
Copy link
Contributor Author

@guozhangwang could you take a final look since the test passes? Thank you!

@guozhangwang guozhangwang merged commit 1e207b2 into apache:trunk May 15, 2018
@guozhangwang
Copy link
Contributor

Merged to trunk, thanks @abbccdda !

@abbccdda
Copy link
Contributor Author

@guozhangwang thank you!!!

@abbccdda abbccdda deleted the only_producer branch May 18, 2018 21:20
guozhangwang pushed a commit that referenced this pull request Jun 29, 2018
KAFKA-6986:Export Admin Client metrics through Stream Threads

We already exported producer and consumer metrics through KafkaStreams class:

#4998

It makes sense to also export the Admin client metrics.

I didn't add a separate unittest case for this. Let me know if it's needed.

This is my first contribution, feel free to point out any mistakes that I did.

Reviewers: Guozhang Wang <wangguoz@gmail.com>
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
We would like to also export the producer metrics from StreamThread just like consumer metrics, so that we could gain more visibility of stream application. The approach is to pass in the threadProducer into the StreamThread so that we could export its metrics in dynamic.

Note that this is a pure internal change that doesn't require a KIP, and in the future we also want to export admin client metrics. A followup KIP for admin client will be created once this is merged.

Reviewers: Guozhang Wang <wangguoz@gmail.com>
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
…e#5210)

KAFKA-6986:Export Admin Client metrics through Stream Threads

We already exported producer and consumer metrics through KafkaStreams class:

apache#4998

It makes sense to also export the Admin client metrics.

I didn't add a separate unittest case for this. Let me know if it's needed.

This is my first contribution, feel free to point out any mistakes that I did.

Reviewers: Guozhang Wang <wangguoz@gmail.com>
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.

3 participants