Skip to content

Commit

Permalink
Add request tracing framework
Browse files Browse the repository at this point in the history
Signed-off-by: suranjay <surajkumar.tu@gmail.com>
  • Loading branch information
suranjay committed May 29, 2023
1 parent 0d67058 commit a2dd91d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.opentelemetry.api.OpenTelemetry;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.FeatureFlags;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.TracerPlugin;
import org.opensearch.threadpool.ThreadPool;
Expand All @@ -18,6 +19,8 @@
import java.util.Map;
import java.util.function.Supplier;

import static org.opensearch.common.util.FeatureFlags.TRACER;

/**
* Tracer plugin based on Otel
*/
Expand All @@ -32,10 +35,13 @@ public OTelTracerModulePlugin() {}

@Override
public Settings additionalSettings() {
return Settings.builder()
// set Otel tracer as default tracer
.put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME)
.build();
if (FeatureFlags.isEnabled(TRACER)) {
return Settings.builder()
// set Otel tracer as default tracer
.put(TracerModule.TRACER_DEFAULT_TYPE_SETTING.getKey(), OTEL_TRACER_NAME)
.build();
}
return Settings.EMPTY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,8 @@ public void apply(Settings value, Settings current, Settings previous) {
RemoteRefreshSegmentPressureSettings.MIN_CONSECUTIVE_FAILURES_LIMIT,
RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_MOVING_AVERAGE_WINDOW_SIZE,
RemoteRefreshSegmentPressureSettings.UPLOAD_BYTES_PER_SEC_MOVING_AVERAGE_WINDOW_SIZE,
RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE,
RemoteRefreshSegmentPressureSettings.UPLOAD_TIME_MOVING_AVERAGE_WINDOW_SIZE

// Settings related to Tracing framework
TracerSettings.TRACER_LEVEL_SETTING,
TracerSettings.TRACER_EXPORTER_DELAY_SETTING,
TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING,
TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING,
TracerModule.TRACER_DEFAULT_TYPE_SETTING,
TracerModule.TRACER_TYPE_SETTING
)
)
);
Expand All @@ -678,6 +671,15 @@ public void apply(Settings value, Settings current, Settings previous) {
IndicesService.CLUSTER_REMOTE_STORE_REPOSITORY_SETTING,
IndicesService.CLUSTER_REMOTE_TRANSLOG_STORE_ENABLED_SETTING,
IndicesService.CLUSTER_REMOTE_TRANSLOG_REPOSITORY_SETTING
),
List.of(FeatureFlags.TRACER),
List.of(
TracerSettings.TRACER_LEVEL_SETTING,
TracerSettings.TRACER_EXPORTER_DELAY_SETTING,
TracerSettings.TRACER_EXPORTER_BATCH_SIZE_SETTING,
TracerSettings.TRACER_EXPORTER_MAX_QUEUE_SIZE_SETTING,
TracerModule.TRACER_TYPE_SETTING,
TracerModule.TRACER_DEFAULT_TYPE_SETTING
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ protected FeatureFlagSettings(
FeatureFlags.EXTENSIONS_SETTING,
FeatureFlags.IDENTITY_SETTING,
FeatureFlags.SEARCH_PIPELINE_SETTING,
FeatureFlags.CONCURRENT_SEGMENT_SEARCH_SETTING
FeatureFlags.CONCURRENT_SEGMENT_SEARCH_SETTING,
FeatureFlags.TRACER_SETTING
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class FeatureFlags {
*/
public static final String CONCURRENT_SEGMENT_SEARCH = "opensearch.experimental.feature.concurrent_segment_search.enabled";

/**
* Gates the functionality of tracing framework.
*/
public static final String TRACER = "opensearch.experimental.feature.tracer.enabled";

/**
* Should store the settings from opensearch.yml.
*/
Expand Down Expand Up @@ -105,6 +110,8 @@ public static boolean isEnabled(String featureFlagName) {

public static final Setting<Boolean> IDENTITY_SETTING = Setting.boolSetting(IDENTITY, false, Property.NodeScope);

public static final Setting<Boolean> TRACER_SETTING = Setting.boolSetting(TRACER, false, Property.NodeScope);

public static final Setting<Boolean> CONCURRENT_SEGMENT_SEARCH_SETTING = Setting.boolSetting(
CONCURRENT_SEGMENT_SEARCH,
false,
Expand Down
17 changes: 11 additions & 6 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@

import static java.util.stream.Collectors.toList;
import static org.opensearch.common.util.FeatureFlags.SEARCH_PIPELINE;
import static org.opensearch.common.util.FeatureFlags.TRACER;
import static org.opensearch.env.NodeEnvironment.collectFileCacheDataPath;
import static org.opensearch.index.ShardIndexingPressureSettings.SHARD_INDEXING_PRESSURE_ENABLED_ATTRIBUTE_KEY;

Expand Down Expand Up @@ -1012,11 +1013,13 @@ protected Node(
searchModule.getIndexSearcherExecutor(threadPool)
);

final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings());
List<TracerPlugin> tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class);
TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings);
TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector());
resourcesToClose.add(TracerManager::closeTracer);
if (FeatureFlags.isEnabled(TRACER)) {
final TracerSettings tracerSettings = new TracerSettings(settings, clusterService.getClusterSettings());
List<TracerPlugin> tracerPlugins = pluginsService.filterPlugins(TracerPlugin.class);
TracerModule tracerModule = new TracerModule(settings, tracerPlugins, threadPool, tracerSettings);
TracerManager.initTracerManager(tracerSettings, tracerModule.getTracerSupplier(), tracerModule.getTracerHeaderInjector());
resourcesToClose.add(TracerManager::closeTracer);
}

final List<PersistentTasksExecutor<?>> tasksExecutors = pluginsService.filterPlugins(PersistentTaskPlugin.class)
.stream()
Expand Down Expand Up @@ -1475,7 +1478,9 @@ public synchronized void close() throws IOException {
toClose.add(() -> stopWatch.stop().start("node_environment"));
toClose.add(injector.getInstance(NodeEnvironment.class));
toClose.add(stopWatch::stop);
toClose.add(TracerManager::closeTracer);
if (FeatureFlags.isEnabled(TRACER)) {
toClose.add(TracerManager::closeTracer);
}

if (logger.isTraceEnabled()) {
toClose.add(() -> logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint()));
Expand Down

0 comments on commit a2dd91d

Please sign in to comment.