...
I propose introducing a new interface: Monitorable
. If a plugin implements this interface, the withPluginMetrics()
method will be called when the plugin is instantiated (after configure()
if the plugin also implements Configurable
). This will allow the plugin plugins to adds its their own metrics to the component (producer, consumer, etc) that instantiated itthem.
Code Block | ||||
---|---|---|---|---|
| ||||
package org.apache.kafka.common.metrics; public interface Monitorable { /** * Get the PluginMetrics instance from the client that instantiates the plugin. */ void withPluginMetrics(PluginMetrics metrics); } |
...
When instantiating a class via the Utils.newInstance()
helper methods, if it implements Monitorable
and a Metrics
object is available, a new PluginMetrics instance will be created and passed to the withPluginMetrics()
method. It will be always called after configure()
. Metrics registered by plugins will inherit the prefix/namespace from the current Metrics
instance, these are: kafka.producer, kafka.consumer, kafka.connect, kafka.streams and kafka.server. Metrics reporters should not implement the Monitorable interface as they are created before the Metrics instance.
The goal is for all plugins, apart from MetricsReporter and KafkaMetricsReporter, to support this feature.
Example usage
For example if we create a custom ProducerInterceptor
...