Browse Source

Allowing {index}/_xpack/rollup/data to accept comma delimited list (#34115)

* Allowing `{index}/_xpack/rollup/data` to accept comma delimited list

* Address PR comments
Benjamin Trent 7 years ago
parent
commit
10201e06cb

+ 3 - 1
x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java

@@ -8,6 +8,7 @@ package org.elasticsearch.xpack.rollup.rest;
 import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.client.node.NodeClient;
 import org.elasticsearch.client.node.NodeClient;
 import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestController;
 import org.elasticsearch.rest.RestController;
@@ -27,7 +28,8 @@ public class RestGetRollupIndexCapsAction extends BaseRestHandler {
     protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) {
     protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) {
         String index = restRequest.param(INDEX.getPreferredName());
         String index = restRequest.param(INDEX.getPreferredName());
         IndicesOptions options = IndicesOptions.fromRequest(restRequest, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED);
         IndicesOptions options = IndicesOptions.fromRequest(restRequest, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED);
-        GetRollupIndexCapsAction.Request request = new GetRollupIndexCapsAction.Request(new String[]{index}, options);
+        GetRollupIndexCapsAction.Request request =
+            new GetRollupIndexCapsAction.Request(Strings.splitStringByCommaToArray(index), options);
         return channel -> client.execute(GetRollupIndexCapsAction.INSTANCE, request, new RestToXContentListener<>(channel));
         return channel -> client.execute(GetRollupIndexCapsAction.INSTANCE, request, new RestToXContentListener<>(channel));
     }
     }
 
 

+ 103 - 0
x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/get_rollup_index_caps.yml

@@ -288,6 +288,109 @@ setup:
                   - agg: "max"
                   - agg: "max"
                   - agg: "sum"
                   - agg: "sum"
 
 
+---
+"Verify job caps by rollup index comma delimited list":
+
+- skip:
+    version: " - 6.99.99"
+    reason: "comma delimited index support was fixed in 7.0"
+
+- do:
+    headers:
+      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
+    xpack.rollup.put_job:
+      id: foo2
+      body:  >
+        {
+          "index_pattern": "foo2",
+          "rollup_index": "foo_rollup",
+          "cron": "*/30 * * * * ?",
+          "page_size" :10,
+          "groups" : {
+            "date_histogram": {
+              "field": "the_field",
+              "interval": "1h"
+            }
+          },
+          "metrics": [
+            {
+              "field": "value_field",
+              "metrics": ["min", "max", "sum"]
+            }
+          ]
+        }
+- do:
+    headers:
+      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
+    xpack.rollup.put_job:
+      id: foo3
+      body:  >
+        {
+          "index_pattern": "foo3",
+          "rollup_index": "foo_rollup2",
+          "cron": "*/30 * * * * ?",
+          "page_size" :10,
+          "groups" : {
+            "date_histogram": {
+              "field": "the_field",
+              "interval": "1h"
+            }
+          },
+          "metrics": [
+            {
+              "field": "value_field",
+              "metrics": ["min", "max", "sum"]
+            }
+          ]
+        }
+
+- do:
+    xpack.rollup.get_rollup_index_caps:
+      index: "foo_rollup2,foo_rollup"
+
+- match:
+    $body:
+      foo_rollup:
+        rollup_jobs:
+        - job_id: "foo"
+          rollup_index: "foo_rollup"
+          index_pattern: "foo"
+          fields:
+            the_field:
+            - agg: "date_histogram"
+              interval: "1h"
+              time_zone: "UTC"
+            value_field:
+            - agg: "min"
+            - agg: "max"
+            - agg: "sum"
+        - job_id: "foo2"
+          rollup_index: "foo_rollup"
+          index_pattern: "foo2"
+          fields:
+            the_field:
+            - agg: "date_histogram"
+              interval: "1h"
+              time_zone: "UTC"
+            value_field:
+            - agg: "min"
+            - agg: "max"
+            - agg: "sum"
+      foo_rollup2:
+        rollup_jobs:
+        - job_id: "foo3"
+          rollup_index: "foo_rollup2"
+          index_pattern: "foo3"
+          fields:
+            the_field:
+            - agg: "date_histogram"
+              interval: "1h"
+              time_zone: "UTC"
+            value_field:
+            - agg: "min"
+            - agg: "max"
+            - agg: "sum"
+
 ---
 ---
 "Verify index pattern":
 "Verify index pattern":