---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "esql.metrics_counter_fields"
    reason: "require metrics counter fields"
    test_runner_features: "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "metricset"
            - "k8s.pod.uid"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            metricset:
              type: "keyword"
              time_series_dimension: true
            k8s:
              properties:
                pod:
                  properties:
                    uid:
                      type: "keyword"
                      time_series_dimension: true
                    name:
                      type: "keyword"
                    ip:
                      type: "ip"
                    network:
                      properties:
                        tx:
                          type: "long"
                          time_series_metric: "counter"
                        rx:
                          type: "integer"
                          time_series_metric: "counter"
    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:
    bulk:
      refresh: true
      index: "test"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:04.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2001818691, \"rx\": 802133794}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:24.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2005177954, \"rx\": 801479970}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:44.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2006223737, \"rx\": 802337279}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:51:04.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.2\", \"network\": {\"tx\": 2012916202, \"rx\": 803685721}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434521831, \"rx\": 530575198}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:23.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434577921, \"rx\": 530600088}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:53.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434587694, \"rx\": 530604797}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:51:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434595272, \"rx\": 530605511}}}}"
    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: "test2"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "dim"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            dim:
              type: "keyword"
              time_series_dimension: true
            agg_metric:
              type: "aggregate_metric_double"
              metrics:
              - "min"
              - "max"
              - "sum"
              - "value_count"
              default_metric: "max"
            k8s:
              properties:
                pod:
                  properties:
                    ip:
                      type: "ip"
                    network:
                      properties:
                        tx:
                          type: "long"
    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:
    bulk:
      refresh: true
      index: "test2"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:04.467Z\", \"dim\": \"A\", \"agg_metric\"\
        : {\"max\": 10, \"min\": -1, \"sum\": 20, \"value_count\": 5}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:24.467Z\", \"dim\": \"B\", \"agg_metric\"\
        : {\"max\": 20, \"min\": 3, \"sum\": 50, \"value_count\": 7}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:44.467Z\", \"dim\": \"B\", \"agg_metric\"\
        : {\"max\": 17, \"min\": -5, \"sum\": 33, \"value_count\": 9}}"
    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: "test3"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "k8s.pod.uid"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            agg_metric:
              type: "aggregate_metric_double"
              metrics:
              - "min"
              - "max"
              default_metric: "min"
            k8s:
              properties:
                pod:
                  properties:
                    uid:
                      type: "keyword"
                      time_series_dimension: true
    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:
    bulk:
      refresh: true
      index: "test3"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T19:50:04.467Z\", \"agg_metric\": {\"max\":\
        \ 1, \"min\": -3}, \"k8s\": {\"pod\": {\"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        }}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T19:50:24.467Z\", \"agg_metric\": {\"max\":\
        \ 10, \"min\": 3}, \"k8s\": {\"pod\": {\"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        }}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T19:50:44.467Z\", \"agg_metric\": {\"max\":\
        \ 17, \"min\": 2}, \"k8s\": {\"pod\": {\"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        }}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T19:51:04.467Z\", \"k8s\": {\"pod\": {\"uid\"\
        :\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"}}}"
    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: "test4"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "k8s.pod.uid"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            agg_metric:
              type: "aggregate_metric_double"
              metrics:
              - "sum"
              - "value_count"
              default_metric: "sum"
            k8s:
              properties:
                pod:
                  properties:
                    uid:
                      type: "keyword"
                      time_series_dimension: true
    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:
    bulk:
      refresh: true
      index: "test4"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T23:50:04.467Z\", \"agg_metric\": {\"sum\":\
        \ 1, \"value_count\": 10}, \"k8s\": {\"pod\": {\"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        }}}"
    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"
---
load everything:
- requires:
    cluster_features:
    - "gte_v8.13.0"
    reason: "_source is available in 8.13+"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "from test metadata _id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "@timestamp"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "k8s.pod.ip"
- match:
    columns.1.type: "ip"
- match:
    columns.2.name: "k8s.pod.name"
- match:
    columns.2.type: "keyword"
- match:
    columns.3.name: "k8s.pod.network.rx"
- match:
    columns.3.type: "counter_integer"
- match:
    columns.4.name: "k8s.pod.network.tx"
- match:
    columns.4.type: "counter_long"
- match:
    columns.5.name: "k8s.pod.uid"
- match:
    columns.5.type: "keyword"
- match:
    columns.6.name: "metricset"
- match:
    columns.6.type: "keyword"
- length:
    values: 8
