---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- 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      \"format\":\"xcontent\",\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.open_job:
      job_id: "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"
- 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      \"format\" : \"xcontent\",\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.open_job:
      job_id: "jobs-get-stats-datafeed-job"
    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-1"
      body: "{\n  \"job_id\":\"jobs-get-stats-datafeed-job\",\n  \"indexes\":[\"farequote\"\
        ]\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 anomaly detector jobs:
- skip:
    features:
    - "warnings"
    awaits_fix: "Flush API is deprecated"
- do:
    warnings:
    - "Posting data directly to anomaly detection jobs is deprecated, in a future\
      \ major version it will be compulsory to use a datafeed"
    ml.post_data:
      job_id: "job-stats-test"
      body: "{\"airline\":\"AAL\",\"responsetime\":\"132.2046\",\"time\":\"1403481600\"\
        } {\"airline\":\"JZA\",\"responsetime\":\"990.4628\",\"time\":\"1403481600\"\
        } {\"airline\":\"JZA\",\"responsetime\":\"244.1276\",\"time\":\"1403485200\"\
        }\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:
    ml.flush_job:
      job_id: "job-stats-test"
    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:
    flushed: true
- do:
    cat.ml_jobs:
      job_id: "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    data.processed_records     model.bytes\
      \    model.memory_status     forecasts.total     buckets.count\n^ (job\\-stats\\\
      -test \\s+  \\w+  \\s+ \\d+                   \\s+  .*?        \\s+ \\w+   \
      \              \\s+ \\d+           \\s+  \\d+         \\n)+  $/\n"
- do:
    cat.ml_jobs:
      v: true
      job_id: "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+ data\\.processed_records \\s+ model\\\
      .bytes \\s+ model\\.memory_status \\s+ forecasts\\.total \\s+ buckets\\.count\
      \  \\n\n   (job\\-stats\\-test  \\s+  \\w+   \\s+ \\d+                     \\\
      s+ .*?         \\s+ \\w+                  \\s+ \\d+             \\s+ \\d+  \
      \          \\n)+  $/\n"
- do:
    cat.ml_jobs:
      h: "id,data.processed_records,data.processed_fields,data.input_bytes"
      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+  data\\.processed_records \\s+ data\\.processed_fields\
      \ \\s+ data\\.input_bytes \\n\n   (job\\-stats\\-test  \\s+  \\d+          \
      \           \\s+ \\d+                    \\s+ \\w+               \\n)+\n   (jobs\\\
      -get\\-stats\\-datafeed\\-job  \\s+  \\d+                     \\s+ \\d+    \
      \                \\s+ \\w+               \\n)+  $/\n"
