Skip to content

Commit

Permalink
incorporate pr comments
Browse files Browse the repository at this point in the history
Signed-off-by: Gagan Juneja <[email protected]>
  • Loading branch information
Gagan Juneja committed May 17, 2024
1 parent a32b4c9 commit 46a2319
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -621,6 +622,18 @@ protected Node(
final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterService.getClusterSettings());
if (telemetrySettings.isTracingFeatureEnabled() || telemetrySettings.isMetricsFeatureEnabled()) {
List<TelemetryPlugin> telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class);
List<TelemetryPlugin> telemetryPluginsImplementingTelemetryAware = telemetryPlugins.stream()
.filter(a -> TelemetryAwarePlugin.class.isAssignableFrom(a.getClass()))
.collect(toList());
if (telemetryPluginsImplementingTelemetryAware.isEmpty() == false) {
throw new IllegalStateException(
String.format(
Locale.ROOT,
"Telemetry plugins %s should not implement TelemetryAwarePlugin interface",
telemetryPluginsImplementingTelemetryAware
)
);
}
TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, telemetrySettings);
if (telemetrySettings.isTracingFeatureEnabled()) {
tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool.getThreadContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.common.lifecycle.LifecycleComponent;
import org.opensearch.core.common.io.stream.NamedWriteable;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
Expand All @@ -34,6 +35,7 @@
*
* @opensearch.experimental
*/
@ExperimentalApi
public interface TelemetryAwarePlugin {

/**
Expand Down
28 changes: 28 additions & 0 deletions server/src/test/java/org/opensearch/node/NodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.opensearch.common.network.NetworkModule;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.core.common.breaker.CircuitBreaker;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.core.common.transport.BoundTransportAddress;
Expand All @@ -62,10 +63,14 @@
import org.opensearch.plugins.CircuitBreakerPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.TelemetryAwarePlugin;
import org.opensearch.plugins.TelemetryPlugin;
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.script.ScriptService;
import org.opensearch.telemetry.Telemetry;
import org.opensearch.telemetry.TelemetrySettings;
import org.opensearch.telemetry.metrics.MetricsRegistry;
import org.opensearch.telemetry.tracing.Tracer;
import org.opensearch.test.FeatureFlagSetter;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.MockHttpTransport;
import org.opensearch.test.NodeRoles;
Expand All @@ -79,6 +84,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.RejectedExecutionException;
Expand Down Expand Up @@ -430,6 +436,15 @@ public void testTelemetryAwarePlugins() throws IOException {
}
}

public void testTelemetryPluginShouldNOTImplementTelemetryAwarePlugin() throws IOException {
Settings.Builder settings = baseSettings();
List<Class<? extends Plugin>> plugins = basePlugins();
plugins.add(MockTelemetryPlugin.class);
FeatureFlagSetter.set(FeatureFlags.TELEMETRY);
settings.put(TelemetrySettings.TRACER_FEATURE_ENABLED_SETTING.getKey(), true);
assertThrows(IllegalStateException.class, () -> new MockNode(settings.build(), plugins));
}

private static class MockTelemetryAwareComponent {
private final Tracer tracer;
private final MetricsRegistry metricsRegistry;
Expand Down Expand Up @@ -470,6 +485,19 @@ public Collection<Object> createComponents(

}

public static class MockTelemetryPlugin extends Plugin implements TelemetryPlugin, TelemetryAwarePlugin {

@Override
public Optional<Telemetry> getTelemetry(TelemetrySettings telemetrySettings) {
return Optional.empty();
}

@Override
public String getName() {
return null;
}
}

public static class MockCircuitBreakerPlugin extends Plugin implements CircuitBreakerPlugin {

private SetOnce<CircuitBreaker> myCircuitBreaker = new SetOnce<>();
Expand Down

0 comments on commit 46a2319

Please sign in to comment.