---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "airline-data"
      body:
        mappings:
          properties:
            time:
              type: "date"
            airline:
              type: "keyword"
            responsetime:
              type: "float"
            event_rate:
              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: "airline-data-other"
      body:
        mappings:
          properties:
            time:
              type: "date"
            airline:
              type: "keyword"
            responsetime:
              type: "float"
            event_rate:
              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:
    transform.put_transform:
      transform_id: "airline-transform-stats"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"airline-data-by-airline\" },\n  \"pivot\": {\n    \"group_by\": { \"airline\"\
        : {\"terms\": {\"field\": \"airline\"}}},\n    \"aggs\": {\"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}}}\n  }\n}\n"
    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:
    transform.put_transform:
      transform_id: "airline-transform-latest"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"airline-data-latest\" },\n  \"latest\": {\n    \"unique_key\": [ \"airline\"\
        \ ],\n    \"sort\": \"time\"\n  }\n}\n"
    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:
    index:
      index: "airline-data"
      id: "1"
      body: "{\n  \"time\": \"2017-02-18T00:00:00Z\",\n  \"airline\": \"airline1\"\
        ,\n  \"responsetime\": 1.0,\n  \"event_rate\": 5\n}\n"
    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:
    index:
      index: "airline-data"
      id: "2"
      body: "{\n  \"time\": \"2017-02-18T00:30:00Z\",\n  \"airline\": \"airline1\"\
        ,\n  \"responsetime\": 1.0,\n  \"event_rate\": 6\n}\n"
    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:
    index:
      index: "airline-data"
      id: "3"
      body: "{\n  \"time\": \"2017-02-18T01:00:00Z\",\n  \"airline\": \"airline2\"\
        ,\n  \"responsetime\": 42.0,\n  \"event_rate\": 8\n}\n"
    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:
    index:
      index: "airline-data"
      id: "4"
      body: "{\n  \"time\": \"2017-02-18T01:01:00Z\",\n  \"airline\": \"airline1\"\
        ,\n  \"responsetime\": 42.0,\n  \"event_rate\": 7\n}\n"
    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.refresh:
      index: "airline-data"
    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"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    transform.delete_transform:
      transform_id: "airline-transform-stats"
    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:
    transform.delete_transform:
      transform_id: "airline-transform-latest"
    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"
---
Test cat transform stats hiding headers:
- do:
    cat.transforms:
      transform_id: "airline-transform-*"
    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:
    $body: "/^  #id                           \\s+ state   \\s+ checkpoint \\s+ documents_processed\
      \ \\s+ checkpoint_progress \\s+ last_search_time \\s+ changes_last_detection_time\
      \ \\n\n    (airline\\-transform\\-latest   \\s+ stopped \\s+ 0          \\s+\
      \ 0                   \\s+                     \\s+                  \\s+  \
      \                           \\n)+\n    (airline\\-transform\\-stats    \\s+\
      \ stopped \\s+ 0          \\s+ 0                   \\s+                    \
      \ \\s+                  \\s+                             \\n)+  $/\n"
---
Test cat transform stats with column selection:
- do:
    cat.transforms:
      transform_id: "airline-transform-*"
      v: true
      h: "id,version,source_index,dest_index,search_total,index_total,docp,cdtea,indexed_documents_exp_avg"
    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:
    $body: "/^   id                         \\s+ version \\s+ source_index \\s+ dest_index\
      \              \\s+ search_total \\s+ index_total \\s+ docp \\s+ cdtea  \\s+\
      \ indexed_documents_exp_avg \\n\n    (airline\\-transform-latest  \\s+ [^\\\
      s]+  \\s+ airline-data \\s+ airline-data-latest     \\s+ 0            \\s+ 0\
      \           \\s+ 0    \\s+ 0.00   \\s+ 0.00                      \\n)+\n   \
      \ (airline\\-transform-stats   \\s+ [^\\s]+  \\s+ airline-data \\s+ airline-data-by-airline\
      \ \\s+ 0            \\s+ 0           \\s+ 0    \\s+ 0.00   \\s+ 0.00       \
      \               \\n)+  $/\n"
