-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
* [Metric Framework] Adds support for Histogram metric Signed-off-by: Gagan Juneja <[email protected]> * Adds test Signed-off-by: Gagan Juneja <[email protected]> * Addresses review comments Signed-off-by: Gagan Juneja <[email protected]> * Adds change log Signed-off-by: Gagan Juneja <[email protected]> * Fixed spotless Signed-off-by: Gagan Juneja <[email protected]> * Fixes javadoc Signed-off-by: Gagan Juneja <[email protected]> * Fixes javadoc Signed-off-by: Gagan Juneja <[email protected]> * Fixes test Signed-off-by: Gagan Juneja <[email protected]> * Removes explicit approach Signed-off-by: Gagan Juneja <[email protected]> * Removes explicit approach Signed-off-by: Gagan Juneja <[email protected]> * Addresses review comments Signed-off-by: Gagan Juneja <[email protected]> --------- Signed-off-by: Gagan Juneja <[email protected]> Co-authored-by: Gagan Juneja <[email protected]> (cherry picked from commit a4bc4af) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.metrics; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
/** | ||
* Histogram records the value for an existing metric. | ||
* {@opensearch.experimental} | ||
*/ | ||
@ExperimentalApi | ||
public interface Histogram { | ||
|
||
/** | ||
* record value. | ||
* @param value value to be added. | ||
*/ | ||
void record(double value); | ||
|
||
/** | ||
* record value along with the attributes. | ||
* | ||
* @param value value to be added. | ||
* @param tags attributes/dimensions of the metric. | ||
*/ | ||
void record(double value, Tags tags); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.metrics.noop; | ||
|
||
import org.opensearch.common.annotation.InternalApi; | ||
import org.opensearch.telemetry.metrics.Histogram; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
/** | ||
* No-op {@link Histogram} | ||
* {@opensearch.internal} | ||
*/ | ||
@InternalApi | ||
public class NoopHistogram implements Histogram { | ||
|
||
/** | ||
* No-op Histogram instance | ||
*/ | ||
public final static NoopHistogram INSTANCE = new NoopHistogram(); | ||
Check warning on line 25 in libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java Codecov / codecov/patchlibs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java#L25
|
||
|
||
private NoopHistogram() {} | ||
|
||
@Override | ||
public void record(double value) { | ||
|
||
} | ||
Check warning on line 32 in libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java Codecov / codecov/patchlibs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java#L32
|
||
|
||
@Override | ||
public void record(double value, Tags tags) { | ||
|
||
} | ||
Check warning on line 37 in libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java Codecov / codecov/patchlibs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java#L37
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.metrics; | ||
|
||
import org.opensearch.telemetry.OTelAttributesConverter; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
import io.opentelemetry.api.metrics.DoubleHistogram; | ||
|
||
/** | ||
* OTel aware implementation {@link Histogram} | ||
*/ | ||
class OTelHistogram implements Histogram { | ||
|
||
private final DoubleHistogram otelDoubleHistogram; | ||
|
||
/** | ||
* Constructor | ||
* @param otelDoubleCounter delegate counter. | ||
*/ | ||
public OTelHistogram(DoubleHistogram otelDoubleCounter) { | ||
this.otelDoubleHistogram = otelDoubleCounter; | ||
} | ||
|
||
@Override | ||
public void record(double value) { | ||
otelDoubleHistogram.record(value); | ||
} | ||
|
||
@Override | ||
public void record(double value, Tags tags) { | ||
otelDoubleHistogram.record(value, OTelAttributesConverter.convert(tags)); | ||
} | ||
} |