Skip to content

Commit 3f93300

Browse files
committed
Fix executing enrich policies stats (#48132)
The enrich stats api picked the wrong task to be displayed in the executing stats section. In case `wait_for_completion` was set to `false` then no task was being displayed and if that param was set to `true` then the wrong task was being displayed (transport action task instead of enrich policy executor task). Testing executing policies in enrich stats api is tricky. I have verified locally that this commit fixes the bug.
1 parent 211d647 commit 3f93300

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/enrich/action/ExecuteEnrichPolicyAction.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ public ActionRequestValidationException validate() {
6868
return null;
6969
}
7070

71-
// This will be displayed in tasks api and allows stats api to figure out which policies are being executed.
72-
@Override
73-
public String getDescription() {
74-
return name;
75-
}
76-
7771
@Override
7872
public boolean equals(Object o) {
7973
if (this == o) return true;

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
public class EnrichPolicyExecutor {
3131

32+
public static final String TASK_ACTION = "policy_execution";
33+
3234
private final ClusterService clusterService;
3335
private final Client client;
3436
private final TaskManager taskManager;
@@ -165,7 +167,7 @@ private Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy p
165167

166168
private Task runPolicyTask(final ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
167169
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse, BiConsumer<Task, Exception> onFailure) {
168-
Task asyncTask = taskManager.register("enrich", "policy_execution", new TaskAwareRequest() {
170+
Task asyncTask = taskManager.register("enrich", TASK_ACTION, new TaskAwareRequest() {
169171
@Override
170172
public void setParentTask(TaskId taskId) {
171173
request.setParentTask(taskId);

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/TransportEnrichStatsAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction;
2323
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.CoordinatorStats;
2424
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.ExecutingPolicy;
25-
import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction;
25+
import org.elasticsearch.xpack.enrich.EnrichPolicyExecutor;
2626

2727
import java.io.IOException;
2828
import java.util.Comparator;
@@ -78,7 +78,7 @@ protected void masterOperation(EnrichStatsAction.Request request,
7878
.sorted(Comparator.comparing(CoordinatorStats::getNodeId))
7979
.collect(Collectors.toList());
8080
List<ExecutingPolicy> policyExecutionTasks = taskManager.getTasks().values().stream()
81-
.filter(t -> t.getAction().equals(ExecuteEnrichPolicyAction.NAME))
81+
.filter(t -> t.getAction().equals(EnrichPolicyExecutor.TASK_ACTION))
8282
.map(t -> t.taskInfo(clusterService.localNode().getId(), true))
8383
.map(t -> new ExecutingPolicy(t.getDescription(), t))
8484
.sorted(Comparator.comparing(ExecutingPolicy::getName))

0 commit comments

Comments
 (0)