Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagan Juneja committed May 11, 2024
1 parent d48c217 commit 1fe3245
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opensearch.core.indices.breaker.CircuitBreakerService;
import org.opensearch.env.Environment;
import org.opensearch.indices.IndicesService;
import org.opensearch.telemetry.service.TelemetryService;
import org.opensearch.threadpool.ThreadPool;

public final class OpenSearchResources {
Expand All @@ -25,6 +26,7 @@ public final class OpenSearchResources {
private java.nio.file.Path configPath;
private String pluginFileLocation;
private Client client;
private TelemetryService telemetryService;

private OpenSearchResources() {
threadPool = null;
Expand Down Expand Up @@ -108,4 +110,12 @@ public void setClient(final Client client) {
public Client getClient() {
return client;
}

public TelemetryService getTelemetryService() {
return telemetryService;
}

public void setTelemetryService(TelemetryService telemetryService) {
this.telemetryService = telemetryService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.opensearch.repositories.RepositoriesService;
import org.opensearch.rest.RestController;
import org.opensearch.script.ScriptService;
import org.opensearch.telemetry.service.TelemetryService;
import org.opensearch.telemetry.tracing.Tracer;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.Transport;
Expand Down Expand Up @@ -381,4 +382,9 @@ public List<Setting<?>> getSettings() {
PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING,
PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING);
}

@Override
public void setTelemetryService(TelemetryService telemetryService) {
OpenSearchResources.INSTANCE.setTelemetryService(telemetryService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public class PerformanceAnalyzerSearchListener

public PerformanceAnalyzerSearchListener(final PerformanceAnalyzerController controller) {
this.controller = controller;
if (OpenSearchResources.INSTANCE.getClusterService() != null && OpenSearchResources.INSTANCE.getClusterService().getMetricsRegistry() != null) {
if (OpenSearchResources.INSTANCE.getTelemetryService() != null
&& OpenSearchResources.INSTANCE.getTelemetryService().getMetricsRegistry()
!= null) {
this.metricsRegistry =
OpenSearchResources.INSTANCE.getClusterService().getMetricsRegistry();
OpenSearchResources.INSTANCE.getTelemetryService().getMetricsRegistry();
searchCPUUtilizationCounter =
metricsRegistry.createCounter(
"pa.core.search.cpuUtilization", "test counter", "1");
Expand Down Expand Up @@ -136,7 +138,8 @@ public void preQueryPhase(SearchContext searchContext) {
@Override
public void queryPhase(SearchContext searchContext, long tookInNanos) {
long currTime = System.currentTimeMillis();
if (searchCPUUtilizationCounter != null && !(searchCPUUtilizationCounter instanceof NoopCounter)) {
if (searchCPUUtilizationCounter != null
&& !(searchCPUUtilizationCounter instanceof NoopCounter)) {
LOG.info("Adding the addResourceTrackingCompletionListener");
searchContext
.getTask()
Expand All @@ -150,7 +153,10 @@ protected void innerOnResponse(Task task) {
Tags.create()
.addTag(
"shardId",
searchContext.shardTarget().getShardId().getId())
searchContext
.shardTarget()
.getShardId()
.getId())
.addTag(
"indexName",
searchContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ void set(
this.throughputCounter = throughputCounter;
this.startCpuTimeNanos = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
jvmThreadID = Thread.currentThread().getId();
LOG.info("Updating the counter Start thread {} {}", jvmThreadID, Thread.currentThread().getName());
LOG.info(
"Updating the counter Start thread {} {}",
jvmThreadID,
Thread.currentThread().getName());
}

@Override
Expand All @@ -85,9 +88,15 @@ public String getChannelType() {
public void sendResponse(TransportResponse response) throws IOException {
LOG.info("Updating the counter Finish thread {}", Thread.currentThread().getName());
if (throughputCounter != null && !(throughputCounter instanceof NoopCounter)) {
long timeNow = ((ThreadMXBean)ManagementFactory.getThreadMXBean()).getThreadCpuTime(jvmThreadID);
long timeNow =
((ThreadMXBean) ManagementFactory.getThreadMXBean())
.getThreadCpuTime(jvmThreadID);
long updatedValue = timeNow - startCpuTimeNanos;
LOG.info("Updating the counter inside PATransportChannel {} start time {}, now {}", updatedValue, startCpuTimeNanos, timeNow);
LOG.info(
"Updating the counter inside PATransportChannel {} start time {}, now {}",
updatedValue,
startCpuTimeNanos,
timeNow);
throughputCounter.add(
Math.max(updatedValue, 0),
Tags.create().addTag("indexName", indexName).addTag("shardId", shardId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.bulk.BulkShardRequest;
import org.opensearch.action.support.replication.TransportReplicationAction.ConcreteShardRequest;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.performanceanalyzer.OpenSearchResources;
import org.opensearch.performanceanalyzer.commons.collectors.StatsCollector;
import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController;
Expand All @@ -31,16 +30,15 @@ public class PerformanceAnalyzerTransportRequestHandler<T extends TransportReque
private TransportRequestHandler<T> actualHandler;
boolean logOnce = false;

private ClusterService clusterService = OpenSearchResources.INSTANCE.getClusterService();

private MetricsRegistry metricsRegistry;
private Counter cpuUtilizationCounter;

PerformanceAnalyzerTransportRequestHandler(
TransportRequestHandler<T> actualHandler, PerformanceAnalyzerController controller) {
this.actualHandler = actualHandler;
this.controller = controller;
this.metricsRegistry = clusterService.getMetricsRegistry();
this.metricsRegistry =
OpenSearchResources.INSTANCE.getTelemetryService().getMetricsRegistry();
this.cpuUtilizationCounter =
metricsRegistry.createCounter(
"pa.core.cpuUtilizationCounter", "cpuUtilizationCounter", "time");
Expand Down

0 comments on commit 1fe3245

Please sign in to comment.