|
| 1 | +--- |
| 2 | +- name: "Expected Count {{ scenario_name }}" |
| 3 | + ansible.builtin.debug: |
| 4 | + msg: "Input file has {{ synth_data_rates.data_log.log_count }} data entries that Loki has to return" |
| 5 | + |
| 6 | +# Query Loki |
| 7 | +- name: "Retrieve Logs from Loki via API {{ scenario_name }}" |
| 8 | + block: |
| 9 | + - name: "Query Loki API" |
| 10 | + ansible.builtin.uri: |
| 11 | + url: "{{ loki_query_url }}?query={{ logql_query | urlencode }}&start={{ synth_data_rates.time.begin_step.nanosec }}&limit={{ limit }}" |
| 12 | + method: GET |
| 13 | + client_cert: "{{ cert_dir }}/tls.crt" |
| 14 | + client_key: "{{ cert_dir }}/tls.key" |
| 15 | + ca_path: "{{ cert_dir }}/ca.crt" |
| 16 | + validate_certs: false |
| 17 | + return_content: true |
| 18 | + body_format: json |
| 19 | + register: loki_response |
| 20 | + # Wait condition |
| 21 | + until: |
| 22 | + - loki_response.status == 200 |
| 23 | + - loki_response.json.status == 'success' |
| 24 | + - loki_response.json.data.result | length > 0 |
| 25 | + - (loki_response.json.data.result | map(attribute='values') | map('length') | sum) >= (synth_data_rates.data_log.log_count | int) |
| 26 | + retries: 25 |
| 27 | + delay: 60 |
| 28 | + |
| 29 | + - name: "Save Loki Data to JSON file" |
| 30 | + ansible.builtin.copy: |
| 31 | + content: "{{ loki_response.json | to_json }}" |
| 32 | + dest: "{{ artifacts_dir_zuul }}/{{ scenario_name }}{{ cloudkitty_loki_data_suffix }}" |
| 33 | + mode: '0644' |
| 34 | + |
| 35 | + # Validate |
| 36 | + - name: "Verify Data Integrity {{ scenario_name }}" |
| 37 | + vars: |
| 38 | + actual_count: "{{ loki_response.json.data.result | map(attribute='values') | map('length') | sum }}" |
| 39 | + ansible.builtin.assert: |
| 40 | + that: |
| 41 | + - loki_response.json.status == 'success' |
| 42 | + - loki_response.json.data.result | length > 0 |
| 43 | + - actual_count | int == (synth_data_rates.data_log.log_count | int) |
| 44 | + fail_msg: >- |
| 45 | + Query did not return all data entries. Expected |
| 46 | + {{ synth_data_rates.data_log.log_count }} log entries, but Loki |
| 47 | + only returned {{ actual_count }} |
| 48 | + success_msg: "Query returned all data entries. Input file had {{ synth_data_rates.data_log.log_count }} entries and Loki returned {{ actual_count }}" |
| 49 | + |
| 50 | + rescue: |
| 51 | + - name: "Debug failure" |
| 52 | + ansible.builtin.debug: |
| 53 | + msg: |
| 54 | + - "Status: {{ loki_response.status | default('Unknown') }}" |
| 55 | + - "Body: {{ loki_response.content | default('No Content') }}" |
| 56 | + - "Msg: {{ loki_response.msg | default('Request failed') }}" |
| 57 | + |
| 58 | + # Failure |
| 59 | + - name: "Report Retrieval Failure" |
| 60 | + ansible.builtin.fail: |
| 61 | + msg: "Retrieval Failed" |
| 62 | + |
| 63 | +- name: "Generate chargeback stats from Loki-retrieved data file: {{ scenario_name }}" |
| 64 | + ansible.builtin.command: |
| 65 | + cmd: > |
| 66 | + python3 "{{ cloudkitty_summary_script }}" |
| 67 | + -j "{{ artifacts_dir_zuul }}/{{ scenario_name }}{{ cloudkitty_loki_data_suffix }}" |
| 68 | + -o "{{ artifacts_dir_zuul }}/{{ scenario_name }}{{ cloudkitty_loki_totals_metrics_suffix }}" |
| 69 | + --debug "{{ cloudkitty_debug_dir }}" |
| 70 | + register: synth_rating_info |
| 71 | + changed_when: synth_rating_info.rc == 0 |
0 commit comments