<commit_before>setup:
  - do:
      indices.create:
        index: airline-data
        body:
          mappings:
            response:
              properties:
                time:
                  type: date

  - do:
      xpack.ml.put_job:
        job_id: datafeed-job
        body:  >
          {
            "job_id":"datafeed-job",
            "description":"Analysis of response time by airline",
            "analysis_config" : {
                "bucket_span": "1h",
                "detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
            },
            "data_description" : {
                "format":"xcontent",
                "time_field":"time",
                "time_format":"epoch"
            }
          }
  - do:
      xpack.ml.put_datafeed:
        datafeed_id: datafeed-1
        body:  >
          {
            "job_id":"datafeed-job",
            "indexes":"airline-data",
            "types":"response"
          }

---
"Test start and stop datafeed happy path":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }
  - do:
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: stopped }

---
"Test force stop datafeed":
  - skip:
      version: " - "
      reason: Broken test
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        "datafeed_id": "datafeed-1"
        "start": 0
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }

  - do:
      xpack.ml.stop_datafeed:
        "datafeed_id": "datafeed-1"
        force: true
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: stopped }

---
"Test start datafeed given start is now":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "now"
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }

---
"Test start non existing datafeed":
    - do:
        catch: missing
        xpack.ml.start_datafeed:
          datafeed_id: "non-existing-datafeed"
          start: 0

---
"Test start datafeed job, but not open":
    - do:
        catch: conflict
        xpack.ml.start_datafeed:
          datafeed_id: "datafeed-1"
          start: 0
    - do:
        catch: /cannot start datafeed \[datafeed-1\] because job \[datafeed-job\] is not open/
        xpack.ml.start_datafeed:
          datafeed_id: "datafeed-1"
          start: 0

---
"Test start already started datafeed job":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0
  - do:
      catch: conflict
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0

  - do:
      catch: /cannot start datafeed \[datafeed-1\] because it has already been started/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0

---
"Test stop non existing datafeed":
    - do:
        catch: missing
        xpack.ml.stop_datafeed:
          datafeed_id: "non-existing-datafeed"

---
"Test stop already stopped datafeed job":
  - do:
      catch: conflict
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"
  - do:
      catch: /Cannot stop datafeed \[datafeed-1\] because it has already been stopped/
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"

---
"Test start given end earlier than start":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /.* start \[1485910800000\] must be earlier than end \[1485907200000\]/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "2017-02-01T01:00:00Z"
        end: "2017-02-01T00:00:00Z"

---
"Test start given end same as start":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /.* start \[1485910800000\] must be earlier than end \[1485910800000\]/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "2017-02-01T01:00:00Z"
        end: "2017-02-01T01:00:00Z"

---
"Test start given datafeed index does not exist":
  - do:
      xpack.ml.update_datafeed:
        datafeed_id: datafeed-1
        body:  >
          {
            "indexes":["utopia"]
          }

  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /No node found to start datafeed \[datafeed-1\].*\[utopia\] does not exist.*/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
<commit_msg>Revert "[TEST] mute failing ML test for now"<commit_after>setup:
  - do:
      indices.create:
        index: airline-data
        body:
          mappings:
            response:
              properties:
                time:
                  type: date

  - do:
      xpack.ml.put_job:
        job_id: datafeed-job
        body:  >
          {
            "job_id":"datafeed-job",
            "description":"Analysis of response time by airline",
            "analysis_config" : {
                "bucket_span": "1h",
                "detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
            },
            "data_description" : {
                "format":"xcontent",
                "time_field":"time",
                "time_format":"epoch"
            }
          }
  - do:
      xpack.ml.put_datafeed:
        datafeed_id: datafeed-1
        body:  >
          {
            "job_id":"datafeed-job",
            "indexes":"airline-data",
            "types":"response"
          }

---
"Test start and stop datafeed happy path":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }
  - do:
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: stopped }

---
"Test force stop datafeed":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        "datafeed_id": "datafeed-1"
        "start": 0
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }

  - do:
      xpack.ml.stop_datafeed:
        "datafeed_id": "datafeed-1"
        force: true
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: stopped }

---
"Test start datafeed given start is now":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "now"
  - do:
      xpack.ml.get_datafeed_stats:
        datafeed_id: "datafeed-1"
  - match: { datafeeds.0.state: started }

---
"Test start non existing datafeed":
    - do:
        catch: missing
        xpack.ml.start_datafeed:
          datafeed_id: "non-existing-datafeed"
          start: 0

---
"Test start datafeed job, but not open":
    - do:
        catch: conflict
        xpack.ml.start_datafeed:
          datafeed_id: "datafeed-1"
          start: 0
    - do:
        catch: /cannot start datafeed \[datafeed-1\] because job \[datafeed-job\] is not open/
        xpack.ml.start_datafeed:
          datafeed_id: "datafeed-1"
          start: 0

---
"Test start already started datafeed job":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"
  - do:
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0
  - do:
      catch: conflict
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0

  - do:
      catch: /cannot start datafeed \[datafeed-1\] because it has already been started/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: 0

---
"Test stop non existing datafeed":
    - do:
        catch: missing
        xpack.ml.stop_datafeed:
          datafeed_id: "non-existing-datafeed"

---
"Test stop already stopped datafeed job":
  - do:
      catch: conflict
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"
  - do:
      catch: /Cannot stop datafeed \[datafeed-1\] because it has already been stopped/
      xpack.ml.stop_datafeed:
        datafeed_id: "datafeed-1"

---
"Test start given end earlier than start":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /.* start \[1485910800000\] must be earlier than end \[1485907200000\]/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "2017-02-01T01:00:00Z"
        end: "2017-02-01T00:00:00Z"

---
"Test start given end same as start":
  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /.* start \[1485910800000\] must be earlier than end \[1485910800000\]/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"
        start: "2017-02-01T01:00:00Z"
        end: "2017-02-01T01:00:00Z"

---
"Test start given datafeed index does not exist":
  - do:
      xpack.ml.update_datafeed:
        datafeed_id: datafeed-1
        body:  >
          {
            "indexes":["utopia"]
          }

  - do:
      xpack.ml.open_job:
        job_id: "datafeed-job"

  - do:
      catch: /No node found to start datafeed \[datafeed-1\].*\[utopia\] does not exist.*/
      xpack.ml.start_datafeed:
        datafeed_id: "datafeed-1"

{'fraction_non_alphanumeric': 0.1277, 'fraction_numerical': 0.0296, 'mean_word_length': 1.7634705719812103, 'pattern_counts': {'":': 54, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1117711', 'n_tokens_mistral': 3677, 'n_tokens_neox': 3481, 'n_words': 712}