Skip to content

Commit 48184df

Browse files
authored
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 8066e23 commit 48184df

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
@@ -23,7 +23,7 @@
2323
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction;
2424
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.CoordinatorStats;
2525
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.ExecutingPolicy;
26-
import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction;
26+
import org.elasticsearch.xpack.enrich.EnrichPolicyExecutor;
2727

2828
import java.io.IOException;
2929
import java.util.Comparator;
@@ -80,7 +80,7 @@ protected void masterOperation(Task task,
8080
.sorted(Comparator.comparing(CoordinatorStats::getNodeId))
8181
.collect(Collectors.toList());
8282
List<ExecutingPolicy> policyExecutionTasks = taskManager.getTasks().values().stream()
83-
.filter(t -> t.getAction().equals(ExecuteEnrichPolicyAction.NAME))
83+
.filter(t -> t.getAction().equals(EnrichPolicyExecutor.TASK_ACTION))
8484
.map(t -> t.taskInfo(clusterService.localNode().getId(), true))
8585
.map(t -> new ExecutingPolicy(t.getDescription(), t))
8686
.sorted(Comparator.comparing(ExecutingPolicy::getName))

0 commit comments

Comments
 (0)