Skip to content

Commit

Permalink
Add prom_auth_method for selecting password (<= 1.5.3) vs token (1.5.4+)
Browse files Browse the repository at this point in the history
  • Loading branch information
csibbitt committed Dec 6, 2023
1 parent 430cb83 commit 061448b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions roles/client_side_tests/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
container_bin: 'podman'
prom_auth_method: token
54 changes: 43 additions & 11 deletions roles/client_side_tests/tasks/get_prom_info.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
---
- name: "Generate an access token for prometheus"
ansible.builtin.shell:
cmd: |
oc create token stf-prometheus-reader
register: prom_token_out
changed_when: false
- when: prom_auth_method == 'password'
block:
- name: "Get the default-prometheus-htpasswd secret"
ansible.builtin.shell:
cmd: |
oc get secret default-prometheus-htpasswd -ojson | jq '.data.auth, .data.password' | sed 's/"//g'
register: prom_secret
changed_when: false

- name: "Show the prom_secret value"
ansible.builtin.debug:
var: prom_token_out | string
- name: "Show the prom_secret value"
ansible.builtin.debug:
var: prom_secret | string

- name: "Get the prom creds from the secret"
ansible.builtin.set_fact:
prom_user_decoded: "{{ (prom_secret.stdout_lines[0] | b64decode) }}"
prom_pass: "{{ prom_secret.stdout_lines[1] | b64decode }}"

- name: "Fetch user"
ansible.builtin.set_fact:
prom_user: "{{ prom_user_decoded.split(':')[0] }}"
when: prom_user_decoded is defined

- name: "Show the prom_user value"
ansible.builtin.debug:
var: prom_user

- name: "Set prom auth string for password auth user"
ansible.builtin.set_fact:
prom_auth_string: '-u "{{ prom_user }}:{{ prom_pass }}"'

- when: prom_auth_method == 'token'
block:
- name: "Generate an access token for prometheus"
ansible.builtin.shell:
cmd: |
oc create token stf-prometheus-reader
register: prom_token_out
changed_when: false

- name: "Set prom auth string for password auth user"
ansible.builtin.set_fact:
prom_auth_string: '-H "Authorization: Bearer {{ prom_token_out.stdout }}"'

- name: "Get the prom URL"
ansible.builtin.shell:
Expand All @@ -21,7 +54,6 @@
ansible.builtin.debug:
var: prom_route.stdout

- name: "Get the prom creds from the secret"
- name: "Set the prom URL"
ansible.builtin.set_fact:
prom_token: "{{ prom_token_out.stdout }}"
prom_url: "{{ prom_route.stdout }}"
10 changes: 5 additions & 5 deletions roles/client_side_tests/tasks/test_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Description: Query Prometheus for collectd_cpu_percent metrics and save the output into the file
ansible.builtin.shell:
cmd: >-
/usr/bin/curl -k -H "Authorization: Bearer {{prom_token}}" \
/usr/bin/curl -k {{prom_auth_string}} \
-g https://{{ prom_url }}/api/v1/query? \
--data-urlencode 'query=collectd_cpu_percent {plugin_instance="0"}[1m]' \
--output /tmp/query_collectd_cpu_percent
Expand All @@ -20,7 +20,7 @@
# Description: Query Prometheus for ceph_ceph_bytes metrics and save the output into the file
ansible.builtin.shell:
cmd: >-
/usr/bin/curl -k -H "Authorization: Bearer {{prom_token}}" \
/usr/bin/curl -k {{prom_auth_string}} \
-g https://{{ prom_url }}/api/v1/query? \
--data-urlencode 'query=collectd_ceph_ceph_bytes {plugin_instance="ceph-osd.1"}[1m]' \
--output /tmp/query_ceph_ceph_bytes
Expand All @@ -33,7 +33,7 @@
# Description: Query Prometheus for collectd_interface_if_packets_tx_total metrics and save the output into the file
ansible.builtin.shell:
cmd: >-
/usr/bin/curl -k -H "Authorization: Bearer {{prom_token}}" \
/usr/bin/curl -k {{prom_auth_string}} \
-g https://{{ prom_url }}/api/v1/query? \
--data-urlencode 'query=collectd_interface_if_packets_tx_total {type_instance="base"}[1m]' \
--output /tmp/query_collectd_interface_tx_total
Expand All @@ -46,7 +46,7 @@
# Description: Query Prometheus for collectd_memory metrics and save the output into the file
ansible.builtin.shell:
cmd: >-
/usr/bin/curl -k -H "Authorization: Bearer {{prom_token}}" \
/usr/bin/curl -k {{prom_auth_string}} \
-g https://{{ prom_url }}/api/v1/query? \
--data-urlencode 'query=collectd_memory {plugin_instance="base"}[1m]' \
--output /tmp/query_collectd_memory
Expand All @@ -59,7 +59,7 @@
# Description: Query Prometheus for collectd_load_longterm metrics and save the output into the file
ansible.builtin.shell:
cmd: >-
/usr/bin/curl -k -H "Authorization: Bearer {{prom_token}}" \
/usr/bin/curl -k {{prom_auth_string}} \
-g https://{{ prom_url }}/api/v1/query? \
--data-urlencode 'query=collectd_load_longterm {plugin_instance="base"}[1m]' \
--output /tmp/query_load_longterm
Expand Down

0 comments on commit 061448b

Please sign in to comment.