Skip to content

Commit e2d8b74

Browse files
authored
Merge pull request #377 from manzsolutions-lpr/fix-scrape-config-path
fix: scrape config files path
2 parents 8ab47f1 + 549ca65 commit e2d8b74

File tree

9 files changed

+104
-40
lines changed

9 files changed

+104
-40
lines changed

roles/prometheus/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ prometheus_static_targets_files:
9797
- prometheus/targets/*.json
9898

9999
prometheus_scrape_config_files:
100-
- prometheus/targets/*.yml
101-
- prometheus/targets/*.json
100+
- prometheus/scrape_configs/*.yml
101+
- prometheus/scrape_configs/*.json
102102

103103
# yamllint disable rule:line-length
104104
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length

roles/prometheus/meta/argument_specs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ argument_specs:
148148
- "prometheus/targets/*.json"
149149
prometheus_scrape_config_files:
150150
description:
151-
- "List of folders where ansible will look for files containing custom scrape config configuration files which will be copied to C({{ prometheus_config_dir }}/scrapes/)."
151+
- "List of folders where ansible will look for files containing custom scrape config configuration files which will be copied to C({{ prometheus_config_dir }}/scrape_configs/)."
152152
- "This feature is available starting from Prometheus v2.43.0."
153153
type: "list"
154154
elements: "str"
155155
default:
156-
- "prometheus/scrapes/*.yml"
157-
- "prometheus/scrapes/*.json"
156+
- "prometheus/scrape_configs/*.yml"
157+
- "prometheus/scrape_configs/*.json"
158158
prometheus_system_group:
159159
description:
160160
- "System group for Prometheus."

roles/prometheus/molecule/alternative/molecule.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
---
22
provisioner:
3-
playbooks:
4-
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
53
inventory:
64
group_vars:
75
all:
@@ -58,6 +56,8 @@ provisioner:
5856
- influx.example.org:8080
5957
labels:
6058
env: demo
59+
prometheus_scrape_config_files:
60+
- /tmp/prometheus/scrape_configs/*.yml
6161
prometheus_scrape_configs:
6262
- job_name: "prometheus"
6363
metrics_path: "{{ prometheus_metrics_path }}"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- name: Run local preparation
3+
hosts: localhost
4+
gather_facts: false
5+
tasks:
6+
- name: Create scrape_configs directory
7+
ansible.builtin.file:
8+
name: /tmp/prometheus/scrape_configs
9+
state: directory
10+
recurse: true
11+
check_mode: false
12+
- name: Create empty scrape config file
13+
ansible.builtin.file:
14+
name: /tmp/prometheus/scrape_configs/empty_scrapes.yml
15+
state: touch
16+
mode: 0664
17+
check_mode: false
18+
19+
- name: Import shared preparation playbook
20+
import_playbook: "../../../../.config/molecule/alternative/prepare.yml"

roles/prometheus/molecule/alternative/tests/test_alternative.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@
77
testinfra_hosts = get_target_hosts()
88

99

10-
@pytest.mark.parametrize("dirs", [
11-
"/opt/prom/etc",
12-
"/opt/prom/etc/rules",
13-
"/opt/prom/etc/file_sd",
14-
"/opt/prom/lib"
15-
])
10+
@pytest.mark.parametrize(
11+
"dirs",
12+
[
13+
"/opt/prom/etc",
14+
"/opt/prom/etc/rules",
15+
"/opt/prom/etc/file_sd",
16+
"/opt/prom/etc/scrape_configs",
17+
"/opt/prom/lib",
18+
],
19+
)
1620
def test_directories(host, dirs):
1721
d = host.file(dirs)
1822
assert d.is_directory
1923
assert d.exists
2024

2125

22-
@pytest.mark.parametrize("files", [
23-
"/opt/prom/etc/prometheus.yml",
24-
"/opt/prom/etc/rules/ansible_managed.rules",
25-
"/opt/prom/etc/file_sd/node.yml",
26-
"/opt/prom/etc/file_sd/docker.yml",
27-
"/usr/local/bin/prometheus",
28-
"/usr/local/bin/promtool"
29-
])
26+
@pytest.mark.parametrize(
27+
"files",
28+
[
29+
"/opt/prom/etc/prometheus.yml",
30+
"/opt/prom/etc/rules/ansible_managed.rules",
31+
"/opt/prom/etc/file_sd/node.yml",
32+
"/opt/prom/etc/file_sd/docker.yml",
33+
"/opt/prom/etc/scrape_configs/empty_scrapes.yml",
34+
"/usr/local/bin/prometheus",
35+
"/usr/local/bin/promtool",
36+
],
37+
)
3038
def test_files(host, files):
3139
f = host.file(files)
3240
assert f.exists
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Run local preparation
3+
hosts: localhost
4+
gather_facts: false
5+
tasks:
6+
- name: Create scrape_configs directory
7+
ansible.builtin.file:
8+
name: "{{ playbook_dir }}/../../prometheus/scrape_configs"
9+
state: directory
10+
recurse: true
11+
check_mode: false
12+
- name: Create empty scrape config file
13+
ansible.builtin.file:
14+
name: "{{ playbook_dir }}/../../prometheus/scrape_configs/empty_scrapes.yml"
15+
state: touch
16+
mode: 0664
17+
check_mode: false

roles/prometheus/molecule/default/tests/test_default.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,36 @@ def AnsibleDefaults():
1515
return yaml.full_load(stream)
1616

1717

18-
@pytest.mark.parametrize("dirs", [
19-
"/etc/prometheus",
20-
"/etc/prometheus/console_libraries",
21-
"/etc/prometheus/consoles",
22-
"/etc/prometheus/rules",
23-
"/etc/prometheus/file_sd",
24-
"/var/lib/prometheus"
25-
])
18+
@pytest.mark.parametrize(
19+
"dirs",
20+
[
21+
"/etc/prometheus",
22+
"/etc/prometheus/console_libraries",
23+
"/etc/prometheus/consoles",
24+
"/etc/prometheus/rules",
25+
"/etc/prometheus/file_sd",
26+
"/etc/prometheus/scrape_configs",
27+
"/var/lib/prometheus",
28+
],
29+
)
2630
def test_directories(host, dirs):
2731
d = host.file(dirs)
2832
assert d.is_directory
2933
assert d.exists
3034

3135

32-
@pytest.mark.parametrize("files", [
33-
"/etc/prometheus/prometheus.yml",
34-
"/etc/prometheus/console_libraries/prom.lib",
35-
"/etc/prometheus/consoles/prometheus.html",
36-
"/etc/systemd/system/prometheus.service",
37-
"/usr/local/bin/prometheus",
38-
"/usr/local/bin/promtool"
39-
])
36+
@pytest.mark.parametrize(
37+
"files",
38+
[
39+
"/etc/prometheus/prometheus.yml",
40+
"/etc/prometheus/console_libraries/prom.lib",
41+
"/etc/prometheus/consoles/prometheus.html",
42+
"/etc/prometheus/scrape_configs/empty_scrapes.yml",
43+
"/etc/systemd/system/prometheus.service",
44+
"/usr/local/bin/prometheus",
45+
"/usr/local/bin/promtool",
46+
],
47+
)
4048
def test_files(host, files):
4149
f = host.file(files)
4250
assert f.exists

roles/prometheus/tasks/configure.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
loop:
3939
- "{{ prometheus_config_dir }}/rules"
4040
- "{{ prometheus_config_dir }}/file_sd"
41-
- "{{ prometheus_config_dir }}/scrapes"
41+
- "{{ prometheus_config_dir }}/scrape_configs"
4242
become: true
4343
tags:
4444
- prometheus
@@ -135,6 +135,8 @@
135135
- prometheus
136136
- configure
137137
- prometheus_configure
138+
notify:
139+
- reload prometheus
138140

139141
- name: Copy prometheus custom static targets
140142
ansible.builtin.copy:
@@ -150,11 +152,13 @@
150152
- prometheus
151153
- configure
152154
- prometheus_configure
155+
notify:
156+
- reload prometheus
153157

154158
- name: Copy prometheus scrape config files
155159
ansible.builtin.copy:
156160
src: "{{ item }}"
157-
dest: "{{ prometheus_config_dir }}/scrapes/"
161+
dest: "{{ prometheus_config_dir }}/scrape_configs/"
158162
force: true
159163
owner: "{{ prometheus_system_user }}"
160164
group: "{{ prometheus_system_group }}"
@@ -165,3 +169,10 @@
165169
- prometheus
166170
- configure
167171
- prometheus_configure
172+
notify:
173+
- reload prometheus
174+
175+
- name: Remove "scrapes" folder replaced by "scrape_configs"
176+
ansible.builtin.file:
177+
path: "{{ prometheus_config_dir }}/scrapes"
178+
state: absent

roles/prometheus/templates/prometheus.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ scrape_configs:
3838
{% if prometheus_version is version('2.43.0', '>=') %}
3939
{% if prometheus_scrape_config_files != [] %}
4040
scrape_config_files:
41-
- scrapes/*
41+
- scrape_configs/*
4242
{% endif %}
4343
{% endif %}

0 commit comments

Comments
 (0)