-
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.
Signed-off-by: Gagan Juneja <[email protected]>
- Loading branch information
Gagan Juneja
committed
Sep 26, 2023
1 parent
a8969cb
commit cacdc02
Showing
37 changed files
with
1,301 additions
and
38 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
/* | ||
* 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.tracing.attributes.Attributes; | ||
|
||
/** | ||
* Counter adds the value to the existing metric. | ||
*/ | ||
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 attributes attributes/dimensions of the metric. | ||
*/ | ||
void add(double value, Attributes attributes); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
/* | ||
* 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.Closeable; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Default implementation for {@link MetricsRegistry} | ||
*/ | ||
public 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 { | ||
((Closeable) metricsTelemetry).close(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
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,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 java.io.Closeable; | ||
|
||
/** | ||
* MetricsRegistry helps in creating the metric instruments. | ||
*/ | ||
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
35 changes: 35 additions & 0 deletions
35
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,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.noop; | ||
|
||
import org.opensearch.telemetry.metrics.Counter; | ||
import org.opensearch.telemetry.tracing.attributes.Attributes; | ||
|
||
/** | ||
* No-op {@link Counter} | ||
*/ | ||
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, Attributes attributes) { | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
/* | ||
* 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.telemetry.metrics.Counter; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
*No-op {@link MetricsRegistry} | ||
*/ | ||
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 { | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
/* | ||
* 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 | ||
*/ | ||
package org.opensearch.telemetry.metrics.noop; |
51 changes: 51 additions & 0 deletions
51
...telemetry/src/test/java/org/opensearch/telemetry/metrics/DefaultMetricsRegistryTests.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,51 @@ | ||
/* | ||
* 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.test.OpenSearchTestCase; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DefaultMetricsRegistryTests extends OpenSearchTestCase { | ||
|
||
private MetricsTelemetry metricsTelemetry; | ||
private DefaultMetricsRegistry defaultMeterRegistry; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
metricsTelemetry = mock(MetricsTelemetry.class); | ||
defaultMeterRegistry = new DefaultMetricsRegistry(metricsTelemetry); | ||
} | ||
|
||
public void testCounter() { | ||
Counter mockCounter = mock(Counter.class); | ||
when(defaultMeterRegistry.createCounter(any(String.class), any(String.class), any(String.class))).thenReturn(mockCounter); | ||
Counter counter = defaultMeterRegistry.createCounter( | ||
"org.opensearch.telemetry.metrics.DefaultMeterRegistryTests.testCounter", | ||
"test counter", | ||
"1" | ||
); | ||
assertSame(mockCounter, counter); | ||
} | ||
|
||
public void testUpDownCounter() { | ||
Counter mockCounter = mock(Counter.class); | ||
when(defaultMeterRegistry.createUpDownCounter(any(String.class), any(String.class), any(String.class))).thenReturn(mockCounter); | ||
Counter counter = defaultMeterRegistry.createUpDownCounter( | ||
"org.opensearch.telemetry.metrics.DefaultMeterRegistryTests.testUpDownCounter", | ||
"test up-down counter", | ||
"1" | ||
); | ||
assertSame(mockCounter, counter); | ||
} | ||
|
||
} |
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
1 change: 1 addition & 0 deletions
1
plugins/telemetry-otel/licenses/opentelemetry-extension-incubator-1.30.1-alpha.jar.sha1
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 @@ | ||
bfcea9bd71f97dd4e8a4f92c15ba5659fb07ff05 |
Oops, something went wrong.