Skip to content

Commit

Permalink
Remove unused TracingPlugin interface (#80799)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner authored Nov 18, 2021
1 parent 69caefd commit 3a304f2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 47 deletions.
6 changes: 2 additions & 4 deletions server/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 0 additions & 28 deletions server/src/main/java/org/elasticsearch/plugins/TracingPlugin.java

This file was deleted.

4 changes: 2 additions & 2 deletions server/src/main/java/org/elasticsearch/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions server/src/main/java/org/elasticsearch/tasks/TaskTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,16 +20,16 @@ public class TaskTracer {

private static final Logger logger = LogManager.getLogger();

private final List<TracingPlugin.Tracer> tracers = new CopyOnWriteArrayList<>();
private final List<Tracer> 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) {
Expand All @@ -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) {
Expand Down
32 changes: 32 additions & 0 deletions server/src/main/java/org/elasticsearch/tracing/Traceable.java
Original file line number Diff line number Diff line change
@@ -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 <i>span</i> 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<String, Object> getAttributes();
}
25 changes: 25 additions & 0 deletions server/src/main/java/org/elasticsearch/tracing/Tracer.java
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void clearRecordedSpans() {
}

public void testModule() {
List<TracingPlugin> plugins = internalCluster().getMasterNodeInstance(PluginsService.class).filterPlugins(TracingPlugin.class);
List<APM> plugins = internalCluster().getMasterNodeInstance(PluginsService.class).filterPlugins(APM.class);
assertThat(plugins, hasSize(1));

TransportService transportService = internalCluster().getInstance(TransportService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> TRACE_HEADERS = Set.of(Task.TRACE_PARENT, Task.TRACE_STATE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public Map<String, String> 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();
Expand Down

0 comments on commit 3a304f2

Please sign in to comment.