---
Test cat transform stats with batch transform:
- skip:
    awaits_fix: "https://github.com/elastic/elasticsearch/issues/68350"
- do:
    transform.put_transform:
      transform_id: "airline-transform-batch"
      body: "{\n  \"source\": {\n    \"index\": [\"airline-data\", \"airline-data-other\"\
        ],\n    \"query\": {\"bool\":{\"filter\":{\"term\":{\"airline\":\"airline1\"\
        }}}}\n  },\n  \"dest\": { \"index\": \"airline-data-by-airline-batch\" },\n\
        \  \"pivot\": {\n    \"group_by\": { \"airline\": {\"terms\": {\"field\":\
        \ \"airline\"}}},\n    \"aggs\": {\"avg_response\": {\"avg\": {\"field\":\
        \ \"responsetime\"}}}\n  },\n  \"description\": \"description\"\n}\n"
    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:
    cat.transforms:
      transform_id: "airline-transform-batch"
      v: true
    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:
    $body: "/^   id                         \\s+ state   \\s+ checkpoint \\s+ documents_processed\
      \ \\s+ checkpoint_progress \\s+ last_search_time \\s+ changes_last_detection_time\
      \ \\n\n    (airline\\-transform\\-batch  \\s+ stopped \\s+ 0          \\s+ 0\
      \                   \\s+                     \\s+                  \\s+    \
      \                         \\n)+  $/\n"
- do:
    transform.start_transform:
      transform_id: "airline-transform-batch"
    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:
    acknowledged: true
- do:
    transform.stop_transform:
      wait_for_checkpoint: true
      transform_id: "airline-transform-batch"
      wait_for_completion: 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"
- match:
    acknowledged: true
- do:
    cat.transforms:
      transform_id: "airline-transform-batch"
      v: true
    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:
    $body: "/^   id                        \\s+ state    \\s+ checkpoint \\s+ documents_processed\
      \ \\s+ checkpoint_progress \\s+ last_search_time \\s+ changes_last_detection_time\
      \ \\n\n    (airline\\-transform\\-batch  \\s+ stop.*  \\s+ 1          \\s+ 3\
      \                   \\s+ 100.00              \\s+                  \\s+ .* \
      \                         \\n)+  $/\n"
- do:
    transform.delete_transform:
      transform_id: "airline-transform-batch"
    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"
---
Test cat transform stats with continuous transform:
- do:
    transform.put_transform:
      transform_id: "airline-transform-continuous"
      body: "{\n  \"source\": {\n    \"index\": [\"airline-data\", \"airline-data-other\"\
        ],\n    \"query\": {\"bool\":{\"filter\":{\"term\":{\"airline\":\"foo\"}}}}\n\
        \  },\n  \"dest\": { \"index\": \"airline-data-by-airline-continuous\" },\n\
        \  \"frequency\": \"10s\",\n  \"pivot\": {\n    \"group_by\": { \"airline\"\
        : {\"terms\": {\"field\": \"airline\"}}},\n    \"aggs\": {\"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}}}\n  },\n  \"description\": \"description\"\
        ,\n  \"sync\": {\n    \"time\": {\n      \"field\": \"time\"\n    }\n  }\n\
        }\n"
    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:
    cat.transforms:
      transform_id: "airline-transform-continuous"
      v: true
    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:
    $body: "/^   id                             \\s+ state   \\s+ checkpoint \\s+\
      \ documents_processed \\s+ checkpoint_progress \\s+ last_search_time \\s+ changes_last_detection_time\
      \ \\n\n    (airline\\-transform\\-continuous \\s+ stopped \\s+ 0          \\\
      s+ 0                   \\s+                     \\s+                  \\s+ \
      \                            \\n)+  $/\n"
- do:
    transform.delete_transform:
      transform_id: "airline-transform-continuous"
    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"
