---
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 get job stats after uploading data prompting the creation of some stats:
- 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:
    ml.get_job_stats:
      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:
    jobs.0.job_id: "job-stats-test"
- match:
    jobs.0.data_counts.processed_record_count: 3
- match:
    jobs.0.data_counts.processed_field_count: 6
- match:
    jobs.0.data_counts.input_field_count: 6
- gte:
    jobs.0.model_size_stats.model_bytes: 0
- match:
    jobs.0.state: "opened"
- is_true: "jobs.0.node.name"
- is_true: "jobs.0.node.transport_address"
- is_true: "jobs.0.node.attributes.ml\\.machine_memory"
- is_true: "jobs.0.open_time"
- match:
    jobs.0.timing_stats.job_id: "job-stats-test"
- match:
    jobs.0.timing_stats.bucket_count: 1
- gte:
    jobs.0.timing_stats.total_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.minimum_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.maximum_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.average_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.exponential_average_bucket_processing_time_ms: 0.0
---
Test get job stats for closed job:
- 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:
    ml.close_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:
    closed: true
- do:
    ml.get_job_stats:
      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:
    jobs.0.job_id: "job-stats-test"
- match:
    jobs.0.data_counts.processed_record_count: 3
- match:
    jobs.0.data_counts.processed_field_count: 6
- match:
    jobs.0.data_counts.input_field_count: 6
- gt:
    jobs.0.model_size_stats.model_bytes: 0
- match:
    jobs.0.state: "closed"
- is_false: "jobs.0.node"
- is_false: "jobs.0.open_time"
- match:
    jobs.0.timing_stats.job_id: "job-stats-test"
- match:
    jobs.0.timing_stats.bucket_count: 1
- gte:
    jobs.0.timing_stats.total_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.minimum_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.maximum_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.average_bucket_processing_time_ms: 0.0
- gte:
    jobs.0.timing_stats.exponential_average_bucket_processing_time_ms: 0.0
---
Test get job stats of datafeed job that has not received any data:
- do:
    ml.get_job_stats:
      job_id: "jobs-get-stats-datafeed-job"
    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:
    jobs.0.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.0.data_counts.processed_record_count: 0
- match:
    jobs.0.model_size_stats.model_bytes: 0
- match:
    jobs.0.state: "opened"
- is_true: "jobs.0.open_time"
- match:
    jobs.0.timing_stats.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.0.timing_stats.bucket_count: 0
- match:
    jobs.0.timing_stats.total_bucket_processing_time_ms: 0.0
- is_false: "jobs.0.timing_stats.minimum_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.maximum_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.average_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.exponential_average_bucket_processing_time_ms"
---
Test get all job stats with _all:
- do:
    ml.get_job_stats:
      job_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: 2
- match:
    jobs.0.job_id: "job-stats-test"
- match:
    jobs.0.state: "opened"
- match:
    jobs.1.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.1.state: "opened"
---
Test get all job stats with wildcard:
- do:
    ml.get_job_stats:
      job_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: 2
- match:
    jobs.0.job_id: "job-stats-test"
- match:
    jobs.0.state: "opened"
- match:
    jobs.1.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.1.state: "opened"
---
Test get all job stats implicitly:
- do:
    ml.get_job_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: 2
---
Test get job stats given missing job:
- do:
    catch: "missing"
    ml.get_job_stats:
      job_id: "unknown-job"
    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 job stats given pattern and allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    ml.get_job_stats:
      job_id: "missing-*"
      allow_no_match: 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:
    count: 0
---
Test get job stats given pattern and not allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    catch: "missing"
    ml.get_job_stats:
      job_id: "missing-*"
      allow_no_match: false
    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 reading v54 data counts and model size stats:
- skip:
    awaits_fix: "Version 5.4 support removed"
