-
Notifications
You must be signed in to change notification settings - Fork 992
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 binder without JMX #1835
Kafka binder without JMX #1835
Conversation
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the pull request. This generally seems like the right direction.
I left some comments - please take a look.
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
...eter-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaClientMetricsIT.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
I'd like to add that I do agree an approach like #1173 could be complementary to export metrics when there are off-the-shelf components like Kafka Connectors, and we can pass this instrumentation via config. Similar to Zipkin's Brave for streams and clients, and Zipkin kafka interceptors |
I've removed the |
002a4d1
to
039d6ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few comments. I'm really wanting to move away from running the logic on each time the kafka metric values are read. Maybe a task scheduler that runs the logic once per step per registered MeterRegistry would be better. It would need to be cleaned up when the MeterBinder is closed, like notification listeners with some JMX-based MeterBinders.
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaMetricsTest.java
Outdated
Show resolved
Hide resolved
micrometer-core/src/test/java/io/micrometer/core/instrument/binder/kafka/KafkaMetricsTest.java
Show resolved
Hide resolved
micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaMetrics.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're just about ready to ship this. Could you rebase this on the latest master? I did some ad-hoc testing myself but I don't have any realistic apps using Kafka. Have you tried this out with some kafka apps to make sure everything looks as expected? I think the plan will be to release this in 1.4 (non-LTS) as an Incubating feature, gather feedback from users on it, and hopefully with enough feedback, remove the Incubating status in time for 1.5 (LTS).
Sounds great! I've test it with this sample application https://github.com/jeqo/tracing-kafka-apps/compare/metrics and works as expected on all components (producer/consumer/streams). |
e.g. producer metrics in Prometheus format:
|
Will you skip the group |
@saltos thanks for your review. I'm ok removing |
@jeqo thank you for the reply. I've add some extra test for my code... You are right. |
@shakuzen do you have an opinion about removing I'm between adding an special path to name this counter properly (e.g. Testing consumer/producer (IT) with the same registry lead to 2 meters with the same tags: |
I would be inclined to go with filtering it out unless a Kafka user can make a case for why they would want that metric specifically. It would not break anyone to filter it out initially and undo that decision later, but it might be breaking for someone if we decide to filter it later. |
with current naming this group is named kafka.kafka.count.count which is useless if users request this counter we have to add an alternative naming for it
@jeqo Thank you so much for your perseverance on getting this to the state it is now and testing. Supporting Kafka producer metrics and stream metrics have been highly popular feature requests, and with this we will finally have them. Great work! |
Waiting for micrometer-metrics/micrometer#1835 release I simply copy the implementation and add collectors on all Kafka client
Yes, as a result I have only one metric with |
I found some odd behaviour with a consumer metrics.
Function Collection<Meter> meters = registry.find(metricName(metric)).meters();
for (Meter meter : meters) {
if (meter.getId().getTags().size() < (metricTags(metric).size() + extraTagsSize))
registry.remove(meter);
// Check if already exists
else if (meter.getId().getTags().equals(metricTags(metric))) return;
else hasLessTags = true;
} The condition for (Meter meter : meters) {
List<Tag> meterTags = meter.getId().getTags();
List<Tag> metricTags = metricTags(metric);
metricTags.addAll(tags);
if (meterTags.size() < metricTags.size()) {
registry.remove(meter);
} else if (meterTags.size() == metricTags.size()) {
if (meter.getId().getTags().equals(metricTags)) {
// do not register the metric with the same tags
return;
} else {
// create the new metric with different values of the tags
break;
}
} else {
hasLessTags = true;
}
} and got all 3 metrics.
|
@saltos Thank you for testing this out and reporting back your findings - it's great to find these kinds of things before the release. Would you please make a new issue to track this? If you would be interested, also feel free to make a pull request with your mentioned changes. Ideally we would want to add a test case that covers the scenario you found. Thanks again for the help! |
@shakuzen Ok, I will make an issue and try to make a pull request with the test, that's my pleasure. You are doing a really remarkable job. |
@jeqo Awesome, great job! This solves the problem. |
Support for Clients (Consumer/Producer/Admin APIs) and Streams via
metrics
API, instead of JMX-based metrics.There are 3 different interfaces to gather metrics from Kafka applications:
JMX exported metrics have been used as a first attempt to gather metrics, but there some downsides to consider:
Metrics Reporter is another option, which require to load an implementation of MetricsReporter when configuring Kafka clients. Downsides (?):
Metrics API (proposed by this PR) uses
KafkaClient#metrics()
method to gather current metrics available in a client instance.Resolves #1095
Resolves #1096