---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "foo"
      body:
        mappings:
          properties:
            the_field:
              type: "date"
            value_field:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "foo2"
      body:
        mappings:
          properties:
            the_field:
              type: "date"
            value_field:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "foo3"
      body:
        mappings:
          properties:
            the_field:
              type: "date"
            value_field:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "dummy-rollup-index"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
        mappings:
          _meta:
            _rollup:
              my-id: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"the_field\",\n      \"calendar_interval\"\
        : \"1h\"\n    }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"value_field\"\
        ,\n      \"metrics\": [\"min\", \"max\", \"sum\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.delete:
      index: "dummy-rollup-index"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Verify one job caps:
- do:
    rollup.get_rollup_caps:
      id: "foo"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    foo:
      rollup_jobs:
      - job_id: "foo"
        rollup_index: "foo_rollup"
        index_pattern: "foo"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
---
Verify two job caps:
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo2"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"the_field\",\n      \"calendar_interval\"\
        : \"1h\"\n    }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"value_field\"\
        ,\n      \"metrics\": [\"min\", \"max\", \"sum\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.get_rollup_caps:
      id: "foo"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    foo:
      rollup_jobs:
      - job_id: "foo"
        rollup_index: "foo_rollup"
        index_pattern: "foo"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
      - job_id: "foo2"
        rollup_index: "foo_rollup"
        index_pattern: "foo"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
---
Verify all caps:
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo2"
      body: "{\n  \"index_pattern\": \"foo2\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"the_field\",\n      \"calendar_interval\"\
        : \"1h\"\n    }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"value_field\"\
        ,\n      \"metrics\": [\"min\", \"max\", \"sum\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo3"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"different_index\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"the_field\",\n      \"calendar_interval\"\
        : \"1h\"\n    }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"value_field\"\
        ,\n      \"metrics\": [\"min\", \"max\", \"sum\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.get_rollup_caps:
      id: "_all"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    foo:
      rollup_jobs:
      - job_id: "foo"
        rollup_index: "foo_rollup"
        index_pattern: "foo"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
      - job_id: "foo3"
        rollup_index: "different_index"
        index_pattern: "foo"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
- match:
    foo2:
      rollup_jobs:
      - job_id: "foo2"
        rollup_index: "foo_rollup"
        index_pattern: "foo2"
        fields:
          the_field:
          - agg: "date_histogram"
            calendar_interval: "1h"
            time_zone: "UTC"
          value_field:
          - agg: "min"
          - agg: "max"
          - agg: "sum"
