Skip to content

Commit

Permalink
Adds support to provide tags with value in Gauge metric
Browse files Browse the repository at this point in the history
Signed-off-by: Gagan Juneja <[email protected]>
  • Loading branch information
Gagan Juneja committed Jun 5, 2024
1 parent 472af7f commit 4d3f9c8
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObservableMeasurement> value) {
public Closeable createGauge(String name, String description, String unit, Supplier<TaggedMeasurement> value) {
return metricsTelemetry.createGauge(name, description, unit, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObservableMeasurement> value);
Closeable createGauge(String name, String description, String unit, Supplier<TaggedMeasurement> value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ObservableMeasurement> value) {
public Closeable createGauge(String name, String description, String unit, Supplier<TaggedMeasurement> value) {
return () -> {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObservableMeasurement> valueProvider = () -> {
return ObservableMeasurement.create(Double.valueOf(testValue.incrementAndGet()), tags);
Supplier<TaggedMeasurement> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObservableMeasurement> value) {
public Closeable createGauge(String name, String description, String unit, Supplier<TaggedMeasurement> value) {
ObservableDoubleGauge doubleObservableGauge = AccessController.doPrivileged(
(PrivilegedAction<ObservableDoubleGauge>) () -> otelMeter.gaugeBuilder(name)
.setUnit(unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ObservableMeasurement> value) {
public Closeable createGauge(String name, String description, String unit, Supplier<TaggedMeasurement> value) {
return () -> {};
}

Expand Down

0 comments on commit 4d3f9c8

Please sign in to comment.