From af145969639721b1cda559e34a15f882668f62f6 Mon Sep 17 00:00:00 2001 From: Gagan Juneja Date: Wed, 5 Jun 2024 19:23:12 +0530 Subject: [PATCH] Adds support to provide tags with value in Gauge metric Signed-off-by: Gagan Juneja --- .../telemetry/metrics/DefaultMetricsRegistry.java | 2 +- .../telemetry/metrics/MetricsRegistry.java | 2 +- ...rvableMeasurement.java => TaggedMeasurement.java} | 12 ++++++------ .../telemetry/metrics/noop/NoopMetricsRegistry.java | 4 ++-- .../metrics/DefaultMetricsRegistryTests.java | 2 +- .../metrics/TelemetryMetricsEnabledSanityIT.java | 4 ++-- .../telemetry/metrics/OTelMetricsTelemetry.java | 2 +- .../telemetry/metrics/OTelMetricsTelemetryTests.java | 2 +- .../org/opensearch/test/telemetry/MockTelemetry.java | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) rename libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/{ObservableMeasurement.java => TaggedMeasurement.java} (73%) diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistry.java index c41529f038958..bcf5c163cb91f 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistry.java @@ -49,7 +49,7 @@ public Closeable createGauge(String name, String description, String unit, Suppl } @Override - public Closeable createGauge(String name, String description, String unit, Supplier value) { + public Closeable createGauge(String name, String description, String unit, Supplier value) { return metricsTelemetry.createGauge(name, description, unit, value); } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsRegistry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsRegistry.java index fd9c0f32cb835..3dc212b1341cc 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsRegistry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsRegistry.java @@ -73,6 +73,6 @@ public interface MetricsRegistry extends Closeable { * @param value value provider. * @return closeable to dispose/close the Gauge metric. */ - Closeable createGauge(String name, String description, String unit, Supplier value); + Closeable createGauge(String name, String description, String unit, Supplier value); } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/ObservableMeasurement.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/TaggedMeasurement.java similarity index 73% rename from libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/ObservableMeasurement.java rename to libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/TaggedMeasurement.java index 7225feeffdc50..a6ae3f5485813 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/ObservableMeasurement.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/TaggedMeasurement.java @@ -16,21 +16,21 @@ * @opensearch.experimental */ @ExperimentalApi -public class ObservableMeasurement { +public class TaggedMeasurement { private final Double value; private final Tags tags; /** - * Factory method to create the {@link ObservableMeasurement} object. + * Factory method to create the {@link TaggedMeasurement} object. * @param value value. * @param tags tags to be added per value. - * @return ObservableMeasurement + * @return tagged measurement TaggedMeasurement */ - public static ObservableMeasurement create(double value, Tags tags) { - return new ObservableMeasurement(value, tags); + public static TaggedMeasurement create(double value, Tags tags) { + return new TaggedMeasurement(value, tags); } - private ObservableMeasurement(double value, Tags tags) { + private TaggedMeasurement(double value, Tags tags) { this.value = value; this.tags = tags; } diff --git a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopMetricsRegistry.java b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopMetricsRegistry.java index 493c30791827f..7bec136c42ba7 100644 --- a/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopMetricsRegistry.java +++ b/libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopMetricsRegistry.java @@ -12,7 +12,7 @@ import org.opensearch.telemetry.metrics.Counter; import org.opensearch.telemetry.metrics.Histogram; import org.opensearch.telemetry.metrics.MetricsRegistry; -import org.opensearch.telemetry.metrics.ObservableMeasurement; +import org.opensearch.telemetry.metrics.TaggedMeasurement; import org.opensearch.telemetry.metrics.tags.Tags; import java.io.Closeable; @@ -54,7 +54,7 @@ public Closeable createGauge(String name, String description, String unit, Suppl } @Override - public Closeable createGauge(String name, String description, String unit, Supplier value) { + public Closeable createGauge(String name, String description, String unit, Supplier value) { return () -> {}; } diff --git a/libs/telemetry/src/test/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistryTests.java b/libs/telemetry/src/test/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistryTests.java index 2c6910f66cd69..0873c7c502148 100644 --- a/libs/telemetry/src/test/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistryTests.java +++ b/libs/telemetry/src/test/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistryTests.java @@ -88,7 +88,7 @@ public void testGaugeWithValueAndTagSupplier() { "org.opensearch.telemetry.metrics.DefaultMeterRegistryTests.testObservableGauge", "test observable gauge", "ms", - () -> ObservableMeasurement.create(1.0, Tags.EMPTY) + () -> TaggedMeasurement.create(1.0, Tags.EMPTY) ); assertSame(mockCloseable, closeable); } diff --git a/plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsEnabledSanityIT.java b/plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsEnabledSanityIT.java index 51c18313e4e60..b0582624e21d5 100644 --- a/plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsEnabledSanityIT.java +++ b/plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsEnabledSanityIT.java @@ -156,8 +156,8 @@ public void testGaugeWithValueAndTagSupplier() throws Exception { InMemorySingletonMetricsExporter.INSTANCE.reset(); Tags tags = Tags.create().addTag("test", "integ-test"); final AtomicInteger testValue = new AtomicInteger(0); - Supplier valueProvider = () -> { - return ObservableMeasurement.create(Double.valueOf(testValue.incrementAndGet()), tags); + Supplier valueProvider = () -> { + return TaggedMeasurement.create(Double.valueOf(testValue.incrementAndGet()), tags); }; Closeable gaugeCloseable = metricsRegistry.createGauge(metricName, "test", "ms", valueProvider); // Sleep for about 2.2s to wait for metrics to be published. diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetry.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetry.java index 98e8aea88eac6..3258e91738ba6 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetry.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetry.java @@ -102,7 +102,7 @@ public Closeable createGauge(String name, String description, String unit, Suppl } @Override - public Closeable createGauge(String name, String description, String unit, Supplier value) { + public Closeable createGauge(String name, String description, String unit, Supplier value) { ObservableDoubleGauge doubleObservableGauge = AccessController.doPrivileged( (PrivilegedAction) () -> otelMeter.gaugeBuilder(name) .setUnit(unit) diff --git a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetryTests.java b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetryTests.java index df92124c0bddc..16f647518828c 100644 --- a/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetryTests.java +++ b/plugins/telemetry-otel/src/test/java/org/opensearch/telemetry/metrics/OTelMetricsTelemetryTests.java @@ -204,7 +204,7 @@ public void testGaugeWithValueAndTagsSupplier() throws Exception { observableGaugeName, description, unit, - () -> ObservableMeasurement.create(1.0, Tags.EMPTY) + () -> TaggedMeasurement.create(1.0, Tags.EMPTY) ); closeable.close(); verify(observableDoubleGauge).close(); diff --git a/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java b/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java index a5fe8d1f0511a..e9d8ddd06fcba 100644 --- a/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java +++ b/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java @@ -13,7 +13,7 @@ import org.opensearch.telemetry.metrics.Counter; import org.opensearch.telemetry.metrics.Histogram; import org.opensearch.telemetry.metrics.MetricsTelemetry; -import org.opensearch.telemetry.metrics.ObservableMeasurement; +import org.opensearch.telemetry.metrics.TaggedMeasurement; import org.opensearch.telemetry.metrics.noop.NoopCounter; import org.opensearch.telemetry.metrics.noop.NoopHistogram; import org.opensearch.telemetry.metrics.tags.Tags; @@ -64,7 +64,7 @@ public Closeable createGauge(String name, String description, String unit, Suppl } @Override - public Closeable createGauge(String name, String description, String unit, Supplier value) { + public Closeable createGauge(String name, String description, String unit, Supplier value) { return () -> {}; }