Skip to content

Commit 9bd1911

Browse files
authored
Merge pull request #42388 from geoand/#42355-take2
Ensure that all AutoCloseable binders are closed
2 parents e4aa5ae + dde46df commit 9bd1911

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerRecorder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,21 @@ public void configureRegistries(MicrometerConfig config,
107107
}
108108
}
109109

110+
List<AutoCloseable> autoCloseables = new ArrayList<>();
111+
110112
// Base JVM Metrics
111113
if (config.checkBinderEnabledWithDefault(() -> config.binder.jvm)) {
112114
new ClassLoaderMetrics().bindTo(Metrics.globalRegistry);
113-
new JvmHeapPressureMetrics().bindTo(Metrics.globalRegistry);
115+
JvmHeapPressureMetrics jvmHeapPressureMetrics = new JvmHeapPressureMetrics();
116+
jvmHeapPressureMetrics.bindTo(Metrics.globalRegistry);
117+
autoCloseables.add(jvmHeapPressureMetrics);
114118
new JvmMemoryMetrics().bindTo(Metrics.globalRegistry);
115119
new JvmThreadMetrics().bindTo(Metrics.globalRegistry);
116120
new JVMInfoBinder().bindTo(Metrics.globalRegistry);
117121
if (ImageMode.current() == ImageMode.JVM) {
118-
new JvmGcMetrics().bindTo(Metrics.globalRegistry);
122+
JvmGcMetrics jvmGcMetrics = new JvmGcMetrics();
123+
jvmGcMetrics.bindTo(Metrics.globalRegistry);
124+
autoCloseables.add(jvmGcMetrics);
119125
}
120126
}
121127

@@ -149,6 +155,14 @@ public void run() {
149155
meterRegistry.close();
150156
Metrics.removeRegistry(meterRegistry);
151157
}
158+
// iterate over the auto-closeables and close them
159+
for (AutoCloseable autoCloseable : autoCloseables) {
160+
try {
161+
autoCloseable.close();
162+
} catch (Exception e) {
163+
log.error("Error closing", e);
164+
}
165+
}
152166
}
153167
});
154168
}

0 commit comments

Comments
 (0)