---
load a document:
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "from test | where @timestamp == \"2021-04-28T18:50:23.142Z\""
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 7
- match:
    values.0.0: "2021-04-28T18:50:23.142Z"
- match:
    values.0.1: "10.10.55.3"
- match:
    values.0.2: "dog"
- match:
    values.0.3: 530600088
- match:
    values.0.4: 1434577921
- match:
    values.0.5: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"
- match:
    values.0.6: "pod"
---
filter on counter without cast:
- do:
    catch: "bad_request"
    esql.query:
      body:
        query: "from test | where k8s.pod.network.tx == 1434577921"
    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"
---
cast counter then filter:
- do:
    esql.query:
      body:
        query: "from test | where k8s.pod.network.tx::long == 2005177954 and k8s.pod.network.rx::integer\
          \ == 801479970 | sort @timestamp | limit 10"
    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"
- length:
    values: 1
- length:
    values.0: 7
- match:
    values.0.0: "2021-04-28T18:50:24.467Z"
- match:
    values.0.1: "10.10.55.1"
- match:
    values.0.2: "cat"
- match:
    values.0.3: 801479970
- match:
    values.0.4: 2005177954
- match:
    values.0.5: "947e4ced-1786-4e53-9e0c-5c447e959507"
- match:
    values.0.6: "pod"
---
sort on counter without cast:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "sorting_on_source_and_counters_forbidden"
    reason: "Sorting on counters shouldn't have been possible"
- do:
    catch: "/cannot sort on counter_long/"
    esql.query:
      body:
        query: "from test |  KEEP k8s.pod.network.tx | sort k8s.pod.network.tx | limit\
          \ 1"
    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"
---
cast then sort on counter:
- do:
    esql.query:
      body:
        query: "from test | KEEP k8s.pod.network.tx | EVAL tx=to_long(k8s.pod.network.tx)\
          \ | sort tx | limit 1"
    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"
- length:
    values: 1
- match:
    values.0.0: 1434521831
---
from doc with aggregate_metric_double:
- skip:
    awaits_fix: "TODO: support for subset of metric fields"
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double"
    reason: "Support for aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "from test2"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "@timestamp"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "agg_metric"
- match:
    columns.1.type: "aggregate_metric_double"
- match:
    columns.2.name: "dim"
- match:
    columns.2.type: "keyword"
- match:
    columns.3.name: "k8s.pod.ip"
- match:
    columns.3.type: "ip"
- match:
    columns.4.name: "k8s.pod.network.tx"
- match:
    columns.4.type: "long"
- length:
    values: 3
---
stats on aggregate_metric_double:
- skip:
    awaits_fix: "TODO: support for subset of metric fields"
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double"
    reason: "Support for aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test2 | STATS max(agg_metric), min(agg_metric), sum(agg_metric),\
          \ count(agg_metric)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 4
- match:
    columns.0.name: "max(agg_metric)"
- match:
    columns.0.type: "double"
- match:
    columns.1.name: "min(agg_metric)"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "sum(agg_metric)"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "count(agg_metric)"
- match:
    columns.3.type: "long"
- match:
    values.0.0: 20.0
- match:
    values.0.1: -5.0
- match:
    values.0.2: 103.0
- match:
    values.0.3: 21.0
---
grouping stats on aggregate_metric_double:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double"
    reason: "Support for aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test2 | STATS max(agg_metric), min(agg_metric), sum(agg_metric),\
          \ count(agg_metric) BY dim | SORT dim"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 2
- length:
    values.0: 5
- match:
    columns.0.name: "max(agg_metric)"
- match:
    columns.0.type: "double"
- match:
    columns.1.name: "min(agg_metric)"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "sum(agg_metric)"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "count(agg_metric)"
- match:
    columns.3.type: "long"
- match:
    columns.4.name: "dim"
- match:
    columns.4.type: "keyword"
- match:
    values.0.0: 10.0
- match:
    values.0.1: -1.0
- match:
    values.0.2: 20.0
- match:
    values.0.3: 5.0
- match:
    values.0.4: "A"
- match:
    values.1.0: 20.0
- match:
    values.1.1: -5.0
- match:
    values.1.2: 83.0
- match:
    values.1.3: 16.0
- match:
    values.1.4: "B"
---
sorting with aggregate_metric_double with partial submetrics:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_sorting"
    reason: "Support for sorting when aggregate_metric_double present"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test3 | SORT @timestamp | KEEP @timestamp, agg_metric"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 4
- length:
    values.0: 2
- match:
    columns.0.name: "@timestamp"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "agg_metric"
- match:
    columns.1.type: "aggregate_metric_double"
