From e17fa16f282f95678dc80c85cb8855e677cfe674 Mon Sep 17 00:00:00 2001 From: Wojciech Baszczyk Date: Fri, 4 Oct 2024 08:44:37 +0200 Subject: [PATCH] fix(metrics): hold strong reference to probes results in micrometer gauge --- .../io/gravitee/node/monitoring/DefaultProbeEvaluator.java | 4 ++++ .../micrometer/NodeHealthCheckMicrometerHandler.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/DefaultProbeEvaluator.java b/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/DefaultProbeEvaluator.java index d0b34c1c9..ef0862812 100644 --- a/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/DefaultProbeEvaluator.java +++ b/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/DefaultProbeEvaluator.java @@ -72,4 +72,8 @@ public CompletableFuture> evaluate(final Set probeIds } }); } + + public Map getCachedResults() { + return lastProbeResults; + } } diff --git a/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/healthcheck/micrometer/NodeHealthCheckMicrometerHandler.java b/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/healthcheck/micrometer/NodeHealthCheckMicrometerHandler.java index 33188e297..283ad7123 100644 --- a/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/healthcheck/micrometer/NodeHealthCheckMicrometerHandler.java +++ b/gravitee-node-monitoring/src/main/java/io/gravitee/node/monitoring/healthcheck/micrometer/NodeHealthCheckMicrometerHandler.java @@ -41,7 +41,7 @@ public void bindTo(@NonNull MeterRegistry registry) { try { for (Map.Entry entry : probeRegistry.evaluate().get().entrySet()) { Gauge - .builder("node", entry, e -> e.getValue().isHealthy() ? 1d : 0d) + .builder("node", probeRegistry, e -> e.getCachedResults().get(entry.getKey()).isHealthy() ? 1d : 0d) .tag("probe", entry.getKey().id()) .description("The health-check probes of the node") .baseUnit("health")