Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've packed quite a few changes in this PR.
First let's cover the form. I moved a bunch of classes under a new package
collector
as we were starting to have many classes in the top level package. That way all logic about collecting metrics is regrouped and we only have the 2 reporter implementations and the config in the top level package.Now I'll try to explain the logic. The main issue is that only
MetricsReporter
(used for Kafka metrics) is reconfigurable.KafkaMetricsReporter
(used for Yammer metrics) is not reconfigurable. Internally Kafka has some custom logic to make the JMX implementation ofKafkaMetricsReporter
reconfigurable but we can't do that. To work around this issue, the logic relies onPrometheusCollector
which is a singleton and holds references to both reporter implementations.So when a user triggers a reconfiguration with the Admin API,
KafkaPrometheusMetricsReporter.reconfigure()
is invoked with the new configuration values. We build a newPrometheusMetricsReporterConfig
instance just to parse the allowlist and pass the allowlist to thePrometheusCollector
instance which in turns passes it toKafkaCollector
andYammerCollector
. Now that the allowlist is in the collector classes I moved the filtering logic there too (it used to be inKafkaPrometheusMetricsReporter
andYammerPrometheusMetricsReporter
).Another complication is the need to handle cases when the scope of the allowlist is increased. For that reason, we need to keep track of all existing metrics (the
otherMetrics
field inMetricsCollector
), so if the user decides to collect more metrics we can retrieve them. I don't think there's an alternative to this and this is actually whatJmxReporter
in Kafka does too (https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java).Since both
KafkaCollector
andYammerCollector
have to keep track of all metrics and do the same filtering logic, I moved that intoMetricsCollector
and change it from a interface to an abstract class.Moving the logic into the collectors causes a significant change in behavior when you run multiple instances of the reporter in the same JVM, for example in Kafka Connect, Kafka Streams, or a Kafka application that starts multiple clients. In this case
KafkaCollector
being a singleton shared by all instances, the allowlist is now global to all clients. So if a user configures different allowlists, the last client starting will overwrite the previous allowlist. For Kafka Streams and Kafka Connect, users should set the allowlist simply usingprometheus.metrics.reporter.allowlist
and not set it per client using theproducer.
,consumer.
oradmin.
prefixes. In other applications when starting multiple clients they should all have the same allowlist.So for example with the following configuration should be avoided:
Using it, you only get
kafka_consumer_consumer
metrics.One thing I'm considering is making
PrometheusMetricsReporterConfig
a singleton. That way we would recommend setting all metrics-reporter configurations at the top level (without any prefix). We would lose the ability to assign different port to different client but I don't think that's a very useful "feature", it's probably best in most cases to expose a single endpoint.Finally, note that the reconfiguration feature is only supported on brokers, that's not a limitation of the metrics-reporter, it's just the way it works in Apache Kafka.