I'm using Spring Boot Micrometer and it produces metrics like http_server_requests_seconds_bucket
, http_server_requests_seconds_sum
, http_server_requests_seconds_count
, http_server_requests_seconds_max
etc.
I'm using a WebFluxTagsProvider
to add tags to these metrics
@Bean
public WebFluxTagsProvider webFluxTagsProvider() {
return (serverWebExchange, throwable) -> {
HttpHeaders headers = serverWebExchange.getRequest().getHeaders();
return ImmutableList.of(
Tag.of(
"my_tag",
Objects.toString(headers.getFirst("tag_value"), "")));
};
}
The "my_tag" value correctly shows up in all the metrics above.
But the http_server_requests_seconds_bucket
metric is too high cardinality. It's the one metric that doesn't need "my_tag".
How can I add that tag to all metrics except http_server_requests_seconds_bucket
?
EDIT
I tried this solution but it didn't work but maybe I'm doing it wrong
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry ->
registry
.config()
.meterFilter(
MeterFilter.maximumAllowableTags(
"http_server_requests_seconds_bucket",
"my_tag",
0,
MeterFilter.ignoreTags("my_tag")
));
}
I thought I could set the max tags to be 0 and then ignore it on the fly. Doesn't seem to work but probably not optimal even if it did
You are on the right track with the MeterFilter
approach. I'm not certain why the approach you attempted didn't work though. It could be due to the fact that Micrometer meters use dot-notation. The underscores you are using look like the metric is how you see in in Prometheus. You could try "http.server.requests", but then that would impact the _sum
, _count
, and _max
.
You might consider creating a separate meter to control tags independently.
Or if you are using Prometheus, you could use a relabel config to drop the unneeded labels. But that could cause collisions with the other buckets, which Prometheus would drop. I'm not certain in that case.