---
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: "get-influencers-test"
      body: "{\n  \"analysis_config\" : {\n      \"detectors\" :[{\"function\":\"\
        metric\",\"field_name\":\"responsetime\",\"by_field_name\":\"airline\"}]\n\
        \  },\n  \"data_description\" : {\n      \"format\":\"xcontent\",\n      \"\
        time_field\":\"time\"\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"
    index:
      index: ".ml-anomalies-get-influencers-test"
      id: "get-influencers-test_1464739200000_1_1"
      body:
        job_id: "get-influencers-test"
        timestamp: "2016-06-01T00:00:00Z"
        influencer_field_name: "foo"
        influencer_field_value: "bar"
        influencer_score: 50.0
        result_type: "influencer"
        bucket_span: 1
    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-get-influencers-test"
      id: "get-influencers-test_1464825600000_1_2"
      body:
        job_id: "get-influencers-test"
        timestamp: "2016-06-02T00:00:00Z"
        influencer_field_name: "foo"
        influencer_field_value: "zoo"
        influencer_score: 80.0
        result_type: "influencer"
        bucket_span: 1
        is_interim: 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"
- 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-get-influencers-test"
      id: "get-influencers-test_1464912000000_1_3"
      body:
        job_id: "get-influencers-test"
        timestamp: "2016-06-03T00:00:00Z"
        influencer_field_name: "foo"
        influencer_field_value: "zoo"
        influencer_score: 60.0
        result_type: "influencer"
        bucket_span: 1
    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-get-influencers-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"
---
Test result influencers api:
- do:
    ml.get_influencers:
      job_id: "get-influencers-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:
    count: 3
- match:
    influencers.0.influencer_score: 80
- match:
    influencers.0.timestamp: 1464825600000
- match:
    influencers.1.influencer_score: 60
- match:
    influencers.1.timestamp: 1464912000000
- match:
    influencers.2.influencer_score: 50
- match:
    influencers.2.timestamp: 1464739200000
---
Test get influencers with paging:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      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
- length:
    influencers: 2
- match:
    influencers.0.influencer_score: 60
- match:
    influencers.0.timestamp: 1464912000000
- match:
    influencers.1.influencer_score: 50
- match:
    influencers.1.timestamp: 1464739200000
---
Test get influencers with paging in body:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      body: "{\n  \"page\": {\n    \"from\": 1,\n    \"size\": 2\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"
- match:
    count: 3
- length:
    influencers: 2
- match:
    influencers.0.influencer_score: 60
- match:
    influencers.0.timestamp: 1464912000000
- match:
    influencers.1.influencer_score: 50
- match:
    influencers.1.timestamp: 1464739200000
---
Test get influencers given exclude_interim false:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      exclude_interim: 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"
- match:
    count: 3
---
Test get influencers given exclude_interim true:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      exclude_interim: 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: 2
- match:
    influencers.0.timestamp: 1464912000000
- match:
    influencers.0.is_interim: false
- match:
    influencers.1.timestamp: 1464739200000
- match:
    influencers.1.is_interim: false
---
Test result influencers api with time range:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      start: "2016-06-01T00:00:00Z"
      end: "2016-06-01T01:00:00Z"
    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:
    influencers.0.timestamp: 1464739200000
---
Test with unknown job id:
- do:
    catch: "missing"
    ml.get_influencers:
      job_id: "non-existent-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 influencers api with influencer score filter:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      influencer_score: 70
    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:
    influencers.0.timestamp: 1464825600000
---
Test get influencers api sort:
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      desc: 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"
- match:
    count: 3
- match:
    influencers.0.influencer_score: 50
- match:
    influencers.1.influencer_score: 60
- match:
    influencers.2.influencer_score: 80
- do:
    ml.get_influencers:
      job_id: "get-influencers-test"
      sort: "timestamp"
    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:
    influencers.0.timestamp: 1464912000000
- match:
    influencers.1.timestamp: 1464825600000
- match:
    influencers.2.timestamp: 1464739200000
