forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gagan Juneja <[email protected]>
- Loading branch information
Gagan Juneja
committed
May 13, 2024
1 parent
cd55bca
commit d30fca6
Showing
5 changed files
with
140 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
server/src/main/java/org/opensearch/telemetry/service/TelemetryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.telemetry.service; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.common.lifecycle.AbstractLifecycleComponent; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.plugins.PluginsService; | ||
import org.opensearch.plugins.TelemetryPlugin; | ||
import org.opensearch.telemetry.TelemetryModule; | ||
import org.opensearch.telemetry.TelemetrySettings; | ||
import org.opensearch.telemetry.metrics.MetricsRegistry; | ||
import org.opensearch.telemetry.metrics.MetricsRegistryFactory; | ||
import org.opensearch.telemetry.metrics.NoopMetricsRegistryFactory; | ||
import org.opensearch.telemetry.tracing.NoopTracerFactory; | ||
import org.opensearch.telemetry.tracing.Tracer; | ||
import org.opensearch.telemetry.tracing.TracerFactory; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import static org.opensearch.common.util.FeatureFlags.TELEMETRY; | ||
|
||
/** | ||
* It initializes the telemetry plugin and creates the {@link TracerFactory} and {@link MetricsRegistryFactory} factories. | ||
* It provides the access to {@link Tracer} and {@link MetricsRegistry} to other code paths for instrumentations. | ||
* @opensearch.experimental | ||
*/ | ||
@ExperimentalApi | ||
public class TelemetryService extends AbstractLifecycleComponent { | ||
|
||
private TracerFactory tracerFactory = new NoopTracerFactory(); | ||
private MetricsRegistryFactory metricsRegistryFactory = new NoopMetricsRegistryFactory(); | ||
|
||
/** | ||
* Construcs the {@link TelemetryService} | ||
* @param settings settings | ||
* @param clusterSettings cluster settings. | ||
* @param pluginsService plugin service. | ||
* @param threadPool thread pool. | ||
*/ | ||
public TelemetryService(Settings settings, ClusterSettings clusterSettings, PluginsService pluginsService, ThreadPool threadPool) { | ||
init(settings, clusterSettings, pluginsService, threadPool); | ||
} | ||
|
||
private void init(Settings settings, ClusterSettings clusterSettings, PluginsService pluginsService, ThreadPool threadPool) { | ||
if (FeatureFlags.isEnabled(TELEMETRY)) { | ||
final TelemetrySettings telemetrySettings = new TelemetrySettings(settings, clusterSettings); | ||
if (telemetrySettings.isTracingFeatureEnabled() || telemetrySettings.isMetricsFeatureEnabled()) { | ||
List<TelemetryPlugin> telemetryPlugins = pluginsService.filterPlugins(TelemetryPlugin.class); | ||
TelemetryModule telemetryModule = new TelemetryModule(telemetryPlugins, telemetrySettings); | ||
if (telemetrySettings.isTracingFeatureEnabled()) { | ||
tracerFactory = new TracerFactory(telemetrySettings, telemetryModule.getTelemetry(), threadPool.getThreadContext()); | ||
} | ||
if (telemetrySettings.isMetricsFeatureEnabled()) { | ||
metricsRegistryFactory = new MetricsRegistryFactory(telemetrySettings, telemetryModule.getTelemetry()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns the tracer object. If tracer or telemetry plugin is not configured then returns {@link org.opensearch.telemetry.tracing.noop.NoopTracer} | ||
* will be returned. | ||
* @return tracer. | ||
*/ | ||
public Tracer getTracer(){ | ||
return tracerFactory.getTracer(); | ||
} | ||
|
||
/** | ||
* Returns the {@link MetricsRegistry} object. If metrics registry or telemetry plugin is not configured then returns {@link MetricsRegistry} | ||
* @return | ||
*/ | ||
public MetricsRegistry getMetricsRegistry(){ | ||
return metricsRegistryFactory.getMetricsRegistry(); | ||
} | ||
|
||
@Override | ||
protected void doStart() { | ||
} | ||
|
||
@Override | ||
protected void doStop() { | ||
} | ||
|
||
@Override | ||
protected void doClose() throws IOException { | ||
metricsRegistryFactory.getMetricsRegistry().close(); | ||
tracerFactory.getTracer().close(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
server/src/main/java/org/opensearch/telemetry/service/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/** | ||
* This package contains classes needed for telemetry. | ||
*/ | ||
package org.opensearch.telemetry.service; |