Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a common group tag #130

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

ryanjbaxter
Copy link
Contributor

Fixes #121

This addresses an issue in micrometer where CB with different tags end up not showing up in the metrics.
See micrometer-metrics/micrometer#877

@ryanjbaxter ryanjbaxter linked an issue Feb 7, 2022 that may be closed by this pull request
@ryanjbaxter
Copy link
Contributor Author

@jonatan-ivanov would like your thoughts if you have any knowledge here.

If you think this looks OK, I would probably make this configurable as well as add a property to disable it.

@codecov
Copy link

codecov bot commented Feb 7, 2022

Codecov Report

Merging #130 (14fa251) into 2.1.x (8984e86) will increase coverage by 0.17%.
The diff coverage is 81.25%.

Impacted file tree graph

@@             Coverage Diff              @@
##              2.1.x     #130      +/-   ##
============================================
+ Coverage     77.39%   77.56%   +0.17%     
- Complexity       78       81       +3     
============================================
  Files            13       14       +1     
  Lines           345      361      +16     
  Branches         10       12       +2     
============================================
+ Hits            267      280      +13     
- Misses           74       77       +3     
  Partials          4        4              
Impacted Files Coverage Δ
...ilience4j/Resilience4JConfigurationProperties.java 66.66% <66.66%> (ø)
...er/resilience4j/Resilience4JAutoConfiguration.java 50.00% <100.00%> (+12.96%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8984e86...14fa251. Read the comment docs.


@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags(Resilience4JCircuitBreaker.CIRCUIT_BREAKER_GROUP_TAG, "none");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way the tag will be added for every single meter you have (e.g.: Spring MVC metrics, Kafka metrics, etc). Is it what you want or do you want to only add this tag to Resilience4J-related metrics?

We usually recommend adding fallback tag values at the instrumentation level, e.g.:

Timer timer = Timer.builder("my.timer")
    .tags("group", circuitBreaker.getGroupName() != null ? circuitBreaker.getGroupName() : "none")

Here's a real-life example when we attach the name of the exception as a tag but we set value "none" if there were no exceptions: TimedAspect.java#L216-L227. I guess your use-case is similar.

If you have no control over this, I recommend using a MeterFilter where you can selectively attach the missing tag based on the name and the current tags of the Meter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way the tag will be added for every single meter you have (e.g.: Spring MVC metrics, Kafka metrics, etc). Is it what you want or do you want to only add this tag to Resilience4J-related metrics?

No just resilience4j metrics, is there a better way to do that?

If you have no control over this, I recommend using a MeterFilter where you can selectively attach the missing tag based on the name and the current tags of the Meter.

I think the problem is here https://github.com/resilience4j/resilience4j/blob/master/resilience4j-spring/src/main/java/io/github/resilience4j/bulkhead/configure/threadpool/ThreadPoolBulkheadConfiguration.java#L72-L74
Which we don't have control over. They are not using the tags like we are.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest creating a MeterFilter (boot will auto-config it for you), like this: https://micrometer.io/docs/concepts#_transforming_metrics
So you can check if this is a resilience4j-related meter and the group tag is missing, add it with a default value.

Use MeterFilter instead of MeterRegistryCustomizer
@ryanjbaxter ryanjbaxter merged commit a0f2f02 into spring-cloud:2.1.x Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resilience4J bulkhead metrics missing at /actutor/prometheus
3 participants