Skip to content

Monitoring Listener Performance with multiple MeterRegistry beans #2148

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

Closed
garyrussell opened this issue Mar 4, 2022 Discussed in #2105 · 0 comments · Fixed by #2151
Closed

Monitoring Listener Performance with multiple MeterRegistry beans #2148

garyrussell opened this issue Mar 4, 2022 Discussed in #2105 · 0 comments · Fixed by #2151

Comments

@garyrussell
Copy link
Contributor

Discussed in #2105

Originally posted by alexanderad February 11, 2022
Hi!

Recently I've been looking for a way to monitor listener specific metrics and found a corresponding section in the docs (Monitoring Listener Performance) saying

... the listener container will automatically create and update Micrometer Timers for the listener, if Micrometer is detected on the class path, and a single MeterRegistry is present in the application context ...

This way of collecting listener metrics is particulary useful given that it is able to account for multiple types of listeners (e.g. declared with @KafkaListener, or @KafkaHandler, or being batch listeners, or hidden behind custom factories for consumers, etc); as well as aware of concurrent listeners, and templates.

The corresponding implementation to be found in:

public MicrometerHolder(@Nullable ApplicationContext context, String name,
String timerName, String timerDesc, Map<String, String> tags) {
if (context == null) {
throw new IllegalStateException("No micrometer registry present");
}
Map<String, MeterRegistry> registries = context.getBeansOfType(MeterRegistry.class, false, false);
this.timerName = timerName;
this.timerDesc = timerDesc;
this.name = name;
this.tags = tags;
if (registries.size() == 1) {
this.registry = registries.values().iterator().next();
buildTimer(NONE_EXCEPTION_METERS_KEY);
}
else {
throw new IllegalStateException("No micrometer registry present (or more than one)");
}
}

The problem I faced is that in case when multiple registries are auto-configured for the application context, e.g. Prometheus + Graphite timers for metrics do not register themselves.This applies to any combination of monitoring systems providing more that one MeterRegistry.class bean visible via context.getBeansOfType(MeterRegistry.class, ...). KafkaMessageListenerContainer silently rejects to collect these metrics, and it seems there is no approachable way to configure alternative behavior, e.g.:

  • prefer a specific registry (say, provided via containerProperties)
  • combine discovered registries into CompositeMeterRegistry

I'm looking for an advice here. Is there anything obvious I'm missing? Is the only one way reasonable in here would be to patch spring-kafka itself to achieve metrics collection for the case of multiple metric registries in use?

Thanks!

@garyrussell garyrussell added this to the 3.0.0-M3 milestone Mar 4, 2022
@garyrussell garyrussell self-assigned this Mar 7, 2022
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Mar 7, 2022
Resolves spring-projects#2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
- use `@Primary` registry bean
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Mar 7, 2022
Resolves spring-projects#2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Mar 7, 2022
Resolves spring-projects#2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean

**cherry-pick to 2.8.x**
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Mar 7, 2022
Resolves spring-projects#2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean

**cherry-pick to 2.8.x**
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue Mar 7, 2022
Resolves spring-projects#2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean

**cherry-pick to 2.8.x**
artembilan pushed a commit that referenced this issue Mar 7, 2022
Resolves #2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean
* Boot's `AutoConfiguredCompositeMeterRegistry` is marked `@Primary`.

**cherry-pick to 2.8.x**
artembilan pushed a commit that referenced this issue Mar 7, 2022
Resolves #2148

- use Boot's `AutoConfiguredCompositeMeterRegistry`, if only one
  (tested with a Boot application)
- use `@Primary` registry bean
* Boot's `AutoConfiguredCompositeMeterRegistry` is marked `@Primary`.

**cherry-pick to 2.8.x**
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue May 18, 2022
artembilan pushed a commit that referenced this issue May 18, 2022
artembilan pushed a commit that referenced this issue May 18, 2022
**cherry-pick to 2.9.x, 2.8.x**

# Conflicts:
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/MicrometerHolderTests.java
artembilan pushed a commit that referenced this issue May 18, 2022
**cherry-pick to 2.9.x, 2.8.x**

# Conflicts:
#	spring-kafka/src/test/java/org/springframework/kafka/support/micrometer/MicrometerHolderTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant