Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply workaround for spring-projects/spring-boot#26630
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.izeye.sample.config; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties; | ||
import org.springframework.boot.actuate.metrics.data.MetricsRepositoryMethodInvocationListener; | ||
import org.springframework.boot.actuate.metrics.data.RepositoryTagsProvider; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
|
||
/** | ||
* Configuration for metrics. | ||
* | ||
* @author Johnny Lim | ||
*/ | ||
@Configuration | ||
public class MetricsConfig { | ||
|
||
@Bean | ||
public MeterBinder myMeterBinder() { | ||
return (registry) -> registry.counter("binder.test"); | ||
} | ||
|
||
// FIXME: See https://github.com/spring-projects/spring-boot/issues/26630 | ||
@Bean | ||
public static MetricsRepositoryMethodInvocationListener metricsRepositoryMethodInvocationListener( | ||
MetricsProperties metricsProperties, @Lazy MeterRegistry registry, RepositoryTagsProvider tagsProvider) { | ||
MetricsProperties.Data.Repository properties = metricsProperties.getData().getRepository(); | ||
return new MetricsRepositoryMethodInvocationListener(registry, tagsProvider, properties.getMetricName(), | ||
properties.getAutotime()); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/izeye/sample/config/MetricsConfigTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.izeye.sample.config; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
class MetricsConfigTests { | ||
|
||
@Autowired | ||
private MeterRegistry registry; | ||
|
||
@Test | ||
void userDefinedMeterBinderWorks() { | ||
assertThat(this.registry.find("binder.test").counter()).isNotNull(); | ||
} | ||
|
||
} |