Skip to content

Commit adc0242

Browse files
committed
Improve fask failure detection for ingest and retrieve
task files
1 parent 6d8b926 commit adc0242

2 files changed

Lines changed: 48 additions & 40 deletions

File tree

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
---
22
# Ingest data generated by gen_synth_loki_data.yml to Loki
33

4-
- name: "TEST Push data to Loki"
5-
ansible.builtin.uri:
6-
## loki_push_url will be used in future role developement
7-
url: "{{ loki_push_url }}"
8-
method: POST
9-
src: "{{ cloudkitty_data_file }}"
10-
body_format: json
11-
client_cert: "{{ cert_dir }}/tls.crt"
12-
client_key: "{{ cert_dir }}/tls.key"
13-
validate_certs: false
14-
status_code: 204
15-
return_content: true
16-
register: loki_response
17-
ignore_errors: true
18-
failed_when: loki_response.status != 204
4+
- name: "Push data to Loki {{ scenario_name }}"
5+
block:
6+
- name: "POST data to Loki"
7+
ansible.builtin.uri:
8+
# loki_push_url is configured in setup_loki_env.yml
9+
url: "{{ loki_push_url }}"
10+
method: POST
11+
src: "{{ cloudkitty_data_file }}"
12+
body_format: json
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+
status_code: 204
18+
return_content: true
19+
register: loki_response
1920

20-
- name: "Ingest Status Message"
21-
ansible.builtin.debug:
22-
msg: "Ingestion Successful"
23-
when: loki_response.status | default(0) == 204
21+
- name: "Ingest Status Message"
22+
ansible.builtin.debug:
23+
msg: "Ingestion Successful for {{ scenario_name }}"
24+
25+
rescue:
26+
- name: "IngestionFailed"
27+
ansible.builtin.fail:
28+
msg:
29+
- "Scenario: {{ scenario_name }}"
30+
- "Status: {{ loki_response.status | default('Unknown') }}"
31+
- "Body: {{ loki_response.content | default('No Content') }}"
32+
- "Message: {{ loki_response.msg | default('Request failed') }}"

roles/telemetry_chargeback/tasks/retrieve_loki_data.yml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
client_cert: "{{ cert_dir }}/tls.crt"
1414
client_key: "{{ cert_dir }}/tls.key"
1515
ca_path: "{{ cert_dir }}/ca.crt"
16+
# TODO: Enable validate_certs in production environments
1617
validate_certs: false
1718
return_content: true
1819
body_format: json
1920
register: loki_response
20-
# Wait condition
21+
# Wait for Loki to return all expected log entries
2122
until:
2223
- loki_response.status == 200
2324
- loki_response.json.status == 'success'
2425
- loki_response.json.data.result | length > 0
26+
# Verify Loki returned all expected log entries
2527
- (loki_response.json.data.result | map(attribute='values') | map('length') | sum) >= (synth_data_rates.data_summary.log_count | int)
26-
retries: 25
28+
retries: 20
2729
delay: 60
2830

2931
- name: "Save Loki Data to JSON file"
@@ -47,26 +49,23 @@
4749
only returned {{ actual_count }}
4850
success_msg: "Query returned all data entries. Input file had {{ synth_data_rates.data_summary.log_count }} entries and Loki returned {{ actual_count }}"
4951

52+
# Only runs if retrieval was successful
53+
- name: "Generate chargeback stats from Loki-retrieved data file: {{ scenario_name }}"
54+
ansible.builtin.command:
55+
cmd: >
56+
python3 "{{ cloudkitty_summary_script }}"
57+
-j "{{ artifacts_dir_zuul }}/{{ scenario_name }}{{ cloudkitty_loki_data_suffix }}"
58+
-o "{{ artifacts_dir_zuul }}/{{ scenario_name }}{{ cloudkitty_loki_totals_metrics_suffix }}"
59+
--debug "{{ cloudkitty_debug }}"
60+
--debug_dir "{{ cloudkitty_debug_dir }}"
61+
register: synth_rating_info
62+
changed_when: synth_rating_info.rc == 0
63+
5064
rescue:
51-
- name: "Debug failure"
52-
ansible.builtin.debug:
65+
- name: "Report Retrieval Failure"
66+
ansible.builtin.fail:
5367
msg:
68+
- "Failed to retrieve Loki data for {{ scenario_name }}"
5469
- "Status: {{ loki_response.status | default('Unknown') }}"
5570
- "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 }}"
70-
--debug_dir "{{ cloudkitty_debug_dir }}"
71-
register: synth_rating_info
72-
changed_when: synth_rating_info.rc == 0
71+
- "Message: {{ loki_response.msg | default('Request failed') }}"

0 commit comments

Comments
 (0)