-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add telemetry tracer/metric enable flag and integ test #10395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reta
merged 12 commits into
opensearch-project:main
from
Gaganjuneja:main-telemetry-flags
Oct 17, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb41efe
Add telemetry tracer/metric enable flag and integ test
e1ce0a8
Add Changelog
44e04c4
Fix compilation issue
fcef9f8
Empty-Commit
f28c5d2
Add component flag to traceable wrappers
Gaganjuneja d63c38c
Address review comment
9a67369
Address review comment
d8c67a0
Address review comment
c277a2b
Address review comment
c359f90
Address review comment
8e1701e
Address review comment
b84239a
Merge branch 'main' into main-telemetry-flags
Gaganjuneja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
65 changes: 65 additions & 0 deletions
65
...alClusterTest/java/org/opensearch/telemetry/metrics/InMemorySingletonMetricsExporter.java
This file contains hidden or 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,65 @@ | ||
| /* | ||
| * 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.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import io.opentelemetry.sdk.common.CompletableResultCode; | ||
| import io.opentelemetry.sdk.metrics.InstrumentType; | ||
| import io.opentelemetry.sdk.metrics.data.AggregationTemporality; | ||
| import io.opentelemetry.sdk.metrics.data.MetricData; | ||
| import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
| import io.opentelemetry.sdk.testing.exporter.InMemoryMetricExporter; | ||
|
|
||
| public class InMemorySingletonMetricsExporter implements MetricExporter { | ||
|
|
||
| public static final InMemorySingletonMetricsExporter INSTANCE = new InMemorySingletonMetricsExporter(InMemoryMetricExporter.create()); | ||
|
|
||
| private static InMemoryMetricExporter delegate; | ||
|
|
||
| public static InMemorySingletonMetricsExporter create() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| private InMemorySingletonMetricsExporter(InMemoryMetricExporter delegate) { | ||
| InMemorySingletonMetricsExporter.delegate = delegate; | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode export(Collection<MetricData> metrics) { | ||
| return delegate.export(metrics); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode flush() { | ||
| return delegate.flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode shutdown() { | ||
| return delegate.shutdown(); | ||
| } | ||
|
|
||
| public List<MetricData> getFinishedMetricItems() { | ||
| return delegate.getFinishedMetricItems(); | ||
| } | ||
|
|
||
| /** | ||
| * Clears the state. | ||
| */ | ||
| public void reset() { | ||
| delegate.reset(); | ||
| } | ||
|
|
||
| @Override | ||
| public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) { | ||
| return delegate.getAggregationTemporality(instrumentType); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
...alClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsDisabledSanityIT.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * 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.settings.Settings; | ||
| import org.opensearch.common.unit.TimeValue; | ||
| import org.opensearch.plugins.Plugin; | ||
| import org.opensearch.telemetry.IntegrationTestOTelTelemetryPlugin; | ||
| import org.opensearch.telemetry.OTelTelemetrySettings; | ||
| import org.opensearch.telemetry.TelemetrySettings; | ||
| import org.opensearch.telemetry.metrics.noop.NoopCounter; | ||
| import org.opensearch.telemetry.metrics.noop.NoopMetricsRegistry; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, minNumDataNodes = 1) | ||
| public class TelemetryMetricsDisabledSanityIT extends OpenSearchIntegTestCase { | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal) { | ||
| return Settings.builder() | ||
| .put(super.nodeSettings(nodeOrdinal)) | ||
| .put(TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), false) | ||
| .put( | ||
| OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(), | ||
| "org.opensearch.telemetry.metrics.InMemorySingletonMetricsExporter" | ||
| ) | ||
| .put(TelemetrySettings.METRICS_PUBLISH_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(1)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return Arrays.asList(IntegrationTestOTelTelemetryPlugin.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean addMockTelemetryPlugin() { | ||
| return false; | ||
| } | ||
|
|
||
| public void testSanityChecksWhenMetricsDisabled() throws Exception { | ||
| MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class); | ||
|
|
||
| Counter counter = metricsRegistry.createCounter("test-counter", "test", "1"); | ||
| counter.add(1.0); | ||
|
|
||
| Thread.sleep(2000); | ||
|
|
||
| assertTrue(metricsRegistry instanceof NoopMetricsRegistry); | ||
| assertTrue(counter instanceof NoopCounter); | ||
| } | ||
|
|
||
| } |
99 changes: 99 additions & 0 deletions
99
...nalClusterTest/java/org/opensearch/telemetry/metrics/TelemetryMetricsEnabledSanityIT.java
This file contains hidden or 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; | ||
|
|
||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.common.unit.TimeValue; | ||
| import org.opensearch.plugins.Plugin; | ||
| import org.opensearch.telemetry.IntegrationTestOTelTelemetryPlugin; | ||
| import org.opensearch.telemetry.OTelTelemetrySettings; | ||
| import org.opensearch.telemetry.TelemetrySettings; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
| import org.junit.After; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import io.opentelemetry.sdk.metrics.data.DoublePointData; | ||
|
|
||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, minNumDataNodes = 1) | ||
| public class TelemetryMetricsEnabledSanityIT extends OpenSearchIntegTestCase { | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal) { | ||
| return Settings.builder() | ||
| .put(super.nodeSettings(nodeOrdinal)) | ||
| .put(TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), true) | ||
| .put( | ||
| OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(), | ||
| "org.opensearch.telemetry.metrics.InMemorySingletonMetricsExporter" | ||
| ) | ||
| .put(TelemetrySettings.METRICS_PUBLISH_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(1)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return Arrays.asList(IntegrationTestOTelTelemetryPlugin.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean addMockTelemetryPlugin() { | ||
| return false; | ||
| } | ||
|
|
||
| public void testCounter() throws Exception { | ||
| MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class); | ||
| InMemorySingletonMetricsExporter.INSTANCE.reset(); | ||
|
|
||
| Counter counter = metricsRegistry.createCounter("test-counter", "test", "1"); | ||
| counter.add(1.0); | ||
| // Sleep for about 2s to wait for metrics to be published. | ||
| Thread.sleep(2000); | ||
|
|
||
| InMemorySingletonMetricsExporter exporter = InMemorySingletonMetricsExporter.INSTANCE; | ||
| double value = ((DoublePointData) ((ArrayList) exporter.getFinishedMetricItems() | ||
| .stream() | ||
| .filter(a -> a.getName().equals("test-counter")) | ||
| .collect(Collectors.toList()) | ||
| .get(0) | ||
| .getDoubleSumData() | ||
| .getPoints()).get(0)).getValue(); | ||
| assertEquals(1.0, value, 0.0); | ||
| } | ||
|
|
||
| public void testUpDownCounter() throws Exception { | ||
|
|
||
| MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class); | ||
| InMemorySingletonMetricsExporter.INSTANCE.reset(); | ||
|
|
||
| Counter counter = metricsRegistry.createUpDownCounter("test-up-down-counter", "test", "1"); | ||
| counter.add(1.0); | ||
| counter.add(-2.0); | ||
| // Sleep for about 2s to wait for metrics to be published. | ||
| Thread.sleep(2000); | ||
|
|
||
| InMemorySingletonMetricsExporter exporter = InMemorySingletonMetricsExporter.INSTANCE; | ||
| double value = ((DoublePointData) ((ArrayList) exporter.getFinishedMetricItems() | ||
| .stream() | ||
| .filter(a -> a.getName().equals("test-up-down-counter")) | ||
| .collect(Collectors.toList()) | ||
| .get(0) | ||
| .getDoubleSumData() | ||
| .getPoints()).get(0)).getValue(); | ||
| assertEquals(-1.0, value, 0.0); | ||
| } | ||
|
|
||
| @After | ||
| public void reset() { | ||
| InMemorySingletonMetricsExporter.INSTANCE.reset(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.