Skip to content

Commit

Permalink
Merge pull request quarkusio#42388 from geoand/quarkusio#42355-take2
Browse files Browse the repository at this point in the history
Ensure that all AutoCloseable binders are closed
  • Loading branch information
geoand authored Aug 8, 2024
2 parents e4aa5ae + dde46df commit 9bd1911
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,21 @@ public void configureRegistries(MicrometerConfig config,
}
}

List<AutoCloseable> autoCloseables = new ArrayList<>();

// Base JVM Metrics
if (config.checkBinderEnabledWithDefault(() -> config.binder.jvm)) {
new ClassLoaderMetrics().bindTo(Metrics.globalRegistry);
new JvmHeapPressureMetrics().bindTo(Metrics.globalRegistry);
JvmHeapPressureMetrics jvmHeapPressureMetrics = new JvmHeapPressureMetrics();
jvmHeapPressureMetrics.bindTo(Metrics.globalRegistry);
autoCloseables.add(jvmHeapPressureMetrics);
new JvmMemoryMetrics().bindTo(Metrics.globalRegistry);
new JvmThreadMetrics().bindTo(Metrics.globalRegistry);
new JVMInfoBinder().bindTo(Metrics.globalRegistry);
if (ImageMode.current() == ImageMode.JVM) {
new JvmGcMetrics().bindTo(Metrics.globalRegistry);
JvmGcMetrics jvmGcMetrics = new JvmGcMetrics();
jvmGcMetrics.bindTo(Metrics.globalRegistry);
autoCloseables.add(jvmGcMetrics);
}
}

Expand Down Expand Up @@ -149,6 +155,14 @@ public void run() {
meterRegistry.close();
Metrics.removeRegistry(meterRegistry);
}
// iterate over the auto-closeables and close them
for (AutoCloseable autoCloseable : autoCloseables) {
try {
autoCloseable.close();
} catch (Exception e) {
log.error("Error closing", e);
}
}
}
});
}
Expand Down

0 comments on commit 9bd1911

Please sign in to comment.