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

Use global Collector to handle multiple reporters in the JVM #46

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

mimaison
Copy link
Contributor

@mimaison mimaison commented Sep 13, 2024

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

@mimaison mimaison added this to the 0.1.0 milestone Sep 13, 2024
@@ -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.`.
Copy link

@k-wall k-wall Sep 16, 2024

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.

Copy link
Contributor Author

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.

Copy link

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
Copy link

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.

Copy link
Contributor Author

@mimaison mimaison Sep 17, 2024

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.

Copy link

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) {
Copy link

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@OwenCorrigan76
Copy link
Contributor

OwenCorrigan76 commented Sep 19, 2024

I have tested this with the Streams WordCount app mentioned in the issue with the following config in Streams:

metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter
auto.include.jmx.reporter=false
admin.metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter
admin.auto.include.jmx.reporter=false
producer.metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter
producer.auto.include.jmx.reporter=false
consumer.metric.reporters=io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter
consumer.auto.include.jmx.reporter=false
prometheus.metrics.reporter.listener = http://localhost:8080

The error outlined in #43 An Exception occurred while scraping metrics: java.lang.IllegalStateException: kafka_consumer_app_info_commit_id: duplicate metric name is gone

Copy link

@k-wall k-wall left a comment

Choose a reason for hiding this comment

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

lgtm

@mimaison mimaison merged commit 9fa996a into strimzi:main Sep 30, 2024
7 checks passed
@mimaison mimaison deleted the issue-43 branch September 30, 2024 12:49
scholzj pushed a commit that referenced this pull request Sep 30, 2024
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.

Duplicate metric names when scraping metrics on Kafka clients
4 participants