-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Telemetry metrics framework (#10241)
Signed-off-by: Gagan Juneja <gjjuneja@amazon.com>
- Loading branch information
1 parent
3dd9fc1
commit 211578c
Showing
42 changed files
with
1,489 additions
and
79 deletions.
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/Counter.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; | ||
|
||
/** | ||
* Counter adds the value to the existing metric. | ||
* {@opensearch.experimental} | ||
*/ | ||
@ExperimentalApi | ||
public interface Counter { | ||
|
||
/** | ||
* add value. | ||
* @param value value to be added. | ||
*/ | ||
void add(double value); | ||
|
||
/** | ||
* add value along with the attributes. | ||
* | ||
* @param value value to be added. | ||
* @param tags attributes/dimensions of the metric. | ||
*/ | ||
void add(double value, Tags tags); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistry.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,41 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
|
||
/** | ||
* Default implementation for {@link MetricsRegistry} | ||
*/ | ||
class DefaultMetricsRegistry implements MetricsRegistry { | ||
private final MetricsTelemetry metricsTelemetry; | ||
|
||
/** | ||
* Constructor | ||
* @param metricsTelemetry metrics telemetry. | ||
*/ | ||
public DefaultMetricsRegistry(MetricsTelemetry metricsTelemetry) { | ||
this.metricsTelemetry = metricsTelemetry; | ||
} | ||
|
||
@Override | ||
public Counter createCounter(String name, String description, String unit) { | ||
return metricsTelemetry.createCounter(name, description, unit); | ||
} | ||
|
||
@Override | ||
public Counter createUpDownCounter(String name, String description, String unit) { | ||
return metricsTelemetry.createUpDownCounter(name, description, unit); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
metricsTelemetry.close(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsRegistry.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,39 @@ | ||
/* | ||
* 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 java.io.Closeable; | ||
|
||
/** | ||
* MetricsRegistry helps in creating the metric instruments. | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public interface MetricsRegistry extends Closeable { | ||
|
||
/** | ||
* Creates the counter. | ||
* @param name name of the counter. | ||
* @param description any description about the metric. | ||
* @param unit unit of the metric. | ||
* @return counter. | ||
*/ | ||
Counter createCounter(String name, String description, String unit); | ||
|
||
/** | ||
* Creates the upDown counter. | ||
* @param name name of the upDown counter. | ||
* @param description any description about the metric. | ||
* @param unit unit of the metric. | ||
* @return counter. | ||
*/ | ||
Counter createUpDownCounter(String name, String description, String unit); | ||
} |
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/NoopCounter.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.Counter; | ||
import org.opensearch.telemetry.metrics.tags.Tags; | ||
|
||
/** | ||
* No-op {@link Counter} | ||
* {@opensearch.internal} | ||
*/ | ||
@InternalApi | ||
public class NoopCounter implements Counter { | ||
|
||
/** | ||
* No-op Counter instance | ||
*/ | ||
public final static NoopCounter INSTANCE = new NoopCounter(); | ||
|
||
private NoopCounter() {} | ||
|
||
@Override | ||
public void add(double value) { | ||
|
||
} | ||
|
||
@Override | ||
public void add(double value, Tags tags) { | ||
|
||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/NoopMetricsRegistry.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,45 @@ | ||
/* | ||
* 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.Counter; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
*No-op {@link MetricsRegistry} | ||
* {@opensearch.internal} | ||
*/ | ||
@InternalApi | ||
public class NoopMetricsRegistry implements MetricsRegistry { | ||
|
||
/** | ||
* No-op Meter instance | ||
*/ | ||
public final static NoopMetricsRegistry INSTANCE = new NoopMetricsRegistry(); | ||
|
||
private NoopMetricsRegistry() {} | ||
|
||
@Override | ||
public Counter createCounter(String name, String description, String unit) { | ||
return NoopCounter.INSTANCE; | ||
} | ||
|
||
@Override | ||
public Counter createUpDownCounter(String name, String description, String unit) { | ||
return NoopCounter.INSTANCE; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/noop/package-info.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,16 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Contains metrics related classes | ||
* {@opensearch.internal} | ||
*/ | ||
@InternalApi | ||
package org.opensearch.telemetry.metrics.noop; | ||
|
||
import org.opensearch.common.annotation.InternalApi; |
99 changes: 99 additions & 0 deletions
99
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/tags/Tags.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,99 @@ | ||
/* | ||
* 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.tags; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Class to create tags for a meter. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class Tags { | ||
private final Map<String, Object> tagsMap; | ||
/** | ||
* Empty value. | ||
*/ | ||
public final static Tags EMPTY = new Tags(Collections.emptyMap()); | ||
|
||
/** | ||
* Factory method. | ||
* @return tags. | ||
*/ | ||
public static Tags create() { | ||
return new Tags(new HashMap<>()); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
private Tags(Map<String, Object> tagsMap) { | ||
this.tagsMap = tagsMap; | ||
} | ||
|
||
/** | ||
* Add String attribute. | ||
* @param key key | ||
* @param value value | ||
* @return Same instance. | ||
*/ | ||
public Tags addTag(String key, String value) { | ||
Objects.requireNonNull(value, "value cannot be null"); | ||
tagsMap.put(key, value); | ||
return this; | ||
} | ||
|
||
/** | ||
* Add long attribute. | ||
* @param key key | ||
* @param value value | ||
* @return Same instance. | ||
*/ | ||
public Tags addTag(String key, long value) { | ||
tagsMap.put(key, value); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Add double attribute. | ||
* @param key key | ||
* @param value value | ||
* @return Same instance. | ||
*/ | ||
public Tags addTag(String key, double value) { | ||
tagsMap.put(key, value); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Add boolean attribute. | ||
* @param key key | ||
* @param value value | ||
* @return Same instance. | ||
*/ | ||
public Tags addTag(String key, boolean value) { | ||
tagsMap.put(key, value); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Returns the attribute map. | ||
* @return tags map | ||
*/ | ||
public Map<String, ?> getTagsMap() { | ||
return Collections.unmodifiableMap(tagsMap); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/tags/package-info.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,16 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Contains metrics related classes | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
package org.opensearch.telemetry.metrics.tags; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; |
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
Oops, something went wrong.