Skip to content

Commit

Permalink
Add test for scrape config files
Browse files Browse the repository at this point in the history
Signed-off-by: Leonhard Mayr <[email protected]>
  • Loading branch information
manzsolutions-lpr committed Oct 2, 2024
1 parent db1e61e commit 47014f0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions roles/prometheus/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
provisioner:
playbooks:
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
inventory:
group_vars:
all:
Expand Down Expand Up @@ -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 }}"
Expand Down
20 changes: 20 additions & 0 deletions roles/prometheus/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
])
Expand Down
17 changes: 17 additions & 0 deletions roles/prometheus/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions roles/prometheus/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand Down

0 comments on commit 47014f0

Please sign in to comment.