From 47014f0af0993d582816fcb2ec7ff2de9c9a6db2 Mon Sep 17 00:00:00 2001 From: Leonhard Mayr Date: Mon, 10 Jun 2024 13:59:11 +0200 Subject: [PATCH] Add test for scrape config files Signed-off-by: Leonhard Mayr --- .../molecule/alternative/molecule.yml | 4 ++-- .../molecule/alternative/prepare.yml | 20 +++++++++++++++++++ .../alternative/tests/test_alternative.py | 2 ++ roles/prometheus/molecule/default/prepare.yml | 17 ++++++++++++++++ .../molecule/default/tests/test_default.py | 2 ++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 roles/prometheus/molecule/alternative/prepare.yml create mode 100644 roles/prometheus/molecule/default/prepare.yml diff --git a/roles/prometheus/molecule/alternative/molecule.yml b/roles/prometheus/molecule/alternative/molecule.yml index 76c708494..a69eb169b 100644 --- a/roles/prometheus/molecule/alternative/molecule.yml +++ b/roles/prometheus/molecule/alternative/molecule.yml @@ -1,7 +1,5 @@ --- provisioner: - playbooks: - prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml" inventory: group_vars: all: @@ -58,6 +56,8 @@ provisioner: - influx.example.org:8080 labels: env: demo + prometheus_scrape_config_files: + - /tmp/prometheus/scrapes/*.yml prometheus_scrape_configs: - job_name: "prometheus" metrics_path: "{{ prometheus_metrics_path }}" diff --git a/roles/prometheus/molecule/alternative/prepare.yml b/roles/prometheus/molecule/alternative/prepare.yml new file mode 100644 index 000000000..3aac835b1 --- /dev/null +++ b/roles/prometheus/molecule/alternative/prepare.yml @@ -0,0 +1,20 @@ +--- +- name: Run local preparation + hosts: localhost + gather_facts: false + tasks: + - name: Create scrapes directory + ansible.builtin.file: + name: /tmp/prometheus/scrapes + state: directory + recurse: true + check_mode: false + - name: Create empty scrape config file + ansible.builtin.file: + name: /tmp/prometheus/scrapes/empty_scrapes.yml + state: touch + mode: 0664 + check_mode: false + +- name: Import shared preparation playbook + import_playbook: "../../../../.config/molecule/alternative/prepare.yml" diff --git a/roles/prometheus/molecule/alternative/tests/test_alternative.py b/roles/prometheus/molecule/alternative/tests/test_alternative.py index 94c9e1c17..d4a376209 100644 --- a/roles/prometheus/molecule/alternative/tests/test_alternative.py +++ b/roles/prometheus/molecule/alternative/tests/test_alternative.py @@ -11,6 +11,7 @@ "/opt/prom/etc", "/opt/prom/etc/rules", "/opt/prom/etc/file_sd", + "/opt/prom/etc/scrapes", "/opt/prom/lib" ]) def test_directories(host, dirs): @@ -24,6 +25,7 @@ def test_directories(host, dirs): "/opt/prom/etc/rules/ansible_managed.rules", "/opt/prom/etc/file_sd/node.yml", "/opt/prom/etc/file_sd/docker.yml", + "/opt/prom/etc/scrapes/empty_scrapes.yml", "/usr/local/bin/prometheus", "/usr/local/bin/promtool" ]) diff --git a/roles/prometheus/molecule/default/prepare.yml b/roles/prometheus/molecule/default/prepare.yml new file mode 100644 index 000000000..347673057 --- /dev/null +++ b/roles/prometheus/molecule/default/prepare.yml @@ -0,0 +1,17 @@ +--- +- name: Run local preparation + hosts: localhost + gather_facts: false + tasks: + - name: Create scrapes directory + ansible.builtin.file: + name: "{{ playbook_dir }}/../../prometheus/scrapes" + state: directory + recurse: true + check_mode: false + - name: Create empty scrape config file + ansible.builtin.file: + name: "{{ playbook_dir }}/../../prometheus/scrapes/empty_scrapes.yml" + state: touch + mode: 0664 + check_mode: false diff --git a/roles/prometheus/molecule/default/tests/test_default.py b/roles/prometheus/molecule/default/tests/test_default.py index f5a392c46..068c3a332 100644 --- a/roles/prometheus/molecule/default/tests/test_default.py +++ b/roles/prometheus/molecule/default/tests/test_default.py @@ -21,6 +21,7 @@ def AnsibleDefaults(): "/etc/prometheus/consoles", "/etc/prometheus/rules", "/etc/prometheus/file_sd", + "/etc/prometheus/scrapes", "/var/lib/prometheus" ]) def test_directories(host, dirs): @@ -33,6 +34,7 @@ def test_directories(host, dirs): "/etc/prometheus/prometheus.yml", "/etc/prometheus/console_libraries/prom.lib", "/etc/prometheus/consoles/prometheus.html", + "/etc/prometheus/scrapes/empty_scrapes.yml", "/etc/prometheus/web.yml", "/etc/systemd/system/prometheus.service", "/usr/local/bin/prometheus",