Skip to content

Commit

Permalink
Fix executing enrich policies stats (#48132)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martijnvg committed Oct 22, 2019
1 parent c09b62d commit 0ec0ab6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ public ActionRequestValidationException validate() {
return null;
}

// This will be displayed in tasks api and allows stats api to figure out which policies are being executed.
@Override
public String getDescription() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public class EnrichPolicyExecutor {

public static final String TASK_ACTION = "policy_execution";

private final ClusterService clusterService;
private final Client client;
private final TaskManager taskManager;
Expand Down Expand Up @@ -165,7 +167,7 @@ private Task runPolicy(ExecuteEnrichPolicyAction.Request request, EnrichPolicy p

private Task runPolicyTask(final ExecuteEnrichPolicyAction.Request request, EnrichPolicy policy,
BiConsumer<Task, ExecuteEnrichPolicyStatus> onResponse, BiConsumer<Task, Exception> onFailure) {
Task asyncTask = taskManager.register("enrich", "policy_execution", new TaskAwareRequest() {
Task asyncTask = taskManager.register("enrich", TASK_ACTION, new TaskAwareRequest() {
@Override
public void setParentTask(TaskId taskId) {
request.setParentTask(taskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction;
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.CoordinatorStats;
import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction.Response.ExecutingPolicy;
import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction;
import org.elasticsearch.xpack.enrich.EnrichPolicyExecutor;

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

0 comments on commit 0ec0ab6

Please sign in to comment.