Skip to content

Commit 2565df7

Browse files
authored
Merge branch 'master' into alexy_ck_job_6
2 parents 70f9962 + 039583b commit 2565df7

6 files changed

Lines changed: 46 additions & 58 deletions

File tree

roles/telemetry_chargeback/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ These variables can be overridden when importing the role or set at the play lev
4141
| `cloudkitty_debug_dir` | `"{{ (cloudkitty_debug \| bool) \| ternary(artifacts_dir_zuul + '/debug_ck_db', '') }}"` | Directory for debug output (auto-set based on debug flag) |
4242
| `logs_dir_zuul` | `"{{ cifmw_basedir }}/logs"` | Directory for log files |
4343
| `artifacts_dir_zuul` | `"{{ cifmw_basedir }}/artifacts"` | Directory for generated artifacts and test output |
44+
| `cert_dir` | `"{{ cifmw_basedir }}/ck-certs"` | Directory for CloudKitty client certificates |
45+
| `local_cert_dir` | `"{{ cifmw_basedir }}/flush_certs"` | Local directory for flush certificates (cleaned up after run) |
46+
| `remote_cert_dir` | `"osp-certs"` | Remote directory inside OpenStack pod for certificates |
4447
| `cert_secret_name` | `"cert-cloudkitty-client-internal"` | OpenShift secret name for client certificates |
4548
| `client_secret` | `"secret/cloudkitty-lokistack-gateway-client-http"` | Secret for flush client certificates |
4649
| `ca_configmap` | `"cm/cloudkitty-lokistack-ca-bundle"` | ConfigMap for CA bundle |
@@ -49,7 +52,6 @@ These variables can be overridden when importing the role or set at the play lev
4952
| `openstackpod` | `"openstackclient"` | OpenStack client pod name for exec/cp operations |
5053
| `lookback` | `6` | Days to look back for Loki query time range |
5154
| `limit` | `50` | Limit for Loki query results |
52-
| `cloudkitty_test_scenarios` | `[]` | List of test scenario files to run (empty = auto-discover) |
5355

5456
How It Works
5557
------------
@@ -67,8 +69,7 @@ The role executes the following workflow:
6769
- Configures Loki push/query URLs
6870

6971
3. **Test Scenario Discovery**
70-
- **Auto-discovery** (default): Finds all `test_*.yml` files in `files/` directory
71-
- **User-provided**: Uses scenarios from `cloudkitty_test_scenarios` variable
72+
- Automatically finds all `test_*.yml` files in `files/` directory
7273

7374
4. **Scenario Execution Loop** (for each discovered scenario)
7475
- Generates synthetic Loki log data (`gen_synth_loki_data.py`)
@@ -79,9 +80,6 @@ The role executes the following workflow:
7980
- Removes temporary certificate directories
8081
- Always runs (even on failure) via block/rescue/always structure
8182

82-
### Loop Variable
83-
84-
The role uses `{{ scenario_name }}` as the loop variable when processing multiple test scenarios, making it easy to track which scenario is currently executing.
8583

8684
Python Scripts
8785
--------------
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: "Ingest data log to Loki via API"
5+
block:
196

20-
- name: "Ingest Status Message"
21-
ansible.builtin.debug:
22-
msg: "Ingestion Successful"
23-
when: loki_response.status | default(0) == 204
7+
- name: "Push data to Loki"
8+
ansible.builtin.uri:
9+
## loki_push_url will be used in future role developement
10+
url: "{{ loki_push_url }}"
11+
method: POST
12+
src: "{{ cloudkitty_data_file }}"
13+
body_format: json
14+
client_cert: "{{ cert_dir }}/tls.crt"
15+
client_key: "{{ cert_dir }}/tls.key"
16+
validate_certs: false
17+
status_code: 204
18+
return_content: true
19+
register: loki_response
20+
ignore_errors: false
21+
failed_when: loki_response.status != 204
22+
23+
# Success
24+
- name: "Confirm ingestion success"
25+
ansible.builtin.debug:
26+
msg: "Ingestion Successful!"
27+
28+
rescue:
29+
# Rescue block
30+
- name: "Debug failure"
31+
ansible.builtin.debug:
32+
msg: "Ingest failed. Loki Status: {{ loki_response.status | default('N/A') }}"

