Skip to content

Commit

Permalink
Check if Metrics are enabled prior to getting the MeterRegistry bean (#…
Browse files Browse the repository at this point in the history
…890)

* Check if Metrics are enabled prior to getting the MeterRegistry bean

We had an issue of a circular loop when trying to load a DataSource by name from the BeanContext.

Disabling the metrics made no difference, as the Bean was retrieved prior to checking if it was enabled.

This change checks that metrics are enabled prior to attempting to get the metrics bean.

* Update shared settings

* Update shared settings properly 🙄
  • Loading branch information
timyates authored May 19, 2023
1 parent fae184c commit 540ee28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public DataSource dataSource(DatasourceConfiguration datasourceConfiguration) {

private void addMeterRegistry(HikariUrlDataSource ds) {
try {
MeterRegistry meterRegistry = getMeterRegistry();
if (ds != null && meterRegistry != null &&
this.applicationContext
.getProperty(MICRONAUT_METRICS_BINDERS + ".jdbc.enabled",
boolean.class).orElse(true)) {
ds.setMetricRegistry(meterRegistry);
Boolean metricsEnabled = this.applicationContext.getProperty(MICRONAUT_METRICS_BINDERS + ".jdbc.enabled", boolean.class).orElse(true);
if (ds != null && metricsEnabled) {
MeterRegistry meterRegistry = getMeterRegistry();
if (meterRegistry != null) {
ds.setMetricRegistry(meterRegistry);
}
}
} catch (NoClassDefFoundError ignore) {
LOG.debug("Could not wire metrics to HikariCP as there is no class of type MeterRegistry on the classpath, io.micronaut.configuration:micrometer-core library missing.");
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
id 'io.micronaut.build.shared.settings' version '5.4.6'
id 'io.micronaut.build.shared.settings' version '5.4.9'
}
repositories {
gradlePluginPortal()
Expand Down

0 comments on commit 540ee28

Please sign in to comment.