From 0bcaedc57471a22845f452d56d52c1096dab6a2a Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Fri, 19 Nov 2021 15:11:23 -0600 Subject: [PATCH] Need to support no-op Gauge after all --- .../src/main/java/io/helidon/metrics/api/NoOpMetricImpl.java | 5 +++++ .../main/java/io/helidon/metrics/api/NoOpMetricRegistry.java | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricImpl.java b/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricImpl.java index f3858e0f94c..e3fd291a6ba 100644 --- a/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricImpl.java +++ b/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricImpl.java @@ -112,6 +112,11 @@ static class NoOpGaugeImpl extends NoOpMetricImpl implem return new NoOpGaugeImpl<>(registryType, metadata, metric); } + static NoOpGaugeImpl create(String registryType, Metadata metadata) { + // TODO uncomment above once MP metrics enforces the Number restriction + return new NoOpGaugeImpl<>(registryType, metadata, () -> null); + } + private NoOpGaugeImpl(String registryType, Metadata metadata, Gauge metric) { super(registryType, metadata); value = metric::getValue; diff --git a/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricRegistry.java b/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricRegistry.java index f146b01d897..9f20e33f4ed 100644 --- a/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricRegistry.java +++ b/metrics/api/src/main/java/io/helidon/metrics/api/NoOpMetricRegistry.java @@ -30,9 +30,8 @@ class NoOpMetricRegistry extends AbstractRegistry { private static final Map> NO_OP_METRIC_FACTORIES = - // Omit gauge because creating a gauge requires an existing delegate instance. - // These factory methods do not use delegates. Map.of(MetricType.COUNTER, NoOpMetricImpl.NoOpCounterImpl::create, + MetricType.GAUGE, NoOpMetricImpl.NoOpGaugeImpl::create, MetricType.HISTOGRAM, NoOpMetricImpl.NoOpHistogramImpl::create, MetricType.METERED, NoOpMetricImpl.NoOpMeterImpl::create, MetricType.TIMER, NoOpMetricImpl.NoOpTimerImpl::create,