From 6a9cde2918c63cc696c571358ccf47dd67fbd1f2 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Thu, 1 Oct 2020 13:17:46 -0400 Subject: [PATCH] Add support for x_opaque_id to _cat/tasks (#63036) (#63135) Adds an optional column with support for x_opaque_id to _cat/tasks API. Closes #61118 --- .../rest-api-spec/test/cat.tasks/10_basic.yml | 15 +++++++++++++++ .../rest/action/cat/RestTasksAction.java | 3 +++ 2 files changed, 18 insertions(+) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.tasks/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.tasks/10_basic.yml index c7a38bfb44a..c3f0793a799 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.tasks/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.tasks/10_basic.yml @@ -17,3 +17,18 @@ $body: | / # action task_id parent_task_id type start_time timestamp running_time ip node description ^( \S+\s+ \S+\:\d+\s+ (?:\-|\S+\:\d+)\s+ \S+\s+ \d+\s+ \d\d\:\d\d\:\d\d\s+ \S+\s+ \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s+ \S+\s+ .*\n)+$/ + +--- +"Test cat tasks output with X-Opaque-Id": + - skip: + version: " - 7.9.99" + reason: support for opaque_id was added in 7.10.0 + features: headers + + - do: + headers: { "X-Opaque-Id": "TestID" } + cat.tasks: + h: ["action", "x_opaque_id"] + + - match: + $body: /TestID/ diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java index a43e54dc65f..c3830231a08 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskInfo; import java.time.Instant; @@ -117,6 +118,7 @@ public class RestTasksAction extends AbstractCatAction { table.addCell("port", "default:false;alias:po;desc:bound transport port"); table.addCell("node", "default:true;alias:n;desc:node name"); table.addCell("version", "default:false;alias:v;desc:es version"); + table.addCell("x_opaque_id", "default:false;alias:x;desc:X-Opaque-ID header"); // Task detailed info if (detailed) { @@ -153,6 +155,7 @@ public class RestTasksAction extends AbstractCatAction { table.addCell(node.getAddress().address().getPort()); table.addCell(node == null ? "-" : node.getName()); table.addCell(node == null ? "-" : node.getVersion().toString()); + table.addCell(taskInfo.getHeaders().getOrDefault(Task.X_OPAQUE_ID, "-")); if (detailed) { table.addCell(taskInfo.getDescription());