roles/telemetry_chargeback/tasks/load_loki_data.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
- name: "Ingest CloudKitty data log for {{ scenario_name }}"
33
ansible.builtin.include_tasks: ingest_loki_data.yml
44

5-
- name: "Flush data to Loki storage for {{ scenario_name }}"
6-
ansible.builtin.include_tasks: flush_loki_data.yml
7-
8-
- name: "Retrieve data log from Loki for {{ scenario_name }}"
9-
ansible.builtin.include_tasks: retrieve_loki_data.yml
5+
### more task files in future PRs

roles/telemetry_chargeback/tasks/main.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,24 @@
55
- name: "Setup Loki Environment"
66
ansible.builtin.include_tasks: "setup_loki_env.yml"
77

8-
- name: "Auto-discover test scenarios"
9-
when: cloudkitty_test_scenarios | length == 0
10-
block:
11-
- name: "Find test files"
12-
ansible.builtin.find:
13-
paths: "{{ cloudkitty_scenario_dir }}"
14-
patterns: "test_*.yml"
15-
register: test_files_raw
16-
17-
- name: "Set scenario list from discovered files"
18-
ansible.builtin.set_fact:
19-
cloudkitty_test_scenario_names: "{{ test_files_raw.files | map(attribute='path') | map('basename') | map('regex_replace', '\\.yml$', '') | list }}"
8+
- name: "Find test files"
9+
ansible.builtin.find:
10+
paths: "{{ cloudkitty_scenario_dir }}"
11+
patterns: "test_*.yml"
12+
register: found_files_raw
2013

21-
- name: "Set scenario list from user-provided variable"
14+
- name: "Extract only the filenames into a clean list"
2215
ansible.builtin.set_fact:
23-
cloudkitty_test_scenario_names: "{{ cloudkitty_test_scenarios }}"
24-
when: cloudkitty_test_scenarios | length > 0
16+
found_files: "{{ found_files_raw.files | map(attribute='path') | map('basename') | map('regex_replace', '\\.yml$', '') | list }}"
2517

2618
- name: "Run scenario file through workflow"
27-
when: cloudkitty_test_scenario_names | length > 0
28-
2919
block:
3020
- name: "Process and Loop if files exist"
3121
ansible.builtin.include_tasks: run_test_scenarios.yml
32-
loop: "{{ cloudkitty_test_scenario_names }}"
22+
loop: "{{ found_files }}"
3323
loop_control:
3424
loop_var: scenario_name
35-
when: cloudkitty_test_scenario_names | length > 0
25+
when: found_files | length > 0
3626

3727
rescue:
3828
- name: "Log failure"

roles/telemetry_chargeback/tasks/setup_loki_env.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@
3030
- "Flush URL: {{ ingester_flush_url }}"
3131
- "Query URL: {{ loki_query_url }}"
3232

33-
- name: "Ensure Certificate Directories Exist"
33+
# Certs to Ingest & Retrieve data to/from Loki
34+
- name: "Ensure Local Certificate Directory Exists"
3435
ansible.builtin.file:
35-
path: "{{ item }}"
36+
path: "{{ cert_dir }}"
3637
state: directory
37-
mode: '0700' # Restricted for security
38-
loop:
39-
- "{{ cert_dir }}"
40-
- "{{ local_cert_dir }}"
41-
when: item is defined
38+
mode: '0755'
4239

4340
- name: "Extract Certificates from OpenShift Secret"
4441
ansible.builtin.command:

roles/telemetry_chargeback/vars/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---
2-
# Scenario and script paths (using role_path)
3-
cloudkitty_scenario_dir: "{{ role_path }}/files"
42
cloudkitty_synth_script: "{{ role_path }}/files/gen_synth_loki_data.py"
53
cloudkitty_data_template: "{{ role_path }}/templates/loki_data_templ.j2"
64
cloudkitty_summary_script: "{{ role_path }}/files/gen_db_summary.py"

0 commit comments

Comments
 (0)