<commit_before>setup:
  - do:
      xpack.prelert.put_job:
        body:  >
          {
            "job_id":"farequote",
            "description":"Analysis of response time by airline",
            "analysis_config" : {
                "bucket_span":3600,
                "detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
            },
            "data_description" : {
                "format":"JSON",
                "time_field":"time",
                "time_format":"epoch"
            }
          }

  - do:
      xpack.prelert.open_job:
        job_id: farequote

---
"Test POST data job api, flush, close and verify DataCounts doc":
  - do:
      xpack.prelert.job_data:
        job_id: farequote
        body: >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481700"}

  - match: { processed_record_count: 2 }
  - match: { processed_field_count: 4}
  - match: { input_bytes: 177 }
  - match: { input_field_count: 6 }
  - match: { invalid_date_count: 0 }
  - match: { missing_field_count: 0 }
  - match: { out_of_order_timestamp_count: 0}
  - match: { earliest_record_timestamp: 1403481600000}
  - match: { latest_record_timestamp: 1403481700000}

  - do:
      xpack.prelert.flush_job:
        job_id: farequote
  - match: { acknowledged: true }

  - do:
      xpack.prelert.close_job:
        job_id: farequote
  - match: { acknowledged: true }

  - do:
      xpack.prelert.get_jobs:
        job_id: farequote
        metric: status
  - match: { jobs.0.status: "CLOSED" }

  - do:
    get:
      index: prelertresults-farequote
      type: data_counts
      id: farequote-data-counts

  - match: { _source.processed_record_count: 2 }
  - match: { _source.processed_field_count: 4}
  - match: { _source.input_bytes: 177 }
  - match: { _source.input_field_count: 6 }
  - match: { _source.invalid_date_count: 0 }
  - match: { _source.missing_field_count: 0 }
  - match: { _source.out_of_order_timestamp_count: 0}
  - match: { _source.earliest_record_timestamp: 1403481600000}
  - match: { _source.latest_record_timestamp: 1403481700000}

---
"Test POST data with invalid parameters":
  - do:
      catch: /parse_exception/
      xpack.prelert.job_data:
        job_id: farequote
        reset_start: not_a_date
        body:  >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481600"}

  - do:
      catch: /parse_exception/
      xpack.prelert.job_data:
        job_id: farequote
        reset_end: end_not_a_date
        body:  >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481600"}

---
"Test Flush data with invalid parameters":
  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        start: not_a_date

  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        end: end_not_a_date

  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        advance_time: advance_time_not_a_date<commit_msg>Add yaml tests assert a 404 is returned when the job id isn’t recognised (elastic/elasticsearch#531)<commit_after>setup:
  - do:
      xpack.prelert.put_job:
        body:  >
          {
            "job_id":"farequote",
            "description":"Analysis of response time by airline",
            "analysis_config" : {
                "bucket_span":3600,
                "detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
            },
            "data_description" : {
                "format":"JSON",
                "time_field":"time",
                "time_format":"epoch"
            }
          }

  - do:
      xpack.prelert.open_job:
        job_id: farequote

---
"Test POST data job api, flush, close and verify DataCounts doc":
  - do:
      xpack.prelert.job_data:
        job_id: farequote
        body: >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481700"}

  - match: { processed_record_count: 2 }
  - match: { processed_field_count: 4}
  - match: { input_bytes: 177 }
  - match: { input_field_count: 6 }
  - match: { invalid_date_count: 0 }
  - match: { missing_field_count: 0 }
  - match: { out_of_order_timestamp_count: 0}
  - match: { earliest_record_timestamp: 1403481600000}
  - match: { latest_record_timestamp: 1403481700000}

  - do:
      xpack.prelert.flush_job:
        job_id: farequote
  - match: { acknowledged: true }

  - do:
      xpack.prelert.close_job:
        job_id: farequote
  - match: { acknowledged: true }

  - do:
      xpack.prelert.get_jobs:
        job_id: farequote
        metric: status
  - match: { jobs.0.status: "CLOSED" }

  - do:
    get:
      index: prelertresults-farequote
      type: data_counts
      id: farequote-data-counts

  - match: { _source.processed_record_count: 2 }
  - match: { _source.processed_field_count: 4}
  - match: { _source.input_bytes: 177 }
  - match: { _source.input_field_count: 6 }
  - match: { _source.invalid_date_count: 0 }
  - match: { _source.missing_field_count: 0 }
  - match: { _source.out_of_order_timestamp_count: 0}
  - match: { _source.earliest_record_timestamp: 1403481600000}
  - match: { _source.latest_record_timestamp: 1403481700000}

---
"Test POST data with invalid parameters":
  - do:
      catch: missing
      xpack.prelert.job_data:
        job_id: not_a_job
        body: {}

  - do:
      catch: /parse_exception/
      xpack.prelert.job_data:
        job_id: farequote
        reset_start: not_a_date
        body:  >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481600"}

  - do:
      catch: /parse_exception/
      xpack.prelert.job_data:
        job_id: farequote
        reset_end: end_not_a_date
        body:  >
          {"airline":"AAL","responsetime":"132.2046","sourcetype":"farequote","time":"1403481600"}
          {"airline":"JZA","responsetime":"990.4628","sourcetype":"farequote","time":"1403481600"}

---
"Test Flush data with invalid parameters":
  - do:
      catch: missing
      xpack.prelert.flush_job:
        job_id: not_a_job

  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        start: not_a_date

  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        end: end_not_a_date

  - do:
      catch: /parse_exception/
      xpack.prelert.flush_job:
        job_id: farequote
        advance_time: advance_time_not_a_date

---
"Test open and close with non-existent job id":
  - do:
      catch: missing
      xpack.prelert.open_job:
        job_id: not_a_job

  - do:
      catch: missing
      xpack.prelert.close_job:
        job_id: not_a_job
{'fraction_non_alphanumeric': 0.13441593886462883, 'fraction_numerical': 0.04912663755458515, 'mean_word_length': 2.5354558610709117, 'pattern_counts': {'":': 73, '<': 3, '<?xml version=': 0, '>': 11, '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': '6541178', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2470, 'n_words': 414}