From 56be936acedbac226392a143f09f5c197b0af794 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 18 Aug 2016 11:41:21 +0200 Subject: [PATCH] Watcher: Use search template in Search Input/Transform REST tests These tests would have caught the regression (introduced in elastic/x-pack@95a29c6a42ada331d325e029d4795f0499e2f08a and fixed by elastic/x-pack@9b834b5f509e7ceeb2426d676e15105d92329657) that cause search template to have "groovy" lang by default instead of "mustache" Original commit: elastic/x-pack-elasticsearch@e27e5ae821803fd440049af0c97065b2c88a1652 --- .../build.gradle | 2 + .../watcher_mustache/30_search_input.yaml | 161 ++++++++++++++++++ ...ransform.yaml => 40_search_transform.yaml} | 91 +++++----- 3 files changed, 203 insertions(+), 51 deletions(-) create mode 100644 elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input.yaml rename elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/{30_search_input_and_transform.yaml => 40_search_transform.yaml} (77%) diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/build.gradle b/elasticsearch/qa/smoke-test-watcher-with-mustache/build.gradle index 180295f0419..a6d0bcee740 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/build.gradle +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/build.gradle @@ -11,5 +11,7 @@ integTest { setting 'xpack.security.enabled', 'false' setting 'xpack.monitoring.enabled', 'false' setting 'http.port', '9400' + setting 'script.inline', 'true' + setting 'script.stored', 'true' } } diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input.yaml b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input.yaml new file mode 100644 index 00000000000..24ceb3fcd3d --- /dev/null +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input.yaml @@ -0,0 +1,161 @@ +--- +setup: + - do: + cluster.health: + wait_for_status: yellow + - do: {xpack.watcher.stats:{}} + - do: + index: + index: idx + type: type + id: 1 + body: > + { + "date" : "2015-01-01T00:00:00", + "value" : "val_1" + } + - do: + index: + index: idx + type: type + id: 2 + body: > + { + "date" : "2015-01-02T00:00:00", + "value" : "val_2" + } + - do: + index: + index: idx + type: type + id: 3 + body: > + { + "date" : "2015-01-03T00:00:00", + "value" : "val_3" + } + - do: + index: + index: idx + type: type + id: 4 + body: > + { + "date" : "2015-01-04T00:00:00", + "value" : "val_4" + } + - do: + indices.refresh: + index: idx + +--- +"Test search input mustache integration (using request body)": + - do: + xpack.watcher.execute_watch: + body: > + { + "trigger_data" : { + "scheduled_time" : "2015-01-04T00:00:00" + }, + "watch" : { + "trigger" : { "schedule" : { "interval" : "10s" } }, + "actions" : { + "dummy" : { + "logging" : { + "text" : "executed!" + } + } + }, + "input" : { + "search" : { + "request" : { + "indices" : "idx", + "body" : { + "query" : { + "bool" : { + "filter" : [ + { + "range" : { + "date" : { + "lte" : "{{ctx.trigger.scheduled_time}}", + "gte" : "{{ctx.trigger.scheduled_time}}||-3d" + } + } + } + ] + } + } + } + } + } + } + } + } + - match: { "watch_record.result.input.type": "search" } + - match: { "watch_record.result.input.status": "success" } + - match: { "watch_record.result.input.payload.hits.total": 4 } + # makes sure that the mustache template snippets have been resolved correctly: + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-3d" } + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } + +--- +"Test search input mustache integration (using request template)": + + - do: + put_template: + id: "search-template" + body: { + "query" : { + "bool" : { + "must" : [ + { + "term" : { + "value" : "val_{{num}}" + } + } + ] + } + } + } + - match: { acknowledged: true } + + - do: + xpack.watcher.execute_watch: + body: > + { + "trigger_data" : { + "scheduled_time" : "2015-01-04T00:00:00" + }, + "watch" : { + "trigger" : { "schedule" : { "interval" : "10s" } }, + "actions" : { + "dummy" : { + "logging" : { + "text" : "executed!" + } + } + }, + "input" : { + "search" : { + "request" : { + "indices" : "idx", + "template" : { + "id": "search-template", + "params": { + "num": 2 + } + } + } + } + } + } + } + - match: { "watch_record.result.input.type": "search" } + - match: { "watch_record.result.input.status": "success" } + - match: { "watch_record.result.input.payload.hits.total": 1 } + - match: { "watch_record.result.input.payload.hits.hits.0._id": "2" } + # makes sure that the mustache template snippets have been resolved correctly: + - match: { "watch_record.result.input.search.request.body.query.bool.must.0.term.value": "val_2" } + - match: { "watch_record.result.input.search.request.template.id": "search-template" } + - match: { "watch_record.result.input.search.request.template.lang": "mustache" } + - match: { "watch_record.result.input.search.request.template.params.num": 2 } diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input_and_transform.yaml b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/40_search_transform.yaml similarity index 77% rename from elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input_and_transform.yaml rename to elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/40_search_transform.yaml index 5f8e99e96ce..2f582e8bd42 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/30_search_input_and_transform.yaml +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/resources/rest-api-spec/test/watcher_mustache/40_search_transform.yaml @@ -49,57 +49,7 @@ setup: index: idx --- -"Test input mustache integration": - - do: - xpack.watcher.execute_watch: - body: > - { - "trigger_data" : { - "scheduled_time" : "2015-01-04T00:00:00" - }, - "watch" : { - "trigger" : { "schedule" : { "interval" : "10s" } }, - "actions" : { - "dummy" : { - "logging" : { - "text" : "executed!" - } - } - }, - "input" : { - "search" : { - "request" : { - "indices" : "idx", - "body" : { - "query" : { - "bool" : { - "filter" : [ - { - "range" : { - "date" : { - "lte" : "{{ctx.trigger.scheduled_time}}", - "gte" : "{{ctx.trigger.scheduled_time}}||-3d" - } - } - } - ] - } - } - } - } - } - } - } - } - - match: { "watch_record.result.input.type": "search" } - - match: { "watch_record.result.input.status": "success" } - - match: { "watch_record.result.input.payload.hits.total": 4 } - # makes sure that the mustache template snippets have been resolved correctly: - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-3d" } - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } - ---- -"Test transform mustache integration": +"Test search transform mustache integration (using request body)": - do: xpack.watcher.execute_watch: body: > @@ -155,3 +105,42 @@ setup: - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-1d" } - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } - match: { "watch_record.result.transform.search.request.body.query.bool.filter.1.term.value": "val_3" } + +--- +"Test search transform mustache integration (using request template)": + - do: + xpack.watcher.execute_watch: + body: > + { + "trigger_data" : { + "scheduled_time" : "2015-01-04T00:00:00" + }, + "watch" : { + "trigger" : { "schedule" : { "interval" : "10s" } }, + "input" : { "simple" : { "number" : 2 } }, + "actions" : { + "dummy" : { + "logging" : { + "text" : "executed!" + } + } + }, + "transform" : { + "search" : { + "request" : { + "indices" : "idx", + "template" : { + "inline" : "{\"query\": {\"bool\" : { \"must\": [{\"term\": {\"value\": \"val_{{ctx.payload.number}}\"}}]}}}" + } + } + } + } + } + } + - match: { "watch_record.result.transform.type": "search" } + - match: { "watch_record.result.transform.status": "success" } + - match: { "watch_record.result.transform.payload.hits.total": 1 } + - match: { "watch_record.result.transform.payload.hits.hits.0._id": "2" } + # makes sure that the mustache template snippets have been resolved correctly: + - match: { "watch_record.result.transform.search.request.body.query.bool.must.0.term.value": "val_2" } + - match: { "watch_record.result.transform.search.request.template.lang": "mustache" }