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
3 changed files
with
59 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,39 @@ | ||
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 | ||
class MetricsConfig { | ||
@Bean | ||
fun myMeterBinder(): MeterBinder { | ||
return MeterBinder { registry: MeterRegistry -> registry.counter("binder.test") } | ||
} | ||
|
||
companion object { | ||
// FIXME: See https://github.com/spring-projects/spring-boot/issues/26630 | ||
@Bean | ||
fun metricsRepositoryMethodInvocationListener( | ||
metricsProperties: MetricsProperties, | ||
@Lazy registry: MeterRegistry, | ||
tagsProvider: RepositoryTagsProvider | ||
): MetricsRepositoryMethodInvocationListener { | ||
val properties = metricsProperties.data.repository | ||
return MetricsRepositoryMethodInvocationListener( | ||
registry, tagsProvider, properties.metricName, | ||
properties.autotime | ||
) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/kotlin/com/izeye/sample/config/MetricsConfigTests.kt
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,19 @@ | ||
package com.izeye.sample.config | ||
|
||
import io.micrometer.core.instrument.MeterRegistry | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
/** | ||
* Tests for [MetricsConfig]. | ||
* | ||
* @author Johnny Lim | ||
*/ | ||
@SpringBootTest | ||
class MetricsConfigTests(val registry: MeterRegistry) { | ||
@Test | ||
fun userDefinedMeterBinderWorks() { | ||
Assertions.assertThat(registry.find("binder.test").counter()).isNotNull | ||
} | ||
} |
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 @@ | ||
spring.test.constructor.autowire.mode=all |