From ffe1b02cb12c0c1892580070d33a8afb398fc402 Mon Sep 17 00:00:00 2001 From: markharwood Date: Wed, 30 May 2018 12:00:28 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Add=20=E2=80=9Ctook=E2=80=9D=20timing=20inf?= =?UTF-8?q?o=20to=20response=20for=20=5Fmsearch/template=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #30957 --- .../mustache/MultiSearchTemplateResponse.java | 22 +++++++++++++++++-- .../TransportMultiSearchTemplateAction.java | 2 +- .../mustache/MultiSearchTemplateIT.java | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateResponse.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateResponse.java index 37d72ac4c0d04..b5bc86679aed4 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateResponse.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateResponse.java @@ -20,12 +20,14 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -107,12 +109,14 @@ public Exception getFailure() { } private Item[] items; - + private long tookInMillis; + MultiSearchTemplateResponse() { } - public MultiSearchTemplateResponse(Item[] items) { + public MultiSearchTemplateResponse(Item[] items, long tookInMillis) { this.items = items; + this.tookInMillis = tookInMillis; } @Override @@ -126,6 +130,13 @@ public Iterator iterator() { public Item[] getResponses() { return this.items; } + + /** + * How long the msearch_template took. + */ + public TimeValue getTook() { + return new TimeValue(tookInMillis); + } @Override public void readFrom(StreamInput in) throws IOException { @@ -134,6 +145,9 @@ public void readFrom(StreamInput in) throws IOException { for (int i = 0; i < items.length; i++) { items[i] = Item.readItem(in); } + if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + tookInMillis = in.readVLong(); + } } @Override @@ -143,11 +157,15 @@ public void writeTo(StreamOutput out) throws IOException { for (Item item : items) { item.writeTo(out); } + if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + out.writeVLong(tookInMillis); + } } @Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); + builder.field("took", tookInMillis); builder.startArray(Fields.RESPONSES); for (Item item : items) { if (item.isFailure()) { diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java index 167190d8f5d04..15cfc626fba3b 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java @@ -94,7 +94,7 @@ protected void doExecute(MultiSearchTemplateRequest request, ActionListener Date: Wed, 30 May 2018 15:48:38 +0100 Subject: [PATCH 2/2] Checkstyle fix --- .../elasticsearch/script/mustache/MultiSearchTemplateIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java index ed737534e44d1..c3ec5ae1784a9 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java @@ -141,7 +141,7 @@ public void testBasic() throws Exception { MultiSearchTemplateResponse response = client().execute(MultiSearchTemplateAction.INSTANCE, multiRequest).get(); assertThat(response.getResponses(), arrayWithSize(5)); - assertThat(response.getTook().millis(), greaterThan(0l)); + assertThat(response.getTook().millis(), greaterThan(0L)); MultiSearchTemplateResponse.Item response1 = response.getResponses()[0]; assertThat(response1.isFailure(), is(false));