- match:
    values.0.0: "2021-04-28T19:50:04.467Z"
- match:
    values.1.0: "2021-04-28T19:50:24.467Z"
- match:
    values.2.0: "2021-04-28T19:50:44.467Z"
- match:
    values.3.0: "2021-04-28T19:51:04.467Z"
- match:
    values.0.1: "{\"min\":-3.0,\"max\":1.0}"
- match:
    values.1.1: "{\"min\":3.0,\"max\":10.0}"
- match:
    values.2.1: "{\"min\":2.0,\"max\":17.0}"
- match:
    values.3.1: null
---
aggregate_metric_double unsortable:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_sorting"
    reason: "Support for sorting when aggregate_metric_double present"
- do:
    catch: "/cannot sort on aggregate_metric_double/"
    esql.query:
      body:
        query: "FROM test2 | sort agg_metric"
    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"
---
stats on aggregate_metric_double with partial submetrics:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_partial_submetrics"
    reason: "Support for partial submetrics in aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test3 | STATS max(agg_metric), min(agg_metric), sum(agg_metric),\
          \ count(agg_metric) BY k8s.pod.uid | SORT k8s.pod.uid"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 2
- length:
    values.0: 5
- match:
    columns.0.name: "max(agg_metric)"
- match:
    columns.0.type: "double"
- match:
    columns.1.name: "min(agg_metric)"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "sum(agg_metric)"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "count(agg_metric)"
- match:
    columns.3.type: "long"
- match:
    columns.4.name: "k8s.pod.uid"
- match:
    columns.4.type: "keyword"
- match:
    values.0.0: 10.0
- match:
    values.0.1: -3.0
- match:
    values.0.2: null
- match:
    values.0.3: null
- match:
    values.0.4: "947e4ced-1786-4e53-9e0c-5c447e959507"
- match:
    values.1.0: 17.0
- match:
    values.1.1: 2.0
- match:
    values.1.2: null
- match:
    values.1.3: null
- match:
    values.1.4: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"
---
stats on aggregate_metric_double missing min and max:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_partial_submetrics"
    reason: "Support for partial submetrics in aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test4 | STATS max(agg_metric), min(agg_metric), sum(agg_metric),\
          \ count(agg_metric)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 4
- match:
    columns.0.name: "max(agg_metric)"
- match:
    columns.0.type: "double"
- match:
    columns.1.name: "min(agg_metric)"
- match:
    columns.1.type: "double"
- match:
    columns.2.name: "sum(agg_metric)"
- match:
    columns.2.type: "double"
- match:
    columns.3.name: "count(agg_metric)"
- match:
    columns.3.type: "long"
- match:
    values.0.0: null
- match:
    values.0.1: null
- match:
    values.0.2: 1.0
- match:
    values.0.3: 10
---
render aggregate_metric_double when missing min and max:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_rendering"
    reason: "Support for rendering aggregate_metric_doubles"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test4 | KEEP agg_metric"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 1
- match:
    columns.0.name: "agg_metric"
- match:
    columns.0.type: "aggregate_metric_double"
- match:
    values.0.0: "{\"sum\":1.0,\"value_count\":10}"
---
render aggregate_metric_double when missing value:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_rendering"
    reason: "Support for rendering aggregate_metric_doubles"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test3 | WHERE @timestamp == \"2021-04-28T19:51:04.467Z\" | KEEP\
          \ agg_metric"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 1
- match:
    columns.0.name: "agg_metric"
- match:
    columns.0.type: "aggregate_metric_double"
- match:
    values.0.0: null
---
to_string aggregate_metric_double:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_rendering"
    reason: "Support for rendering aggregate_metric_doubles"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test4 | EVAL agg = to_string(agg_metric) | KEEP agg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 1
- match:
    columns.0.name: "agg"
- match:
    columns.0.type: "keyword"
- match:
    values.0.0: "{\"sum\":1.0,\"value_count\":10}"
---
from index pattern unsupported counter:
- skip:
    awaits_fix: "TODO: support for subset of metric fields"
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_partial_submetrics"
    reason: "Support for partial submetrics in aggregate_metric_double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test*"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "@timestamp"
- match:
    columns.0.type: "date"
- match:
    columns.1.name: "agg_metric"
- match:
    columns.1.type: "aggregate_metric_double"
- match:
    columns.2.name: "dim"
- match:
    columns.2.type: "keyword"
- match:
    columns.3.name: "k8s.pod.ip"
- match:
    columns.3.type: "ip"
- match:
    columns.4.name: "k8s.pod.name"
