Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Stashing context for Stats API to allow users to query from RestAPI (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
saratvemulapalli authored Oct 30, 2020
1 parent ff9e3bf commit 9900493
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Map;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.SearchRequest;
Expand All @@ -27,6 +29,7 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;
Expand All @@ -38,6 +41,7 @@
import com.amazon.opendistroforelasticsearch.ad.util.MultiResponsesDelegateActionListener;

public class StatsAnomalyDetectorTransportAction extends HandledTransportAction<ADStatsRequest, StatsAnomalyDetectorResponse> {
private final Logger logger = LogManager.getLogger(StatsAnomalyDetectorTransportAction.class);

private final Client client;
private final ADStats adStats;
Expand All @@ -60,7 +64,12 @@ public StatsAnomalyDetectorTransportAction(

@Override
protected void doExecute(Task task, ADStatsRequest request, ActionListener<StatsAnomalyDetectorResponse> listener) {
getStats(client, listener, request);
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
getStats(client, listener, request);
} catch (Exception e) {
logger.error(e);
listener.onFailure(e);
}
}

/**
Expand Down

0 comments on commit 9900493

Please sign in to comment.