Skip to content
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

fix: scrape config files path #377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ prometheus_static_targets_files:
- prometheus/targets/*.json

prometheus_scrape_config_files:
- prometheus/targets/*.yml
- prometheus/targets/*.json
- prometheus/scrape_configs/*.yml
- prometheus/scrape_configs/*.json

# yamllint disable rule:line-length
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
Expand Down
6 changes: 3 additions & 3 deletions roles/prometheus/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ argument_specs:
- "prometheus/targets/*.json"
prometheus_scrape_config_files:
description:
- "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/)."
- "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/)."
- "This feature is available starting from Prometheus v2.43.0."
type: "list"
elements: "str"
default:
- "prometheus/scrapes/*.yml"
- "prometheus/scrapes/*.json"
- "prometheus/scrape_configs/*.yml"
- "prometheus/scrape_configs/*.json"
prometheus_system_group:
description:
- "System group for Prometheus."
Expand Down
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/scrape_configs/*.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 scrape_configs directory
ansible.builtin.file:
name: /tmp/prometheus/scrape_configs
state: directory
recurse: true
check_mode: false
- name: Create empty scrape config file
ansible.builtin.file:
name: /tmp/prometheus/scrape_configs/empty_scrapes.yml
state: touch
mode: 0664
check_mode: false

- name: Import shared preparation playbook
import_playbook: "../../../../.config/molecule/alternative/prepare.yml"
36 changes: 22 additions & 14 deletions roles/prometheus/molecule/alternative/tests/test_alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@
testinfra_hosts = get_target_hosts()


@pytest.mark.parametrize("dirs", [
"/opt/prom/etc",
"/opt/prom/etc/rules",
"/opt/prom/etc/file_sd",
"/opt/prom/lib"
])
@pytest.mark.parametrize(
"dirs",
[
"/opt/prom/etc",
"/opt/prom/etc/rules",
"/opt/prom/etc/file_sd",
"/opt/prom/etc/scrape_configs",
"/opt/prom/lib",
],
)
def test_directories(host, dirs):
d = host.file(dirs)
assert d.is_directory
assert d.exists


@pytest.mark.parametrize("files", [
"/opt/prom/etc/prometheus.yml",
"/opt/prom/etc/rules/ansible_managed.rules",
"/opt/prom/etc/file_sd/node.yml",
"/opt/prom/etc/file_sd/docker.yml",
"/usr/local/bin/prometheus",
"/usr/local/bin/promtool"
])
@pytest.mark.parametrize(
"files",
[
"/opt/prom/etc/prometheus.yml",
"/opt/prom/etc/rules/ansible_managed.rules",
"/opt/prom/etc/file_sd/node.yml",
"/opt/prom/etc/file_sd/docker.yml",
"/opt/prom/etc/scrape_configs/empty_scrapes.yml",
"/usr/local/bin/prometheus",
"/usr/local/bin/promtool",
],
)
def test_files(host, files):
f = host.file(files)
assert f.exists
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 scrape_configs directory
ansible.builtin.file:
name: "{{ playbook_dir }}/../../prometheus/scrape_configs"
state: directory
recurse: true
check_mode: false
- name: Create empty scrape config file
ansible.builtin.file:
name: "{{ playbook_dir }}/../../prometheus/scrape_configs/empty_scrapes.yml"
state: touch
mode: 0664
check_mode: false
40 changes: 24 additions & 16 deletions roles/prometheus/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,36 @@ def AnsibleDefaults():
return yaml.full_load(stream)


@pytest.mark.parametrize("dirs", [
"/etc/prometheus",
"/etc/prometheus/console_libraries",
"/etc/prometheus/consoles",
"/etc/prometheus/rules",
"/etc/prometheus/file_sd",
"/var/lib/prometheus"
])
@pytest.mark.parametrize(
"dirs",
[
"/etc/prometheus",
"/etc/prometheus/console_libraries",
"/etc/prometheus/consoles",
"/etc/prometheus/rules",
"/etc/prometheus/file_sd",
"/etc/prometheus/scrape_configs",
"/var/lib/prometheus",
],
)
def test_directories(host, dirs):
d = host.file(dirs)
assert d.is_directory
assert d.exists


@pytest.mark.parametrize("files", [
"/etc/prometheus/prometheus.yml",
"/etc/prometheus/console_libraries/prom.lib",
"/etc/prometheus/consoles/prometheus.html",
"/etc/systemd/system/prometheus.service",
"/usr/local/bin/prometheus",
"/usr/local/bin/promtool"
])
@pytest.mark.parametrize(
"files",
[
"/etc/prometheus/prometheus.yml",
"/etc/prometheus/console_libraries/prom.lib",
"/etc/prometheus/consoles/prometheus.html",
"/etc/prometheus/scrape_configs/empty_scrapes.yml",
"/etc/systemd/system/prometheus.service",
"/usr/local/bin/prometheus",
"/usr/local/bin/promtool",
],
)
def test_files(host, files):
f = host.file(files)
assert f.exists
Expand Down
15 changes: 13 additions & 2 deletions roles/prometheus/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
loop:
- "{{ prometheus_config_dir }}/rules"
- "{{ prometheus_config_dir }}/file_sd"
- "{{ prometheus_config_dir }}/scrapes"
- "{{ prometheus_config_dir }}/scrape_configs"
become: true
tags:
- prometheus
Expand Down Expand Up @@ -135,6 +135,8 @@
- prometheus
- configure
- prometheus_configure
notify:
- reload prometheus

- name: Copy prometheus custom static targets
ansible.builtin.copy:
Expand All @@ -150,11 +152,13 @@
- prometheus
- configure
- prometheus_configure
notify:
- reload prometheus

- name: Copy prometheus scrape config files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/scrapes/"
dest: "{{ prometheus_config_dir }}/scrape_configs/"
force: true
owner: "{{ prometheus_system_user }}"
group: "{{ prometheus_system_group }}"
Expand All @@ -165,3 +169,10 @@
- prometheus
- configure
- prometheus_configure
notify:
- reload prometheus

- name: Remove "scrapes" folder replaced by "scrape_configs"
ansible.builtin.file:
path: "{{ prometheus_config_dir }}/scrapes"
state: absent
2 changes: 1 addition & 1 deletion roles/prometheus/templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ scrape_configs:
{% if prometheus_version is version('2.43.0', '>=') %}
{% if prometheus_scrape_config_files != [] %}
scrape_config_files:
- scrapes/*
- scrape_configs/*
{% endif %}
{% endif %}
Loading