-
Notifications
You must be signed in to change notification settings - Fork 14
Add task files to push and retrieve ck data log to loki #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
myadla
wants to merge
17
commits into
master
Choose a base branch
from
myadla_ck_loki
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e25c057
Add playbooks to push and retreive ck data log to/from loki
myadla f16c300
Modified data stream to query serivce:cloudkitty
myadla e0ed228
Removed hosts and var and included in main.yml
myadla b6eea33
Added a playbook to flush the data to loki storage
myadla b15808f
Made changes to gix ansible lint errors
myadla df5792a
Modified playbooks to count the no. of data streams being ingested
myadla bbf254d
Modified the message to count the correct data entries
myadla 0fe68b8
Addressed all comments and made modifications to the files
myadla 00e2df0
Added setup_loki_env.yaml to handle both URL discovery and Certificat…
myadla 8fdaa9a
Removed the redundant certs task from setup loki file
myadla 5f578bf
Modified retrieve_loki file to change limit_logs to limit
myadla 57b0056
Renamed mTLS certs names in defaults/main.yml
myadla 2773c25
Fixed ansible lint errors by rename namespace to openstack_ns
myadla 793622e
Removed logs_dir var from defaults/main.yml and using it from ci/var/…
myadla 8b4ffdb
Added new line in vars/main.yml
myadla 4443fe8
Removed tags from tasks/main.yml
myadla d4f8afb
explicitly override any inherited settings by adding ignore_errors: f…
myadla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,25 @@ | ||
| --- | ||
| openstack_cmd: "openstack" | ||
|
|
||
| # Cloudkitty certificates | ||
| gateway_client_cert_secret_name: "cert-cloudkitty-client-internal" | ||
| gateway_client_cert_dir: "{{ ansible_user_dir }}/ck-certs" | ||
|
|
||
| ingester_client_cert_secret: "secret/cloudkitty-lokistack-gateway-client-http" | ||
| ingester_ca_configmap: "cm/cloudkitty-lokistack-ca-bundle" | ||
| ingester_client_cert_dir: "{{ ansible_user_dir }}/flush_certs" | ||
| osp_remote_cert_dir: "osp-certs" | ||
|
|
||
| # Loki Ingest & Retrieve logs | ||
| ck_output_file_remote: "{{ logs_dir }}/gen_loki_synth_data.log" | ||
| ck_loki_retrieve_file: "{{ logs_dir }}/retrieve_loki_op.json" | ||
|
|
||
| # LogQL Query | ||
| logql_query: "{{ loki_query | default('{service=\"cloudkitty\"}') }}" | ||
|
|
||
| # vars | ||
| openstack_ns: "openstack" | ||
| openstackpod: "openstackclient" | ||
|
|
||
| # Time window settings | ||
| lookback: 6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| # Flush Loki Ingester Memory to Storage | ||
|
|
||
| - name: Flush Execution inside openstack CLI | ||
| block: | ||
| # create dir | ||
| - name: Create directory inside openstack CLI | ||
| ansible.builtin.command: | ||
| cmd: "oc exec -n {{ openstack_ns }} {{ openstackpod }} -- mkdir -p {{ osp_remote_cert_dir }}" | ||
| changed_when: false | ||
|
|
||
| # copy all certs | ||
| - name: Copy certificates to openstack CLI | ||
| ansible.builtin.command: | ||
| cmd: "oc cp {{ ingester_client_cert_dir }}/. {{ openstack_ns }}/{{ openstackpod }}:{{ osp_remote_cert_dir }}/" | ||
| changed_when: true | ||
|
|
||
| # flush loki | ||
| - name: Trigger Flush | ||
| ansible.builtin.command: | ||
| cmd: > | ||
| oc exec -n {{ openstack_ns }} {{ openstackpod }} -- | ||
| curl -v -X POST {{ ingester_flush_url }} | ||
| --cert {{ osp_remote_cert_dir }}/tls.crt | ||
| --key {{ osp_remote_cert_dir }}/tls.key | ||
| --cacert {{ osp_remote_cert_dir }}/service-ca.crt | ||
| register: flush_response | ||
| changed_when: true | ||
| failed_when: flush_response.rc != 0 | ||
|
|
||
| # Status | ||
| - name: Verify Flush Status | ||
| ansible.builtin.assert: | ||
| that: | ||
| - "'204' in flush_response.stderr or '200' in flush_response.stderr" | ||
| fail_msg: "Flush failed" | ||
| success_msg: "Ingester Memory Flushed successfully" | ||
myadla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| rescue: | ||
| - name: Debug Failure Output | ||
| ansible.builtin.debug: | ||
| msg: | ||
| - "Failure" | ||
| - "Stdout: {{ flush_response.stdout }}" | ||
| - "Stderr: {{ flush_response.stderr }}" | ||
|
|
||
| always: | ||
| # Cleanup | ||
| - name: Cleanup local certificates | ||
| ansible.builtin.file: | ||
| path: "{{ ingester_client_cert_dir }}" | ||
| state: absent | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| # Ingest data log to Loki that is generated from gen_synth_loki_data.yml" | ||
|
|
||
| # Push the json format data log to loki | ||
| - name: Ingest data log to Loki via API | ||
| block: | ||
|
|
||
| - name: Read log file content | ||
| ansible.builtin.slurp: | ||
| src: "{{ ck_output_file_remote }}" | ||
| register: log_file_content | ||
|
|
||
| - name: Push data to Loki | ||
| ansible.builtin.uri: | ||
| url: "{{ loki_push_url }}" | ||
| method: POST | ||
| body: "{{ log_file_content['content'] | b64decode | from_json }}" | ||
| body_format: json | ||
| client_cert: "{{ gateway_client_cert_dir }}/tls.crt" | ||
| client_key: "{{ gateway_client_cert_dir }}/tls.key" | ||
| validate_certs: false | ||
| status_code: 204 | ||
| return_content: yes | ||
| register: loki_response | ||
| ignore_errors: false | ||
| failed_when: loki_response.status != 204 | ||
|
|
||
| # Success | ||
| - name: Confirm Success | ||
| ansible.builtin.debug: | ||
| msg: "Ingestion Successful!" | ||
|
|
||
| rescue: | ||
| # Rescue block | ||
| - name: Debug failure | ||
| ansible.builtin.debug: | ||
| msg: "{{ loki_response.status }}" | ||
|
|
||
| # Failure | ||
| - name: Report Ingestion Failure | ||
| ansible.builtin.fail: | ||
| msg: "Ingestion Failed" | ||
| ignore_errors: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,25 @@ | ||
| --- | ||
| - name: "Validate Chargeback Feature" | ||
| ansible.builtin.include_tasks: "chargeback_tests.yml" | ||
| - name: Validate Chargeback Feature | ||
| ansible.builtin.include_tasks: | ||
| file: chargeback_tests.yml | ||
|
|
||
| - name: Generate Synthetic Data | ||
| ansible.builtin.include_tasks: | ||
| file: gen_synth_loki_data.yml | ||
|
|
||
| - name: Setup Loki Environment | ||
| ansible.builtin.include_tasks: | ||
| file: setup_loki_env.yml | ||
|
|
||
| - name: Ingests Cloudkitty Data log | ||
| ansible.builtin.include_tasks: | ||
| file: ingest_loki_data.yml | ||
|
|
||
| - name: Flush Data to Loki Storage | ||
| ansible.builtin.include_tasks: | ||
| file: flush_loki_data.yml | ||
|
|
||
| - name: Retrieve Data log from Loki | ||
| ansible.builtin.include_tasks: | ||
| file: retrieve_loki_data.yml | ||
|
|
||
| - name: "Generate Synthetic Data" | ||
| ansible.builtin.include_tasks: "gen_synth_loki_data.yml" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| --- | ||
| # Query Loki to retrieve data and output to retrieve_loki_op.json | ||
|
|
||
| # Count the entries in the log file | ||
| - name: Read the json data log file to calculate the no. of entries | ||
| ansible.builtin.slurp: | ||
| src: "{{ ck_output_file_remote }}" | ||
| register: source_file_data | ||
|
|
||
| - name: Set Expected Log Count | ||
| ansible.builtin.set_fact: | ||
| expected_log_count: "{{ (source_file_data['content'] | b64decode | from_json).streams | map(attribute='values') | map('length') | sum }}" | ||
|
|
||
| - name: Expected Count | ||
| ansible.builtin.debug: | ||
| msg: "Input file has {{ expected_log_count }} data entries that Loki has to return" | ||
|
|
||
| # Calculate Time | ||
| - name: Calculate Start Time in nanoseconds | ||
| ansible.builtin.command: date -d "{{ lookback }} days ago" +%s000000000 | ||
| register: nano_time | ||
| changed_when: false | ||
|
|
||
| - name: Set Start Time | ||
| ansible.builtin.set_fact: | ||
| start_time: "{{ nano_time.stdout }}" | ||
|
|
||
| - name: Display Query Parameters | ||
| ansible.builtin.debug: | ||
| msg: | ||
| - "Query: {{ logql_query }}" | ||
| - "Start Time: {{ start_time }}" | ||
|
|
||
| # Query Loki | ||
| - name: Retrieve Logs from Loki via API | ||
| block: | ||
| - name: Query Loki API | ||
| ansible.builtin.uri: | ||
| url: "{{ loki_query_url }}?query={{ logql_query | urlencode }}&start={{ start_time }}" | ||
| method: GET | ||
| client_cert: "{{ gateway_client_cert_dir }}/tls.crt" | ||
| client_key: "{{ gateway_client_cert_dir }}/tls.key" | ||
| ca_path: "{{ gateway_client_cert_dir }}/ca.crt" | ||
| validate_certs: false | ||
| return_content: yes | ||
| body_format: json | ||
| register: loki_response | ||
| # Wait condition | ||
| until: | ||
| - loki_response.status == 200 | ||
| - loki_response.json.status == 'success' | ||
| - loki_response.json.data.result | length > 0 | ||
| - (loki_response.json.data.result | map(attribute='values') | map('length') | sum) >= expected_log_count|int | ||
| retries: 25 | ||
| delay: 60 | ||
|
|
||
| # Save data | ||
| - name: Save Loki Data to JSON file | ||
| ansible.builtin.copy: | ||
| content: "{{ loki_response.json | to_nice_json }}" | ||
| dest: "{{ ck_loki_retrieve_file }}" | ||
| mode: '0644' | ||
|
|
||
| # Validate | ||
| - name: Verify Data Integrity | ||
| vars: | ||
| actual_count: "{{ loki_response.json.data.result | map(attribute='values') | map('length') | sum }}" | ||
| ansible.builtin.assert: | ||
| that: | ||
| - loki_response.json.status == 'success' | ||
| - loki_response.json.data.result | length > 0 | ||
| - actual_count|int == expected_log_count|int | ||
| fail_msg: "Query did not return all data entries. Expected {{ expected_log_count }} log entries, but Loki only returned {{ actual_count }}" | ||
| success_msg: "Query returned all data entries. Input file had {{ expected_log_count }} entries and Loki returned {{ actual_count }}" | ||
| ignore_errors: false | ||
|
|
||
| rescue: | ||
myadla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Debug failure | ||
| ansible.builtin.debug: | ||
| msg: | ||
| - "Status: {{ loki_response.status | default('Unknown') }}" | ||
| - "Body: {{ loki_response.content | default('No Content') }}" | ||
| - "Msg: {{ loki_response.msg | default('Request failed') }}" | ||
|
|
||
| # Failure | ||
| - name: Report Retrieval Failure | ||
| ansible.builtin.fail: | ||
| msg: "Retrieval Failed" | ||
| ignore_errors: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| # Setup Loki Environment | ||
|
|
||
| # Dynamic URL's | ||
| - name: Get Loki Public Route Host | ||
| ansible.builtin.command: | ||
| cmd: oc get route cloudkitty-lokistack -n {{ openstack_ns }} -o jsonpath='{.spec.host}' | ||
| register: loki_route | ||
| changed_when: false | ||
|
|
||
| - name: Set Loki URLs | ||
| ansible.builtin.set_fact: | ||
| # Base URL | ||
| loki_base_url: "https://{{ loki_route.stdout }}" | ||
|
|
||
| # Internal Flush URL (Service DNS: https://<service>.<openstack_ns>.svc:3100/flush) | ||
| ingester_flush_url: "https://cloudkitty-lokistack-ingester-http.{{ openstack_ns }}.svc:3100/flush" | ||
|
|
||
| - name: Set Derived Loki URLs | ||
| ansible.builtin.set_fact: | ||
| loki_push_url: "{{ loki_base_url }}/api/logs/v1/cloudkitty/loki/api/v1/push" | ||
| loki_query_url: "{{ loki_base_url }}/api/logs/v1/cloudkitty/loki/api/v1/query_range" | ||
|
|
||
| - name: Debug URLs | ||
| ansible.builtin.debug: | ||
| msg: | ||
| - "Loki Route: {{ loki_base_url }}" | ||
| - "Push URL: {{ loki_push_url }}" | ||
| - "Flush URL: {{ ingester_flush_url }}" | ||
| - "Query URL: {{ loki_query_url }}" | ||
|
|
||
| # Certs to Ingest & Retrieve data to/from Loki | ||
| - name: Ensure Local Certificate Directory Exists | ||
| ansible.builtin.file: | ||
| path: "{{ gateway_client_cert_dir }}" | ||
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: Extract Certificates from Openshift Secret | ||
| ansible.builtin.command: | ||
| cmd: > | ||
| oc extract secret/{{ gateway_client_cert_secret_name }} | ||
| --to={{ gateway_client_cert_dir }} | ||
| --confirm | ||
| -n {{ openstack_ns }} | ||
| changed_when: true | ||
|
|
||
| # Certs to Flush data to Loki | ||
| - name: Create a directory to extract certificates | ||
| ansible.builtin.file: | ||
| path: "{{ ingester_client_cert_dir }}" | ||
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: Extract Client Certificates | ||
| ansible.builtin.command: | ||
| cmd: > | ||
| oc extract {{ ingester_client_cert_secret }} | ||
| --to={{ ingester_client_cert_dir }} | ||
myadla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --confirm | ||
| -n {{ openstack_ns }} | ||
| changed_when: true | ||
|
|
||
| - name: Extract CA Bundle | ||
| ansible.builtin.command: | ||
| cmd: "oc extract {{ ingester_ca_configmap }} | ||
| --to={{ ingester_client_cert_dir }} | ||
| --confirm | ||
| -n {{ openstack_ns }}" | ||
| changed_when: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| --- | ||
| logs_dir_zuul: "/home/zuul/ci-framework-data/logs" | ||
| artifacts_dir_zuul: "/home/zuul/ci-framework-data/artifacts" | ||
|
|
||
| ck_synth_script: "{{ role_path }}/files/gen_synth_loki_data.py" | ||
| ck_data_template: "{{ role_path }}/template/loki_data_templ.j2" | ||
| ck_data_config: "{{ role_path }}/files/test_static.yml" | ||
| ck_output_file_local: "{{ artifacts_dir_zuul }}/loki_synth_data.json" | ||
| ck_output_file_remote: "{{ logs_dir_zuul }}/gen_loki_synth_data.log" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.