franz-go
franz-go copied to clipboard
kprom: Support for multiple clients
Hi,
I'm trying to use the kprom plugin with two producers running in the same program to expose separate metrics for each producer. I expected the WithClientLabel
configuration option to allow this, but when I register both producers via the hooks option to the same metric, only the most recent producer gets registered. Here's an example:
metrics := kprom.NewMetrics("test", kprom.WithClientLabel())
// Prepare producers
primary, err := kgo.NewClient(
kgo.SeedBrokers(brokers...),
kgo.ClientID("primary"),
kgo.WithHooks(metrics),
)
...
secondary, err := kgo.NewClient(
kgo.SeedBrokers(brokers...),
kgo.ClientID("secondary"),
kgo.WithHooks(metrics),
)
...
mux := nethttp.NewServeMux()
mux.Handle("/metrics", metrics.Handler())
// Run the actual HTTP server with metrics
...
// Only metrics about secondary client are seen (although I suspect it's sum of both)
However, I believe that supporting separate metrics for multiple consumers/producers within a single program is a valid use case for this plugin, especially since kgo
allows multiple client instances in the same application. I would love to see this use case supported, I can even create a pull request for it if you'll find this issue valid.