|
34 | 34 | import org.apache.lucene.tests.util.LuceneTestCase;
|
35 | 35 | import org.opensearch.bootstrap.BootstrapCheck;
|
36 | 36 | import org.opensearch.bootstrap.BootstrapContext;
|
| 37 | +import org.opensearch.client.Client; |
37 | 38 | import org.opensearch.cluster.ClusterName;
|
| 39 | +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; |
38 | 40 | import org.opensearch.cluster.node.DiscoveryNodeRole;
|
| 41 | +import org.opensearch.cluster.service.ClusterService; |
39 | 42 | import org.opensearch.common.SetOnce;
|
40 | 43 | import org.opensearch.common.network.NetworkModule;
|
41 | 44 | import org.opensearch.common.settings.Settings;
|
42 | 45 | import org.opensearch.common.settings.SettingsException;
|
| 46 | +import org.opensearch.common.util.FeatureFlags; |
43 | 47 | import org.opensearch.core.common.breaker.CircuitBreaker;
|
| 48 | +import org.opensearch.core.common.io.stream.NamedWriteableRegistry; |
44 | 49 | import org.opensearch.core.common.transport.BoundTransportAddress;
|
45 | 50 | import org.opensearch.core.common.unit.ByteSizeUnit;
|
46 | 51 | import org.opensearch.core.common.unit.ByteSizeValue;
|
47 | 52 | import org.opensearch.core.indices.breaker.CircuitBreakerService;
|
| 53 | +import org.opensearch.core.xcontent.NamedXContentRegistry; |
48 | 54 | import org.opensearch.env.Environment;
|
49 | 55 | import org.opensearch.env.NodeEnvironment;
|
50 | 56 | import org.opensearch.index.IndexService;
|
|
56 | 62 | import org.opensearch.monitor.fs.FsProbe;
|
57 | 63 | import org.opensearch.plugins.CircuitBreakerPlugin;
|
58 | 64 | import org.opensearch.plugins.Plugin;
|
| 65 | +import org.opensearch.plugins.TelemetryAwarePlugin; |
| 66 | +import org.opensearch.plugins.TelemetryPlugin; |
| 67 | +import org.opensearch.repositories.RepositoriesService; |
| 68 | +import org.opensearch.script.ScriptService; |
| 69 | +import org.opensearch.telemetry.Telemetry; |
| 70 | +import org.opensearch.telemetry.TelemetrySettings; |
| 71 | +import org.opensearch.telemetry.metrics.MetricsRegistry; |
| 72 | +import org.opensearch.telemetry.tracing.Tracer; |
| 73 | +import org.opensearch.test.FeatureFlagSetter; |
59 | 74 | import org.opensearch.test.InternalTestCluster;
|
60 | 75 | import org.opensearch.test.MockHttpTransport;
|
61 | 76 | import org.opensearch.test.NodeRoles;
|
62 | 77 | import org.opensearch.test.OpenSearchTestCase;
|
63 | 78 | import org.opensearch.threadpool.ThreadPool;
|
| 79 | +import org.opensearch.watcher.ResourceWatcherService; |
64 | 80 |
|
65 | 81 | import java.io.IOException;
|
66 | 82 | import java.nio.file.Path;
|
67 | 83 | import java.util.ArrayList;
|
| 84 | +import java.util.Collection; |
68 | 85 | import java.util.Collections;
|
69 | 86 | import java.util.List;
|
| 87 | +import java.util.Optional; |
70 | 88 | import java.util.Set;
|
71 | 89 | import java.util.concurrent.CountDownLatch;
|
72 | 90 | import java.util.concurrent.RejectedExecutionException;
|
73 | 91 | import java.util.concurrent.TimeUnit;
|
74 | 92 | import java.util.concurrent.atomic.AtomicBoolean;
|
| 93 | +import java.util.function.Supplier; |
75 | 94 |
|
76 | 95 | import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
|
77 | 96 | import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
|
@@ -404,6 +423,81 @@ public void testCreateWithFileCache() throws Exception {
|
404 | 423 | }
|
405 | 424 | }
|
406 | 425 |
|
| 426 | + public void testTelemetryAwarePlugins() throws IOException { |
| 427 | + Settings.Builder settings = baseSettings(); |
| 428 | + List<Class<? extends Plugin>> plugins = basePlugins(); |
| 429 | + plugins.add(MockTelemetryAwarePlugin.class); |
| 430 | + try (Node node = new MockNode(settings.build(), plugins)) { |
| 431 | + MockTelemetryAwareComponent mockTelemetryAwareComponent = node.injector().getInstance(MockTelemetryAwareComponent.class); |
| 432 | + assertNotNull(mockTelemetryAwareComponent.getTracer()); |
| 433 | + assertNotNull(mockTelemetryAwareComponent.getMetricsRegistry()); |
| 434 | + TelemetryAwarePlugin telemetryAwarePlugin = node.getPluginsService().filterPlugins(TelemetryAwarePlugin.class).get(0); |
| 435 | + assertTrue(telemetryAwarePlugin instanceof MockTelemetryAwarePlugin); |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + public void testTelemetryPluginShouldNOTImplementTelemetryAwarePlugin() throws IOException { |
| 440 | + Settings.Builder settings = baseSettings(); |
| 441 | + List<Class<? extends Plugin>> plugins = basePlugins(); |
| 442 | + plugins.add(MockTelemetryPlugin.class); |
| 443 | + FeatureFlagSetter.set(FeatureFlags.TELEMETRY); |
| 444 | + settings.put(TelemetrySettings.TRACER_FEATURE_ENABLED_SETTING.getKey(), true); |
| 445 | + assertThrows(IllegalStateException.class, () -> new MockNode(settings.build(), plugins)); |
| 446 | + } |
| 447 | + |
| 448 | + private static class MockTelemetryAwareComponent { |
| 449 | + private final Tracer tracer; |
| 450 | + private final MetricsRegistry metricsRegistry; |
| 451 | + |
| 452 | + public MockTelemetryAwareComponent(Tracer tracer, MetricsRegistry metricsRegistry) { |
| 453 | + this.tracer = tracer; |
| 454 | + this.metricsRegistry = metricsRegistry; |
| 455 | + } |
| 456 | + |
| 457 | + public Tracer getTracer() { |
| 458 | + return tracer; |
| 459 | + } |
| 460 | + |
| 461 | + public MetricsRegistry getMetricsRegistry() { |
| 462 | + return metricsRegistry; |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + public static class MockTelemetryAwarePlugin extends Plugin implements TelemetryAwarePlugin { |
| 467 | + @Override |
| 468 | + public Collection<Object> createComponents( |
| 469 | + Client client, |
| 470 | + ClusterService clusterService, |
| 471 | + ThreadPool threadPool, |
| 472 | + ResourceWatcherService resourceWatcherService, |
| 473 | + ScriptService scriptService, |
| 474 | + NamedXContentRegistry xContentRegistry, |
| 475 | + Environment environment, |
| 476 | + NodeEnvironment nodeEnvironment, |
| 477 | + NamedWriteableRegistry namedWriteableRegistry, |
| 478 | + IndexNameExpressionResolver indexNameExpressionResolver, |
| 479 | + Supplier<RepositoriesService> repositoriesServiceSupplier, |
| 480 | + Tracer tracer, |
| 481 | + MetricsRegistry metricsRegistry |
| 482 | + ) { |
| 483 | + return List.of(new MockTelemetryAwareComponent(tracer, metricsRegistry)); |
| 484 | + } |
| 485 | + |
| 486 | + } |
| 487 | + |
| 488 | + public static class MockTelemetryPlugin extends Plugin implements TelemetryPlugin, TelemetryAwarePlugin { |
| 489 | + |
| 490 | + @Override |
| 491 | + public Optional<Telemetry> getTelemetry(TelemetrySettings telemetrySettings) { |
| 492 | + return Optional.empty(); |
| 493 | + } |
| 494 | + |
| 495 | + @Override |
| 496 | + public String getName() { |
| 497 | + return null; |
| 498 | + } |
| 499 | + } |
| 500 | + |
407 | 501 | public static class MockCircuitBreakerPlugin extends Plugin implements CircuitBreakerPlugin {
|
408 | 502 |
|
409 | 503 | private SetOnce<CircuitBreaker> myCircuitBreaker = new SetOnce<>();
|
|
0 commit comments