diff --git a/implementation/src/main/java/io/smallrye/metrics/MetricsRequestHandler.java b/implementation/src/main/java/io/smallrye/metrics/MetricsRequestHandler.java index 4aff065d..90d1c042 100644 --- a/implementation/src/main/java/io/smallrye/metrics/MetricsRequestHandler.java +++ b/implementation/src/main/java/io/smallrye/metrics/MetricsRequestHandler.java @@ -176,6 +176,12 @@ else if (scope != null && metricName != null) { */ else if (scope == null && metricName != null) { output = exporter.exportOneMetricAcrossScopes(metricName); + + if (output == null || output.isEmpty() || output.length() == 0) { + responder.respondWith(404, "Metric " + metricName + " not found in any scope ", + Collections.emptyMap()); + return; + } } /* * Something went wrong :( diff --git a/implementation/src/main/java/io/smallrye/metrics/exporters/PrometheusMetricsExporter.java b/implementation/src/main/java/io/smallrye/metrics/exporters/PrometheusMetricsExporter.java index d88103ae..fedfdf76 100644 --- a/implementation/src/main/java/io/smallrye/metrics/exporters/PrometheusMetricsExporter.java +++ b/implementation/src/main/java/io/smallrye/metrics/exporters/PrometheusMetricsExporter.java @@ -92,6 +92,12 @@ public String exportOneMetricAcrossScopes(String name) { StringBuilder sb = new StringBuilder(); for (MeterRegistry meterRegistry : prometheusRegistryList) { PrometheusMeterRegistry promMeterRegistry = (PrometheusMeterRegistry) meterRegistry; + + //Skip scrape if meter doesn't contain this metric + if (promMeterRegistry.find(name).meter() == null) { + continue; + } + /* * For each Prometheus registry found: * 1. Calculate potential formatted names