forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metric Framework] Adds support for Histogram metric
Signed-off-by: Gagan Juneja <[email protected]>
- Loading branch information
Gagan Juneja
committed
Jan 29, 2024
1 parent
1ec5305
commit d5239fe
Showing
14 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/Histogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/HistogramType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Histogram type, primarily depends on bucketing strategy. | ||
*/ | ||
public enum HistogramType { | ||
/** | ||
* Fixed buckets. | ||
*/ | ||
FIXED_BUCKET, | ||
/** | ||
* Buckets will be defined dynamically based on the value distribution. | ||
*/ | ||
DYNAMIC; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopHistogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
private NoopHistogram() {} | ||
|
||
@Override | ||
public void record(double value) { | ||
|
||
} | ||
|
||
@Override | ||
public void record(double value, Tags tags) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/metrics/OTelHistogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters