Jakub Holý
Jakub Holý

Reputation: 6195

Spring Boot doesn't pick up Micrometer Registry from the classpath (cloudwatch)

I use Spring Boot 1.5 with micrometer-spring-legacy:1.1.4 and micrometer-registry-cloudwatch:1.1.4 on the classpath. According to the docs it should pick up this registry automatically:

Having a dependency on micrometer-registry-{system} in your runtime classpath is enough for Spring Boot to configure the registry.

However when I look at the registered Spring beans when the app starts, there is only "simpleMeterRegistry" (which I assume is the default).

Why does it not pick up the CloudWatchMeterRegistry? How to troubleshoot? thank you!!!

From the log:

Condition CompositeMeterRegistryConfiguration.MultipleNonPrimaryMeterRegistriesCondition on io.micrometer.spring.autoconfigure.CompositeMeterRegistryConfiguration did not match due to NoneNestedConditions 1 matched 1 did not; NestedCondition on CompositeMeterRegistryConfiguration.MultipleNonPrimaryMeterRegistriesCondition.SingleInjectableMeterRegistry @ConditionalOnSingleCandidate (types: io.micrometer.core.instrument.MeterRegistry; SearchStrategy: all) found a primary bean from beans 'simpleMeterRegistry'; NestedCondition on CompositeMeterRegistryConfiguration.MultipleNonPrimaryMeterRegistriesCondition.NoMeterRegistryCondition @ConditionalOnMissingBean (types: io.micrometer.core.instrument.MeterRegistry; SearchStrategy: all) found bean 'simpleMeterRegistry'

Condition DataSourcePoolMetricsAutoConfiguration.DataSourcePoolMetricsConditionalOnBeans on io.micrometer.spring.autoconfigure.jdbc.DataSourcePoolMetricsAutoConfiguration matched due to AllNestedConditions 2 matched 0 did not; NestedCondition on DataSourcePoolMetricsAutoConfiguration.DataSourcePoolMetricsConditionalOnBeans.ConditionalOnMeterRegistryBean @ConditionalOnBean (types: io.micrometer.core.instrument.MeterRegistry; SearchStrategy: all) found bean 'simpleMeterRegistry'; NestedCondition on DataSourcePoolMetricsAutoConfiguration.DataSourcePoolMetricsConditionalOnBeans.ConditionalOnDataSourceBean @ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found bean 'dataSource'

Filter 'webMetricsFilter' configured successfully

Update

I see there is CloudWatchMetricAutoConfiguration and I would expect it to produce a CloudWatchMetricWriter Bean but there is no such bean. It should also create a AmazonCloudWatchAsync bean but it doesn't - the only "amazon" bean we have is amazonS3.

Likely cause

I have discovered that micrometer-spring-legacy:1.1.4 has the package io.micrometer.spring.autoconfigure.export.<system> with <system>MetricsExportAutoConfiguration, <system>Properties, <system>PropertiesConfigAdapter for every supported system - but not CloudWatch. These classes make the *Registry available as a Spring bean and since there is no support for the cloudwatch registry, it is not available as a spring bean.

Upvotes: 3

Views: 4958

Answers (2)

Shivansh Jagga
Shivansh Jagga

Reputation: 1861

The problem with me was that I was using micrometer-registry-cloudwatch2, which wasn't compatible with my SpringBoot. So I used micrometer-registry-cloudwatch and everything worked.

Upvotes: 0

Jakub Hol&#253;
Jakub Hol&#253;

Reputation: 6195

So the problem was that I lacked micrometer-spring integration for CloudWatch, which is not included in micrometer-spring-legacy because of its dependencies. Instead, it lives in the Spring Cloud AWS repo, namely in the package org.springframework.cloud.aws.autoconfigure.metrics of the spring-cloud-aws-autoconfigure library.

See spring-projects/spring-boot#11276 for background.

However spring-cloud-aws-autoconfigure 2 expects Boot 2.x, the latest made for Boot 1.5 is 1.2.3 which lacks the CloudWatch metrics integration. The only option is thus to copy, paste, adjust its CloudWatchMetricsExportAutoConfiguration.

Upvotes: 2

Related Questions