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

The spring-integration actuator endpoint doesn't work when multiple MeterRegistry beans are registered #9335

Closed
trask opened this issue Jul 14, 2024 · 2 comments

Comments

@trask
Copy link

trask commented Jul 14, 2024

Expected Behavior

The spring-integration actuator endpoint should still work when multiple MeterRegistry beans have been registered (which is a use case that the regular spring metrics actuator endpoint supports).

Current Behavior

The spring-integration actuator endpoint doesn't work when multiple MeterMeterRegistry beans have been regsitered, see

Map<String, MeterRegistry> registries = applicationContext.getBeansOfType(MeterRegistry.class, false, false);
if (registries.size() == 1) {
this.registry = registries.values().iterator().next();
}
else {
this.registry = null;
}

Context

The regular spring metrics actuator endpoint supports multiple MeterRegistry beans, and it would be great if the spring-integration actuator endpoint had similar support, see

I have not found any workaround to make the spring-integration actuator endpoint work when multiple MeterRegistry beans have been registered.

@trask trask added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels Jul 14, 2024
@artembilan
Copy link
Member

I think we can fix it similar way we do in the MicrometerMetricsCaptor:

this.meterRegistry = this.meterRegistryProvider.getIfUnique();

Which is based on this decision:

	/**
	 * Return an instance (possibly shared or independent) of the object
	 * managed by this factory.
	 * @return an instance of the bean, or {@code null} if not available or
	 * not unique (i.e. multiple candidates found with none marked as primary)
	 * @throws BeansException in case of creation errors
	 * @see #getObject()
	 */
	@Nullable
	default T getIfUnique() throws BeansException {

This way MicrometerNodeEnhancer would rely on the mentioned AutoConfiguredCompositeMeterRegistry which is marked as @Primary.

@artembilan artembilan added this to the 6.4.0-M1 milestone Jul 15, 2024
@artembilan artembilan self-assigned this Jul 16, 2024
spring-builds pushed a commit that referenced this issue Jul 16, 2024
… bean

Fixes: #9335

Spring Boot provides a `CompositeMeterRegistry` bean marked with a `@Primary`.
So, this one has to be autowired whenever we would like to deal with application
environment.
The `MicrometerNodeEnhancer` has a flaw to skip `MeterRegistry` injection if we have more than one `MeterRegistry` bean.

* Fix `MicrometerNodeEnhancer` logic to use `ObjectProvider.getIfUnique()` API
which is able to deal with the `primary` properly.
Otherwise, `null` as it was before

(cherry picked from commit e0472d8)
spring-builds pushed a commit that referenced this issue Jul 16, 2024
… bean

Fixes: #9335

Spring Boot provides a `CompositeMeterRegistry` bean marked with a `@Primary`.
So, this one has to be autowired whenever we would like to deal with application
environment.
The `MicrometerNodeEnhancer` has a flaw to skip `MeterRegistry` injection if we have more than one `MeterRegistry` bean.

* Fix `MicrometerNodeEnhancer` logic to use `ObjectProvider.getIfUnique()` API
which is able to deal with the `primary` properly.
Otherwise, `null` as it was before

(cherry picked from commit e0472d8)
@trask
Copy link
Author

trask commented Jul 16, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants