-
Notifications
You must be signed in to change notification settings - Fork 9
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
Use global Collector to handle multiple reporters in the JVM #46
Conversation
Signed-off-by: Mickael Maison <[email protected]>
@@ -60,6 +60,23 @@ consumer.metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporte | |||
consumer.auto.include.jmx.reporter=false | |||
``` | |||
|
|||
When setting configurations for the Prometheus metrics reporter, they also need to be set with the `admin.`, `producer.` and `consumer.`. |
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.
In the block above you are telling the reader how to enable the reporter for Connect/Streams and then in the block below, you show how to supply configuration. So, lines 54, 56, 58 and 60 seem unnecessary/repetitious - as you will show that again a few lines below.
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.
The example above shows how to enable the reporter. I added this sentence to say that you also need to add the prefixes when setting reporter-specific configurations for example prometheus.metrics.reporter.allowlist
.
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.
Got it. I misunderstood. "auto.include.jmx.reporter" is property understood by Kafka itself. I had mistakenly thought it was being consumed by our reporter.
producer.auto.include.jmx.reporter=false | ||
consumer.metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter | ||
consumer.prometheus.metrics.reporter.listener=http://:8081 | ||
consumer.auto.include.jmx.reporter=false |
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.
Wider point, I don't find the admin.
and producer.
and consumer.
prefixes particularly intuitive. If I had to guess what they did, my immediate thought would be that they control an aspect related to the ordinary Kafka Admin, Producer and Consumer clients, not something particular to Streams or Connect. I'm not really too familiar with either Streams or Connect, so maybe it is obvious to someone working in that space.
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.
Streams and Connect can be seen as "regular" applications and for all of their interactions with Kafka they use internal consumer, producer or admin clients. Both Streams and Connect use these prefixes to pass configurations to all the internal clients they use.
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.
ok. so it should be familiar to those working with Streams/Connect.
*/ | ||
public YammerMetricsCollector() { | ||
this.metrics = new ConcurrentHashMap<>(); | ||
public static PrometheusCollector register(PrometheusRegistry registry) { |
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.
Code smell - single pattern without a private constructor.
I wonder if you shifted the responsibility for the singleton to a separate class (CollectorHolder
)
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.
The only reason I did not add a private constructor is for tests. It's useful to get unique instances instead of the global collector so tests are independent. We can add a package-only constructor.
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've added a package only constructor in 79dd195
I have tested this with the
The error outlined in #43 |
Signed-off-by: Mickael Maison <[email protected]>
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.
lgtm
Signed-off-by: Mickael Maison <[email protected]>
This allows starting multiple reporter instances in the same JVM. All reporters share a global Collector,
PrometheusCollector
, which aggregates the metrics from all reporter instances.This allows multiple reporters to register metrics with the same names (but different labels). This happen when multiple instances of a Kafka client (producer, consumer, admin) are started in the same JVM.
This fixes #43