---
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:
    transform.put_transform:
      transform_id: "airline-transform-stats"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"airline-data-by-airline-stats\" },\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-stats-dos"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"airline-data-by-airline-stats-dos\" },\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-stats-the-third"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"airline-data-by-airline-stats-the-third\" },\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.start_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"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    transform.stop_transform:
      wait_for_checkpoint: false
      transform_id: "airline-transform-stats"
      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"
- 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-stats-dos"
    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-stats-the-third"
    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 get transform stats:
- do:
    transform.get_transform_stats:
      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"
- match:
    count: 1
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.0.state: "/started|indexing|stopping|stopped/"
- lte:
    transforms.0.checkpointing.last.checkpoint: 1
- lte:
    transforms.0.stats.pages_processed: 1
- match:
    transforms.0.stats.documents_processed: 0
- match:
    transforms.0.stats.documents_indexed: 0
- lte:
    transforms.0.stats.trigger_count: 1
- match:
    transforms.0.stats.index_time_in_ms: 0
- match:
    transforms.0.stats.index_total: 0
- match:
    transforms.0.stats.index_failures: 0
- gte:
    transforms.0.stats.search_time_in_ms: 0
- lte:
    transforms.0.stats.search_total: 1
- match:
    transforms.0.stats.search_failures: 0
---
Test get transform stats with timeout:
- do:
    transform.get_transform_stats:
      transform_id: "airline-transform-stats"
      timeout: "10s"
    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:
    count: 1
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.0.state: "/started|indexing|stopping|stopped/"
---
Test get transform stats on missing transform:
- do:
    transform.get_transform_stats:
      transform_id: "missing-transform"
    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:
    count: 0
- match:
    transforms: []
---
Test get multiple transform stats:
- do:
    transform.get_transform_stats:
      transform_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"
- match:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.1.id: "airline-transform-stats-dos"
- match:
    transforms.2.id: "airline-transform-stats-the-third"
- do:
    transform.get_transform_stats:
      transform_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:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.1.id: "airline-transform-stats-dos"
- match:
    transforms.2.id: "airline-transform-stats-the-third"
- do:
    transform.get_transform_stats:
      transform_id: "airline-transform-stats-dos,airline-transform-stats-the*"
    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:
    count: 2
- match:
    transforms.0.id: "airline-transform-stats-dos"
- match:
    transforms.1.id: "airline-transform-stats-the-third"
- do:
    transform.get_transform_stats:
      transform_id: "_all"
      from: 0
      size: 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:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats"
- do:
    transform.get_transform_stats:
      transform_id: "_all"
      from: 1
      size: 2
    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:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats-dos"
- match:
    transforms.1.id: "airline-transform-stats-the-third"
---
Test get multiple transform stats where one does not have a task:
- do:
    transform.get_transform_stats:
      transform_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"
- match:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.1.id: "airline-transform-stats-dos"
- match:
    transforms.2.id: "airline-transform-stats-the-third"
- do:
    transform.get_transform_stats:
      transform_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:
    count: 3
- match:
    transforms.0.id: "airline-transform-stats"
- match:
    transforms.1.id: "airline-transform-stats-dos"
- match:
    transforms.2.id: "airline-transform-stats-the-third"
---
Test get single transform stats when it does not have a task:
- do:
    transform.get_transform_stats:
      transform_id: "airline-transform-stats-dos"
    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:
    count: 1
- match:
    transforms.0.id: "airline-transform-stats-dos"
- match:
    transforms.0.checkpointing.last.checkpoint: 0
- is_false: "transforms.0.checkpointing.next.progress"
- match:
    transforms.0.stats.pages_processed: 0
- match:
    transforms.0.stats.documents_processed: 0
- match:
    transforms.0.stats.documents_indexed: 0
- match:
    transforms.0.stats.trigger_count: 0
- match:
    transforms.0.stats.index_time_in_ms: 0
- match:
    transforms.0.stats.index_total: 0
- match:
    transforms.0.stats.index_failures: 0
- match:
    transforms.0.stats.search_time_in_ms: 0
- match:
    transforms.0.stats.search_total: 0
- match:
    transforms.0.stats.search_failures: 0