- do:
    ml.put_job:
      job_id: "job-stats-v54-bwc-test"
      body: "{\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  }\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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    indices.refresh:
      index: ".ml-anomalies*"
    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"
    index:
      index: ".ml-anomalies-shared-000001"
      id: "job-stats-v54-bwc-test-data-counts"
      body:
        job_id: "job-stats-v54-bwc-test"
        processed_record_count: 10
        processed_field_count: 0
        input_bytes: 0
        input_field_count: 0
        invalid_date_count: 0
        missing_field_count: 0
        out_of_order_timestamp_count: 0
        empty_bucket_count: 0
        sparse_bucket_count: 0
        bucket_count: 0
        input_record_count: 0
        latest_record_timestamp: 2000000000000
    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"
    index:
      index: ".ml-anomalies-shared-000001"
      id: "job-stats-v54-bwc-test-model_size_stats"
      body:
        job_id: "job-stats-v54-bwc-test"
        result_type: "model_size_stats"
        model_bytes: 0
        total_by_field_count: 101
        total_over_field_count: 0
        total_partition_field_count: 0
        bucket_allocation_failures_count: 0
        memory_status: "ok"
        categorized_doc_count: 0
        total_category_count: 0
        frequent_category_count: 0
        rare_category_count: 0
        dead_category_count: 0
        failed_category_count: 0
        categorization_status: "ok"
        log_time: 1495808248662
    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"
    indices.refresh:
      index:
      - ".ml-anomalies-shared"
    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.get_job_stats:
      job_id: "job-stats-v54-bwc-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:
    jobs.0.job_id: "job-stats-v54-bwc-test"
- match:
    jobs.0.data_counts.processed_record_count: 10
- match:
    jobs.0.model_size_stats.total_by_field_count: 101
---
Test no exception on get job stats with missing index:
- skip:
    features:
    - "warnings"
- 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\"\
        }\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.close_job:
      job_id: "jobs-get-stats-datafeed-job"
    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:
    closed: true
- do:
    ml.close_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:
    closed: true
- do:
    indices.delete:
      index: ".ml-anomalies-shared-000001"
    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.get_job_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: 2
- match:
    jobs.0.job_id: "job-stats-test"
- match:
    jobs.0.data_counts.processed_record_count: 0
- match:
    jobs.0.data_counts.processed_field_count: 0
- match:
    jobs.0.data_counts.input_field_count: 0
- match:
    jobs.0.model_size_stats.model_bytes: 0
- match:
    jobs.0.state: "closed"
- is_false: "jobs.0.node"
- is_false: "jobs.0.open_time"
- match:
    jobs.0.timing_stats.job_id: "job-stats-test"
- match:
    jobs.0.timing_stats.bucket_count: 0
- match:
    jobs.0.timing_stats.total_bucket_processing_time_ms: 0.0
- is_false: "jobs.0.timing_stats.minimum_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.maximum_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.average_bucket_processing_time_ms"
- is_false: "jobs.0.timing_stats.exponential_average_bucket_processing_time_ms"
- match:
    jobs.1.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.1.data_counts.processed_record_count: 0
- match:
    jobs.1.data_counts.processed_field_count: 0
- match:
    jobs.1.data_counts.input_field_count: 0
- match:
    jobs.1.model_size_stats.model_bytes: 0
- match:
    jobs.1.state: "closed"
- is_false: "jobs.1.node"
- is_false: "jobs.1.open_time"
- match:
    jobs.1.timing_stats.job_id: "jobs-get-stats-datafeed-job"
- match:
    jobs.1.timing_stats.bucket_count: 0
- match:
    jobs.1.timing_stats.total_bucket_processing_time_ms: 0.0
- is_false: "jobs.1.timing_stats.minimum_bucket_processing_time_ms"
- is_false: "jobs.1.timing_stats.maximum_bucket_processing_time_ms"
- is_false: "jobs.1.timing_stats.average_bucket_processing_time_ms"
- is_false: "jobs.1.timing_stats.exponential_average_bucket_processing_time_ms"
---
Test closed results index:
- skip:
    features:
    - "warnings"
- 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\"\
        }\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.close_job:
      job_id: "jobs-get-stats-datafeed-job"
    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:
    closed: true
- do:
    ml.close_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:
    closed: true
- do:
    ml.get_job_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"
- length:
    jobs: 2
- do:
    xpack.usage: {}
    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:
    ml.available: true
- match:
    ml.enabled: true
- match:
    ml.jobs.closed.count: 2
- do:
    indices.close:
      index: ".ml-anomalies-shared-000001"
    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:
    catch: "/type=cluster_block_exception, reason=index \\[.ml-anomalies-shared.*?\\\
      ] blocked by. \\[FORBIDDEN\\/.\\/index closed\\]/"
    ml.get_job_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:
    xpack.usage: {}
    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:
    ml.available: true
- match:
    ml.enabled: true
- is_false: "ml.jobs.closed.count"