- match:
    columns.4.type: "keyword"
- match:
    columns.5.name: "k8s.pod.network.rx"
- match:
    columns.5.type: "counter_integer"
- match:
    columns.6.name: "k8s.pod.network.tx"
- match:
    columns.6.type: "unsupported"
- match:
    columns.7.name: "k8s.pod.uid"
- match:
    columns.7.type: "keyword"
- match:
    columns.8.name: "metricset"
- match:
    columns.8.type: "keyword"
- length:
    values: 16
---
from index pattern explicit counter use:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "union_types_fix_rename_resolution"
    reason: "Union type resolution fix for rename also allows direct usage of unsupported\
      \ fields in KEEP"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test* | keep *.tx"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "k8s.pod.network.tx"
- match:
    columns.0.type: "unsupported"
- length:
    values: 16
---
_source:
- requires:
    cluster_features:
    - "gte_v8.13.0"
    reason: "_source is available in 8.13+"
- do:
    bulk:
      index: "test"
      refresh: true
      body:
      - index:
          _index: "test"
          _id: "id-1"
      - wow: 1
        such: "_source"
        you'd: "never"
        expect:
        - "amazing"
        - "source"
    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:
    esql.query:
      body:
        query: "FROM test METADATA _source | WHERE @timestamp == \"2021-04-28T18:50:23.142Z\"\
          \ | KEEP _source | LIMIT 1"
    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:
    columns.0.name: "_source"
- match:
    columns.0.type: "_source"
- length:
    values: 1
- match:
    values.0.0:
      '@timestamp': "2021-04-28T18:50:23.142Z"
      metricset: "pod"
      k8s:
        pod:
          ip: "10.10.55.3"
          name: "dog"
          network:
            rx: 530600088
            tx: 1434577921
          uid: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"
---
to_aggregate_metric_double with multi_values:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_convert_to"
    reason: "Support for to_aggregate_metric_double function"
- do:
    indices.create:
      index: "convert_test"
      body:
        mappings:
          properties:
            some_long_field:
              type: "long"
            some_double_field:
              type: "double"
            some_int_field:
              type: "integer"
            some_unsigned_long_field:
              type: "unsigned_long"
    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:
    bulk:
      refresh: true
      index: "new_test"
      body:
      - index: {}
      - some_long_field:
        - 20385
        - 182941
        - -10958
        some_double_field:
        - 195.1
        - 102.444
        some_int_field:
        - 64
        - 121
        - 498
        - 1456
        some_unsigned_long_field:
        - 13985
        - 19418924
        - 123
    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:
    esql.query:
      body:
        query: "FROM new_test | EVAL from_long=TO_AGGREGATE_METRIC_DOUBLE(some_long_field),\
          \ from_double=TO_AGGREGATE_METRIC_DOUBLE(some_double_field), from_int=TO_AGGREGATE_METRIC_DOUBLE(some_int_field),\
          \ from_ulong=TO_AGGREGATE_METRIC_DOUBLE(some_unsigned_long_field) | KEEP\
          \ from_long, from_double, from_int, from_ulong | LIMIT 1"
    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:
    columns.0.name: "from_long"
- match:
    columns.0.type: "aggregate_metric_double"
- match:
    columns.1.name: "from_double"
- match:
    columns.1.type: "aggregate_metric_double"
- match:
    columns.2.name: "from_int"
- match:
    columns.2.type: "aggregate_metric_double"
- match:
    columns.3.name: "from_ulong"
- match:
    columns.3.type: "aggregate_metric_double"
- match:
    values.0.0: "{\"min\":-10958.0,\"max\":182941.0,\"sum\":192368.0,\"value_count\"\
      :3}"
- match:
    values.0.1: "{\"min\":102.44400024414062,\"max\":195.10000610351562,\"sum\":297.54400634765625,\"\
      value_count\":2}"
- match:
    values.0.2: "{\"min\":64.0,\"max\":1456.0,\"sum\":2139.0,\"value_count\":4}"
- match:
    values.0.3: "{\"min\":123.0,\"max\":1.9418924E7,\"sum\":1.9433032E7,\"value_count\"\
      :3}"
---
avg of aggregate_metric_double:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "aggregate_metric_double_avg"
    reason: "support avg aggregations with aggregate metric double"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test2 | STATS avg = avg(agg_metric) | KEEP avg"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- length:
    values: 1
- length:
    values.0: 1
- match:
    columns.0.name: "avg"
- match:
    columns.0.type: "double"
- match:
    values.0.0: 4.904761904761905
