From 633fde4378905bffb967b30857257427cced4228 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 19 Oct 2018 10:05:26 -0700 Subject: Plugs-in the DerivedLongGauge and DerivedDoubleGauge into the registry (#1505) * Plugs-in the DerivedLongGauge into the registry * Plugs-in the DerivedDoubleGauge into the registry --- .../implcore/metrics/MetricRegistryImpl.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'impl_core/src/main/java/io/opencensus/implcore/metrics') diff --git a/impl_core/src/main/java/io/opencensus/implcore/metrics/MetricRegistryImpl.java b/impl_core/src/main/java/io/opencensus/implcore/metrics/MetricRegistryImpl.java index c606d7e9..1a301ecf 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/metrics/MetricRegistryImpl.java +++ b/impl_core/src/main/java/io/opencensus/implcore/metrics/MetricRegistryImpl.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.opencensus.common.Clock; import io.opencensus.implcore.internal.Utils; +import io.opencensus.metrics.DerivedDoubleGauge; +import io.opencensus.metrics.DerivedLongGauge; import io.opencensus.metrics.DoubleGauge; import io.opencensus.metrics.LabelKey; import io.opencensus.metrics.LongGauge; @@ -73,6 +75,36 @@ public final class MetricRegistryImpl extends MetricRegistry { return doubleGaugeMetric; } + @Override + public DerivedLongGauge addDerivedLongGauge( + String name, String description, String unit, List labelKeys) { + Utils.checkListElementNotNull( + checkNotNull(labelKeys, "labelKeys"), "labelKey element should not be null."); + DerivedLongGaugeImpl derivedLongGauge = + new DerivedLongGaugeImpl( + checkNotNull(name, "name"), + checkNotNull(description, "description"), + checkNotNull(unit, "unit"), + Collections.unmodifiableList(new ArrayList(labelKeys))); + registeredMeters.registerMeter(name, derivedLongGauge); + return derivedLongGauge; + } + + @Override + public DerivedDoubleGauge addDerivedDoubleGauge( + String name, String description, String unit, List labelKeys) { + Utils.checkListElementNotNull( + checkNotNull(labelKeys, "labelKeys"), "labelKey element should not be null."); + DerivedDoubleGaugeImpl derivedDoubleGauge = + new DerivedDoubleGaugeImpl( + checkNotNull(name, "name"), + checkNotNull(description, "description"), + checkNotNull(unit, "unit"), + Collections.unmodifiableList(new ArrayList(labelKeys))); + registeredMeters.registerMeter(name, derivedDoubleGauge); + return derivedDoubleGauge; + } + private static final class RegisteredMeters { private volatile Map registeredMeters = Collections.emptyMap(); -- cgit v1.2.3