---
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"
    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"
    ml.put_job:
      job_id: "job-stats-test"
      body: "{\n  \"job_id\":\"job-stats-test\",\n  \"description\":\"Analysis of\
        \ response time by airline\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        : \"1h\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"\
        responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {\n      \"time_field\":\"time\",\n      \"time_format\":\"epoch\"\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"
    ml.put_datafeed:
      datafeed_id: "datafeed-job-stats-test"
      body: "{\n  \"job_id\":\"job-stats-test\",\n  \"indexes\":[\"airline-data\"\
        ]\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"
    ml.put_job:
      job_id: "jobs-get-stats-datafeed-job"
      body: "{\n  \"job_id\":\"jobs-get-stats-datafeed-job\",\n  \"description\":\"\
        A job with a datafeed\",\n  \"analysis_config\" : {\n      \"bucket_span\"\
        : \"1h\",\n      \"detectors\" :[{\"function\":\"metric\",\"field_name\":\"\
        responsetime\",\"by_field_name\":\"airline\"}]\n  },\n  \"analysis_limits\"\
        \ : {\n      \"model_memory_limit\": \"10mb\"\n  },\n  \"data_description\"\
        \ : {\n      \"time_field\":\"time\",\n      \"time_format\":\"yyyy-MM-dd'T'HH:mm:ssX\"\
        \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"
    ml.put_datafeed:
      datafeed_id: "datafeed-jobs-get-stats-datafeed-job"
      body: "{\n  \"job_id\":\"jobs-get-stats-datafeed-job\",\n  \"indexes\":[\"airline-data\"\
        ]\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"
---
Test cat datafeeds:
- do:
    cat.ml_datafeeds:
      datafeed_id: "datafeed-job-stats-test"
    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                             state    buckets.count     search.count\n\
      ^ (datafeed\\-job\\-stats\\-test \\s+ \\w+ \\s+  \\d+         \\s+  \\d+   \
      \      \\n)+  $/\n"
- do:
    cat.ml_datafeeds:
      v: true
      datafeed_id: "datafeed-job-stats-test"
    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+ buckets\\.count \\s+\
      \ search\\.count \\n\n   (datafeed\\-job\\-stats\\-test  \\s+  \\w+   \\s+ \\\
      d+           \\s+ \\d+           \\n)+  $/\n"
- do:
    cat.ml_datafeeds:
      h: "id,search.count,search.time,search.bucket_avg"
      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+  search\\.count \\\
      s+ search\\.time \\s+ search\\.bucket_avg \\n\n   (datafeed\\-job\\-stats\\\
      -test                 \\s+  \\d+           \\s+ \\w+          \\s+ .*?     \
      \           \\n)+\n   (datafeed\\-jobs\\-get\\-stats\\-datafeed\\-job  \\s+\
      \  \\d+           \\s+ \\w+          \\s+ .*?                \\n)+  $/\n"
