quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.88k stars 2.71k forks source link

Add ability to configure common tags in the Micrometer extension via configuration properties. #23386

Open rdifrango opened 2 years ago

rdifrango commented 2 years ago

Description

I would like the ability to add ability to configure common tags in the Micrometer extension via configuration properties.

Implementation ideas

the proposal would be to add a property with a name like quarkus.micrometer.tags that is a collection of Key/Value pairs that then get added to the registry something like:

registry.config().commonTags(Arrays.asList(Tag.of("stack", "prod"), Tag.of("region", "us-east-1")));
quarkus-bot[bot] commented 2 years ago

/cc @ebullient

ebullient commented 2 years ago

I've refrained from doing this via configuration for a number of reasons. You can define a Producer of MeterFilter that will add common tags as you wish, including reading from configuration attributes or being selectively enabled based on profile, etc.

https://quarkus.io/guides/micrometer#using-meterfilter-to-configure-metrics

rdifrango commented 2 years ago

For me, this is a departure from what I get with Spring Boot as I can configure tags via configuration.

I'd be curious to know what those reasons are?

ebullient commented 2 years ago

Spring Boot describes (in getting started), how to configure common tags using a MeterFilter: https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html#actuator.metrics.getting-started

While Spring Boot Actuator does have a configuration shortcut for common tags (https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/actuator.html#actuator.metrics.customizing.common-tags), it comes with a warning that suggests you use MeterFilter with some registry configurations because the order can't be guaranteed when reading from the config file.

I also wanted to ensure people are aware of MeterFilters and how they work, as that's how you suppress emission of metrics that you don't need (which is a common path for Kafka, e.g.).

I didn't feel the trade-off for the config option was worth it, given how much more control you have by defining a MeterFilter.

rdifrango commented 2 years ago

As I read the Boot page, that only applies to Graphite:

The order of common tags is important if you are using Graphite. As the order of common tags cannot be guaranteed using this approach, Graphite users are advised to define a custom MeterFilter instead.

While I agree the MeterFilter is more powerful, if all you need to do is simply add tags it's a bit of overkill. Also, if you working on an enterprise and want a consistent set of tags it would then require a shared component to enforce it. Whereas with config it's much easier to check and/or configure.

davide-romanini-milkman commented 1 month ago

I stumbled upon this (old) issue. I'm trying to follow this documentation. The config [quarkus.micrometer.export.prometheus."configuration-property-name"](https://quarkus.io/guides/telemetry-micrometer#quarkus-micrometer_quarkus-micrometer-export-prometheus-configuration-property-name) should be able to set commonTags in some way, but seems not to work. What I'm trying to achieve is to add an application tag so I can use the grafana JVM (Micrometer) dashboard as documented in the linked micrometer page here. I'm trying various combinations of the env var QUARKUS_MICROMETER_EXPORT_PROMETHEUS__CONFIGURATION_PROPERTY_NAME__CONFIG_COMMONTAGS_application without any success. Could you please give some clue to know if it is at least possible at all?