Skip to content

Commit 1377872

Browse files
Merge branch '2.x' into 2.x
Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
2 parents 1ceee94 + f00103c commit 1377872

38 files changed

Lines changed: 714 additions & 63 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
## [Unreleased 2.x]
77
### Added
88
- [Admission control] Add Resource usage collector service and resource usage tracker ([#10695](https://github.com/opensearch-project/OpenSearch/pull/10695))
9+
- [Admission control] Add enhancements to FS stats to include read/write time, queue size and IO time ([#10696](https://github.com/opensearch-project/OpenSearch/pull/10696))
910

1011
### Dependencies
1112
- Bumps jetty version to 9.4.52.v20230823 to fix GMS-2023-1857 ([#9822](https://github.com/opensearch-project/OpenSearch/pull/9822))
@@ -23,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2324
- Backport the PR #9107 for updating CONCURRENT_SEGMENT_SEARCH_TARGET_MAX_SLICE_COUNT_KEY setting to a dynamic setting ([#10606](https://github.com/opensearch-project/OpenSearch/pull/10606))
2425
- [Remote Store] Add Remote Store backpressure rejection stats to `_nodes/stats` ([#10524](https://github.com/opensearch-project/OpenSearch/pull/10524))
2526
- [BUG] Fix java.lang.SecurityException in repository-gcs plugin ([#10642](https://github.com/opensearch-project/OpenSearch/pull/10642))
27+
- Add telemetry tracer/metric enable flag and integ test. ([#10395](https://github.com/opensearch-project/OpenSearch/pull/10395))
2628

2729
### Deprecated
2830

libs/telemetry/src/main/java/org/opensearch/telemetry/metrics/MetricsTelemetry.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010

1111
import org.opensearch.common.annotation.ExperimentalApi;
1212

13-
import java.io.Closeable;
14-
1513
/**
1614
* Interface for metrics telemetry providers
1715
*
1816
* @opensearch.experimental
1917
*/
2018
@ExperimentalApi
21-
public interface MetricsTelemetry extends MetricsRegistry, Closeable {
19+
public interface MetricsTelemetry extends MetricsRegistry {
2220

2321
}

libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/DefaultTracer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public SpanScope withSpanInScope(Span span) {
8585
return DefaultSpanScope.create(span, tracerContextStorage).attach();
8686
}
8787

88+
@Override
89+
public boolean isRecording() {
90+
return true;
91+
}
92+
8893
private Span createSpan(SpanCreationContext spanCreationContext, Span parentSpan) {
8994
return tracingTelemetry.createSpan(spanCreationContext, parentSpan);
9095
}

libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/Tracer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ public interface Tracer extends HttpTracer, Closeable {
5353
*/
5454
SpanScope withSpanInScope(Span span);
5555

56+
/**
57+
* Tells if the traces are being recorded or not
58+
* @return boolean
59+
*/
60+
boolean isRecording();
61+
5662
}

libs/telemetry/src/main/java/org/opensearch/telemetry/tracing/noop/NoopTracer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public SpanScope withSpanInScope(Span span) {
5454
return SpanScope.NO_OP;
5555
}
5656

57+
@Override
58+
public boolean isRecording() {
59+
return false;
60+
}
61+
5762
@Override
5863
public void close() {
5964

libs/telemetry/src/test/java/org/opensearch/telemetry/tracing/DefaultTracerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void testCreateSpan() {
6262

6363
String spanName = defaultTracer.getCurrentSpan().getSpan().getSpanName();
6464
assertEquals("span_name", spanName);
65+
assertTrue(defaultTracer.isRecording());
6566
}
6667

6768
@SuppressWarnings("unchecked")

plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/tracing/IntegrationTestOTelTelemetryPlugin.java renamed to plugins/telemetry-otel/src/internalClusterTest/java/org/opensearch/telemetry/IntegrationTestOTelTelemetryPlugin.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.telemetry.tracing;
9+
package org.opensearch.telemetry;
1010

1111
import org.opensearch.common.settings.Settings;
12-
import org.opensearch.telemetry.OTelTelemetryPlugin;
13-
import org.opensearch.telemetry.Telemetry;
14-
import org.opensearch.telemetry.TelemetrySettings;
1512

1613
import java.util.Optional;
1714

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.telemetry.metrics;
10+
11+
import java.util.Collection;
12+
import java.util.List;
13+
14+
import io.opentelemetry.sdk.common.CompletableResultCode;
15+
import io.opentelemetry.sdk.metrics.InstrumentType;
16+
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
17+
import io.opentelemetry.sdk.metrics.data.MetricData;
18+
import io.opentelemetry.sdk.metrics.export.MetricExporter;
19+
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricExporter;
20+
21+
public class InMemorySingletonMetricsExporter implements MetricExporter {
22+
23+
public static final InMemorySingletonMetricsExporter INSTANCE = new InMemorySingletonMetricsExporter(InMemoryMetricExporter.create());
24+
25+
private static InMemoryMetricExporter delegate;
26+
27+
public static InMemorySingletonMetricsExporter create() {
28+
return INSTANCE;
29+
}
30+
31+
private InMemorySingletonMetricsExporter(InMemoryMetricExporter delegate) {
32+
InMemorySingletonMetricsExporter.delegate = delegate;
33+
}
34+
35+
@Override
36+
public CompletableResultCode export(Collection<MetricData> metrics) {
37+
return delegate.export(metrics);
38+
}
39+
40+
@Override
41+
public CompletableResultCode flush() {
42+
return delegate.flush();
43+
}
44+
45+
@Override
46+
public CompletableResultCode shutdown() {
47+
return delegate.shutdown();
48+
}
49+
50+
public List<MetricData> getFinishedMetricItems() {
51+
return delegate.getFinishedMetricItems();
52+
}
53+
54+
/**
55+
* Clears the state.
56+
*/
57+
public void reset() {
58+
delegate.reset();
59+
}
60+
61+
@Override
62+
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
63+
return delegate.getAggregationTemporality(instrumentType);
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.telemetry.metrics;
10+
11+
import org.opensearch.common.settings.Settings;
12+
import org.opensearch.common.unit.TimeValue;
13+
import org.opensearch.plugins.Plugin;
14+
import org.opensearch.telemetry.IntegrationTestOTelTelemetryPlugin;
15+
import org.opensearch.telemetry.OTelTelemetrySettings;
16+
import org.opensearch.telemetry.TelemetrySettings;
17+
import org.opensearch.telemetry.metrics.noop.NoopCounter;
18+
import org.opensearch.telemetry.metrics.noop.NoopMetricsRegistry;
19+
import org.opensearch.test.OpenSearchIntegTestCase;
20+
21+
import java.util.Arrays;
22+
import java.util.Collection;
23+
24+
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, minNumDataNodes = 1)
25+
public class TelemetryMetricsDisabledSanityIT extends OpenSearchIntegTestCase {
26+
27+
@Override
28+
protected Settings nodeSettings(int nodeOrdinal) {
29+
return Settings.builder()
30+
.put(super.nodeSettings(nodeOrdinal))
31+
.put(TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), false)
32+
.put(
33+
OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(),
34+
"org.opensearch.telemetry.metrics.InMemorySingletonMetricsExporter"
35+
)
36+
.put(TelemetrySettings.METRICS_PUBLISH_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(1))
37+
.build();
38+
}
39+
40+
@Override
41+
protected Collection<Class<? extends Plugin>> nodePlugins() {
42+
return Arrays.asList(IntegrationTestOTelTelemetryPlugin.class);
43+
}
44+
45+
@Override
46+
protected boolean addMockTelemetryPlugin() {
47+
return false;
48+
}
49+
50+
public void testSanityChecksWhenMetricsDisabled() throws Exception {
51+
MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class);
52+
53+
Counter counter = metricsRegistry.createCounter("test-counter", "test", "1");
54+
counter.add(1.0);
55+
56+
Thread.sleep(2000);
57+
58+
assertTrue(metricsRegistry instanceof NoopMetricsRegistry);
59+
assertTrue(counter instanceof NoopCounter);
60+
}
61+
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.telemetry.metrics;
10+
11+
import org.opensearch.common.settings.Settings;
12+
import org.opensearch.common.unit.TimeValue;
13+
import org.opensearch.plugins.Plugin;
14+
import org.opensearch.telemetry.IntegrationTestOTelTelemetryPlugin;
15+
import org.opensearch.telemetry.OTelTelemetrySettings;
16+
import org.opensearch.telemetry.TelemetrySettings;
17+
import org.opensearch.test.OpenSearchIntegTestCase;
18+
import org.junit.After;
19+
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.Collection;
23+
import java.util.stream.Collectors;
24+
25+
import io.opentelemetry.sdk.metrics.data.DoublePointData;
26+
27+
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, minNumDataNodes = 1)
28+
public class TelemetryMetricsEnabledSanityIT extends OpenSearchIntegTestCase {
29+
30+
@Override
31+
protected Settings nodeSettings(int nodeOrdinal) {
32+
return Settings.builder()
33+
.put(super.nodeSettings(nodeOrdinal))
34+
.put(TelemetrySettings.METRICS_FEATURE_ENABLED_SETTING.getKey(), true)
35+
.put(
36+
OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.getKey(),
37+
"org.opensearch.telemetry.metrics.InMemorySingletonMetricsExporter"
38+
)
39+
.put(TelemetrySettings.METRICS_PUBLISH_INTERVAL_SETTING.getKey(), TimeValue.timeValueSeconds(1))
40+
.build();
41+
}
42+
43+
@Override
44+
protected Collection<Class<? extends Plugin>> nodePlugins() {
45+
return Arrays.asList(IntegrationTestOTelTelemetryPlugin.class);
46+
}
47+
48+
@Override
49+
protected boolean addMockTelemetryPlugin() {
50+
return false;
51+
}
52+
53+
public void testCounter() throws Exception {
54+
MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class);
55+
InMemorySingletonMetricsExporter.INSTANCE.reset();
56+
57+
Counter counter = metricsRegistry.createCounter("test-counter", "test", "1");
58+
counter.add(1.0);
59+
// Sleep for about 2s to wait for metrics to be published.
60+
Thread.sleep(2000);
61+
62+
InMemorySingletonMetricsExporter exporter = InMemorySingletonMetricsExporter.INSTANCE;
63+
double value = ((DoublePointData) ((ArrayList) exporter.getFinishedMetricItems()
64+
.stream()
65+
.filter(a -> a.getName().equals("test-counter"))
66+
.collect(Collectors.toList())
67+
.get(0)
68+
.getDoubleSumData()
69+
.getPoints()).get(0)).getValue();
70+
assertEquals(1.0, value, 0.0);
71+
}
72+
73+
public void testUpDownCounter() throws Exception {
74+
75+
MetricsRegistry metricsRegistry = internalCluster().getInstance(MetricsRegistry.class);
76+
InMemorySingletonMetricsExporter.INSTANCE.reset();
77+
78+
Counter counter = metricsRegistry.createUpDownCounter("test-up-down-counter", "test", "1");
79+
counter.add(1.0);
80+
counter.add(-2.0);
81+
// Sleep for about 2s to wait for metrics to be published.
82+
Thread.sleep(2000);
83+
84+
InMemorySingletonMetricsExporter exporter = InMemorySingletonMetricsExporter.INSTANCE;
85+
double value = ((DoublePointData) ((ArrayList) exporter.getFinishedMetricItems()
86+
.stream()
87+
.filter(a -> a.getName().equals("test-up-down-counter"))
88+
.collect(Collectors.toList())
89+
.get(0)
90+
.getDoubleSumData()
91+
.getPoints()).get(0)).getValue();
92+
assertEquals(-1.0, value, 0.0);
93+
}
94+
95+
@After
96+
public void reset() {
97+
InMemorySingletonMetricsExporter.INSTANCE.reset();
98+
}
99+
}

0 commit comments

Comments
 (0)