From 3a304f2b71e0434c6c050b63dcb1ea2a51dd3bf1 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 18 Nov 2021 11:24:32 +0000 Subject: [PATCH] Remove unused TracingPlugin interface (#80799) --- .../java/org/elasticsearch/node/Node.java | 6 ++-- .../elasticsearch/plugins/TracingPlugin.java | 28 ---------------- .../java/org/elasticsearch/tasks/Task.java | 4 +-- .../org/elasticsearch/tasks/TaskTracer.java | 10 +++--- .../org/elasticsearch/tracing/Traceable.java | 32 +++++++++++++++++++ .../org/elasticsearch/tracing/Tracer.java | 25 +++++++++++++++ .../org/elasticsearch/xpack/apm/ApmIT.java | 3 +- .../java/org/elasticsearch/xpack/apm/APM.java | 3 +- .../elasticsearch/xpack/apm/APMTracer.java | 8 ++--- 9 files changed, 72 insertions(+), 47 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/plugins/TracingPlugin.java create mode 100644 server/src/main/java/org/elasticsearch/tracing/Traceable.java create mode 100644 server/src/main/java/org/elasticsearch/tracing/Tracer.java diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index b6a71a158ddfd..d3f75d38d2cae 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -147,7 +147,6 @@ import org.elasticsearch.plugins.SearchPlugin; import org.elasticsearch.plugins.ShutdownAwarePlugin; import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.plugins.TracingPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.rest.RestController; @@ -171,6 +170,7 @@ import org.elasticsearch.tasks.TaskTracer; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.tracing.Tracer; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportInterceptor; import org.elasticsearch.transport.TransportService; @@ -753,9 +753,7 @@ protected Node( final IndexingPressure indexingLimits = new IndexingPressure(settings); final TaskTracer taskTracer = transportService.getTaskManager().getTaskTracer(); - pluginComponents.stream() - .map(c -> c instanceof TracingPlugin.Tracer ? (TracingPlugin.Tracer) c : null) - .forEach(taskTracer::addTracer); + pluginComponents.stream().map(c -> c instanceof Tracer ? (Tracer) c : null).forEach(taskTracer::addTracer); final RecoverySettings recoverySettings = new RecoverySettings(settings, settingsModule.getClusterSettings()); RepositoriesModule repositoriesModule = new RepositoriesModule( diff --git a/server/src/main/java/org/elasticsearch/plugins/TracingPlugin.java b/server/src/main/java/org/elasticsearch/plugins/TracingPlugin.java deleted file mode 100644 index 02b3cf11b28bd..0000000000000 --- a/server/src/main/java/org/elasticsearch/plugins/TracingPlugin.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.plugins; - -import java.util.Map; - -public interface TracingPlugin { - - interface Traceable { - String getSpanId(); - - String getSpanName(); - - Map getAttributes(); - } - - interface Tracer { - void onTraceStarted(Traceable traceable); - - void onTraceStopped(Traceable traceable); - } -} diff --git a/server/src/main/java/org/elasticsearch/tasks/Task.java b/server/src/main/java/org/elasticsearch/tasks/Task.java index 152569521862d..e9b6f8500cb38 100644 --- a/server/src/main/java/org/elasticsearch/tasks/Task.java +++ b/server/src/main/java/org/elasticsearch/tasks/Task.java @@ -11,7 +11,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.io.stream.NamedWriteable; -import org.elasticsearch.plugins.TracingPlugin; +import org.elasticsearch.tracing.Traceable; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.ToXContentObject; @@ -21,7 +21,7 @@ /** * Current task information */ -public class Task implements TracingPlugin.Traceable { +public class Task implements Traceable { /** * The request header to mark tasks with specific ids diff --git a/server/src/main/java/org/elasticsearch/tasks/TaskTracer.java b/server/src/main/java/org/elasticsearch/tasks/TaskTracer.java index 23c1f12d9529b..ec631b369a9e9 100644 --- a/server/src/main/java/org/elasticsearch/tasks/TaskTracer.java +++ b/server/src/main/java/org/elasticsearch/tasks/TaskTracer.java @@ -11,7 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.elasticsearch.plugins.TracingPlugin; +import org.elasticsearch.tracing.Tracer; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -20,16 +20,16 @@ public class TaskTracer { private static final Logger logger = LogManager.getLogger(); - private final List tracers = new CopyOnWriteArrayList<>(); + private final List tracers = new CopyOnWriteArrayList<>(); - public void addTracer(TracingPlugin.Tracer tracer) { + public void addTracer(Tracer tracer) { if (tracer != null) { tracers.add(tracer); } } public void onTaskRegistered(Task task) { - for (TracingPlugin.Tracer tracer : tracers) { + for (Tracer tracer : tracers) { try { tracer.onTraceStarted(task); } catch (Exception e) { @@ -48,7 +48,7 @@ public void onTaskRegistered(Task task) { } public void onTaskUnregistered(Task task) { - for (TracingPlugin.Tracer tracer : tracers) { + for (Tracer tracer : tracers) { try { tracer.onTraceStopped(task); } catch (Exception e) { diff --git a/server/src/main/java/org/elasticsearch/tracing/Traceable.java b/server/src/main/java/org/elasticsearch/tracing/Traceable.java new file mode 100644 index 0000000000000..40ad2b92001e2 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/tracing/Traceable.java @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.tracing; + +import java.util.Map; + +/** + * Something which maps onto a span in a distributed trace. + */ +public interface Traceable { + + /** + * @return a key which uniquely identifies the span. + */ + String getSpanId(); + + /** + * @return the name of the span as seen by the external tracing system (e.g. the action name for a task) + */ + String getSpanName(); + + /** + * @return extra metadata about the span. + */ + Map getAttributes(); +} diff --git a/server/src/main/java/org/elasticsearch/tracing/Tracer.java b/server/src/main/java/org/elasticsearch/tracing/Tracer.java new file mode 100644 index 0000000000000..dd4454b8e6b62 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/tracing/Tracer.java @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.tracing; + +/** + * Represents a distributed tracing system that keeps track of the start and end of various activities in the cluster. + */ +public interface Tracer { + + /** + * Called when the {@link Traceable} activity starts. + */ + void onTraceStarted(Traceable traceable); + + /** + * Called when the {@link Traceable} activity ends. + */ + void onTraceStopped(Traceable traceable); +} diff --git a/x-pack/plugin/apm-integration/src/internalClusterTest/java/org/elasticsearch/xpack/apm/ApmIT.java b/x-pack/plugin/apm-integration/src/internalClusterTest/java/org/elasticsearch/xpack/apm/ApmIT.java index 52ec663c8ee3a..a2ed6522f3e6e 100644 --- a/x-pack/plugin/apm-integration/src/internalClusterTest/java/org/elasticsearch/xpack/apm/ApmIT.java +++ b/x-pack/plugin/apm-integration/src/internalClusterTest/java/org/elasticsearch/xpack/apm/ApmIT.java @@ -23,7 +23,6 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsService; -import org.elasticsearch.plugins.TracingPlugin; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskTracer; @@ -64,7 +63,7 @@ public void clearRecordedSpans() { } public void testModule() { - List plugins = internalCluster().getMasterNodeInstance(PluginsService.class).filterPlugins(TracingPlugin.class); + List plugins = internalCluster().getMasterNodeInstance(PluginsService.class).filterPlugins(APM.class); assertThat(plugins, hasSize(1)); TransportService transportService = internalCluster().getInstance(TransportService.class); diff --git a/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APM.java b/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APM.java index fd7f2ea57e493..64227153d4341 100644 --- a/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APM.java +++ b/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APM.java @@ -19,7 +19,6 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.TracingPlugin; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.script.ScriptService; import org.elasticsearch.tasks.Task; @@ -38,7 +37,7 @@ import java.util.Set; import java.util.function.Supplier; -public class APM extends Plugin implements TracingPlugin, NetworkPlugin { +public class APM extends Plugin implements NetworkPlugin { public static final Set TRACE_HEADERS = Set.of(Task.TRACE_PARENT, Task.TRACE_STATE); diff --git a/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APMTracer.java b/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APMTracer.java index d4d7ba1104034..2846daa2c9fbb 100644 --- a/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APMTracer.java +++ b/x-pack/plugin/apm-integration/src/main/java/org/elasticsearch/xpack/apm/APMTracer.java @@ -38,9 +38,9 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.plugins.TracingPlugin; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.tracing.Traceable; import java.security.AccessController; import java.security.PrivilegedAction; @@ -55,7 +55,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class APMTracer extends AbstractLifecycleComponent implements TracingPlugin.Tracer { +public class APMTracer extends AbstractLifecycleComponent implements org.elasticsearch.tracing.Tracer { public static final CapturingSpanExporter CAPTURING_SPAN_EXPORTER = new CapturingSpanExporter(); @@ -122,7 +122,7 @@ protected void doStop() { protected void doClose() {} @Override - public void onTraceStarted(TracingPlugin.Traceable traceable) { + public void onTraceStarted(Traceable traceable) { final Tracer tracer = this.tracer; final OpenTelemetry openTelemetry = this.openTelemetry; if (openTelemetry != null && tracer != null) { @@ -190,7 +190,7 @@ public Map getSpanHeadersById(String id) { } @Override - public void onTraceStopped(TracingPlugin.Traceable traceable) { + public void onTraceStopped(Traceable traceable) { final Span span = spans.remove(traceable.getSpanId()); if (span != null) { span.end();