mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-21 19:33:04 +00:00
Merge pull request #377 from manzsolutions-lpr/fix-scrape-config-path
fix: scrape config files path
This commit is contained in:
commit
e2d8b745dc
9 changed files with 104 additions and 40 deletions
|
@ -97,8 +97,8 @@ prometheus_static_targets_files:
|
||||||
- prometheus/targets/*.json
|
- prometheus/targets/*.json
|
||||||
|
|
||||||
prometheus_scrape_config_files:
|
prometheus_scrape_config_files:
|
||||||
- prometheus/targets/*.yml
|
- prometheus/scrape_configs/*.yml
|
||||||
- prometheus/targets/*.json
|
- prometheus/scrape_configs/*.json
|
||||||
|
|
||||||
# yamllint disable rule:line-length
|
# yamllint disable rule:line-length
|
||||||
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
|
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
|
||||||
|
|
|
@ -148,13 +148,13 @@ argument_specs:
|
||||||
- "prometheus/targets/*.json"
|
- "prometheus/targets/*.json"
|
||||||
prometheus_scrape_config_files:
|
prometheus_scrape_config_files:
|
||||||
description:
|
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."
|
- "This feature is available starting from Prometheus v2.43.0."
|
||||||
type: "list"
|
type: "list"
|
||||||
elements: "str"
|
elements: "str"
|
||||||
default:
|
default:
|
||||||
- "prometheus/scrapes/*.yml"
|
- "prometheus/scrape_configs/*.yml"
|
||||||
- "prometheus/scrapes/*.json"
|
- "prometheus/scrape_configs/*.json"
|
||||||
prometheus_system_group:
|
prometheus_system_group:
|
||||||
description:
|
description:
|
||||||
- "System group for Prometheus."
|
- "System group for Prometheus."
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
---
|
---
|
||||||
provisioner:
|
provisioner:
|
||||||
playbooks:
|
|
||||||
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
|
|
||||||
inventory:
|
inventory:
|
||||||
group_vars:
|
group_vars:
|
||||||
all:
|
all:
|
||||||
|
@ -58,6 +56,8 @@ provisioner:
|
||||||
- influx.example.org:8080
|
- influx.example.org:8080
|
||||||
labels:
|
labels:
|
||||||
env: demo
|
env: demo
|
||||||
|
prometheus_scrape_config_files:
|
||||||
|
- /tmp/prometheus/scrape_configs/*.yml
|
||||||
prometheus_scrape_configs:
|
prometheus_scrape_configs:
|
||||||
- job_name: "prometheus"
|
- job_name: "prometheus"
|
||||||
metrics_path: "{{ prometheus_metrics_path }}"
|
metrics_path: "{{ prometheus_metrics_path }}"
|
||||||
|
|
20
roles/prometheus/molecule/alternative/prepare.yml
Normal file
20
roles/prometheus/molecule/alternative/prepare.yml
Normal file
|
@ -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"
|
|
@ -7,26 +7,34 @@ import pytest
|
||||||
testinfra_hosts = get_target_hosts()
|
testinfra_hosts = get_target_hosts()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("dirs", [
|
@pytest.mark.parametrize(
|
||||||
"/opt/prom/etc",
|
"dirs",
|
||||||
"/opt/prom/etc/rules",
|
[
|
||||||
"/opt/prom/etc/file_sd",
|
"/opt/prom/etc",
|
||||||
"/opt/prom/lib"
|
"/opt/prom/etc/rules",
|
||||||
])
|
"/opt/prom/etc/file_sd",
|
||||||
|
"/opt/prom/etc/scrape_configs",
|
||||||
|
"/opt/prom/lib",
|
||||||
|
],
|
||||||
|
)
|
||||||
def test_directories(host, dirs):
|
def test_directories(host, dirs):
|
||||||
d = host.file(dirs)
|
d = host.file(dirs)
|
||||||
assert d.is_directory
|
assert d.is_directory
|
||||||
assert d.exists
|
assert d.exists
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("files", [
|
@pytest.mark.parametrize(
|
||||||
"/opt/prom/etc/prometheus.yml",
|
"files",
|
||||||
"/opt/prom/etc/rules/ansible_managed.rules",
|
[
|
||||||
"/opt/prom/etc/file_sd/node.yml",
|
"/opt/prom/etc/prometheus.yml",
|
||||||
"/opt/prom/etc/file_sd/docker.yml",
|
"/opt/prom/etc/rules/ansible_managed.rules",
|
||||||
"/usr/local/bin/prometheus",
|
"/opt/prom/etc/file_sd/node.yml",
|
||||||
"/usr/local/bin/promtool"
|
"/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):
|
def test_files(host, files):
|
||||||
f = host.file(files)
|
f = host.file(files)
|
||||||
assert f.exists
|
assert f.exists
|
||||||
|
|
17
roles/prometheus/molecule/default/prepare.yml
Normal file
17
roles/prometheus/molecule/default/prepare.yml
Normal file
|
@ -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
|
|
@ -15,28 +15,36 @@ def AnsibleDefaults():
|
||||||
return yaml.full_load(stream)
|
return yaml.full_load(stream)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("dirs", [
|
@pytest.mark.parametrize(
|
||||||
"/etc/prometheus",
|
"dirs",
|
||||||
"/etc/prometheus/console_libraries",
|
[
|
||||||
"/etc/prometheus/consoles",
|
"/etc/prometheus",
|
||||||
"/etc/prometheus/rules",
|
"/etc/prometheus/console_libraries",
|
||||||
"/etc/prometheus/file_sd",
|
"/etc/prometheus/consoles",
|
||||||
"/var/lib/prometheus"
|
"/etc/prometheus/rules",
|
||||||
])
|
"/etc/prometheus/file_sd",
|
||||||
|
"/etc/prometheus/scrape_configs",
|
||||||
|
"/var/lib/prometheus",
|
||||||
|
],
|
||||||
|
)
|
||||||
def test_directories(host, dirs):
|
def test_directories(host, dirs):
|
||||||
d = host.file(dirs)
|
d = host.file(dirs)
|
||||||
assert d.is_directory
|
assert d.is_directory
|
||||||
assert d.exists
|
assert d.exists
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("files", [
|
@pytest.mark.parametrize(
|
||||||
"/etc/prometheus/prometheus.yml",
|
"files",
|
||||||
"/etc/prometheus/console_libraries/prom.lib",
|
[
|
||||||
"/etc/prometheus/consoles/prometheus.html",
|
"/etc/prometheus/prometheus.yml",
|
||||||
"/etc/systemd/system/prometheus.service",
|
"/etc/prometheus/console_libraries/prom.lib",
|
||||||
"/usr/local/bin/prometheus",
|
"/etc/prometheus/consoles/prometheus.html",
|
||||||
"/usr/local/bin/promtool"
|
"/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):
|
def test_files(host, files):
|
||||||
f = host.file(files)
|
f = host.file(files)
|
||||||
assert f.exists
|
assert f.exists
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
loop:
|
loop:
|
||||||
- "{{ prometheus_config_dir }}/rules"
|
- "{{ prometheus_config_dir }}/rules"
|
||||||
- "{{ prometheus_config_dir }}/file_sd"
|
- "{{ prometheus_config_dir }}/file_sd"
|
||||||
- "{{ prometheus_config_dir }}/scrapes"
|
- "{{ prometheus_config_dir }}/scrape_configs"
|
||||||
become: true
|
become: true
|
||||||
tags:
|
tags:
|
||||||
- prometheus
|
- prometheus
|
||||||
|
@ -135,6 +135,8 @@
|
||||||
- prometheus
|
- prometheus
|
||||||
- configure
|
- configure
|
||||||
- prometheus_configure
|
- prometheus_configure
|
||||||
|
notify:
|
||||||
|
- reload prometheus
|
||||||
|
|
||||||
- name: Copy prometheus custom static targets
|
- name: Copy prometheus custom static targets
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
|
@ -150,11 +152,13 @@
|
||||||
- prometheus
|
- prometheus
|
||||||
- configure
|
- configure
|
||||||
- prometheus_configure
|
- prometheus_configure
|
||||||
|
notify:
|
||||||
|
- reload prometheus
|
||||||
|
|
||||||
- name: Copy prometheus scrape config files
|
- name: Copy prometheus scrape config files
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ item }}"
|
src: "{{ item }}"
|
||||||
dest: "{{ prometheus_config_dir }}/scrapes/"
|
dest: "{{ prometheus_config_dir }}/scrape_configs/"
|
||||||
force: true
|
force: true
|
||||||
owner: "{{ prometheus_system_user }}"
|
owner: "{{ prometheus_system_user }}"
|
||||||
group: "{{ prometheus_system_group }}"
|
group: "{{ prometheus_system_group }}"
|
||||||
|
@ -165,3 +169,10 @@
|
||||||
- prometheus
|
- prometheus
|
||||||
- configure
|
- configure
|
||||||
- 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
|
||||||
|
|
|
@ -38,6 +38,6 @@ scrape_configs:
|
||||||
{% if prometheus_version is version('2.43.0', '>=') %}
|
{% if prometheus_version is version('2.43.0', '>=') %}
|
||||||
{% if prometheus_scrape_config_files != [] %}
|
{% if prometheus_scrape_config_files != [] %}
|
||||||
scrape_config_files:
|
scrape_config_files:
|
||||||
- scrapes/*
|
- scrape_configs/*
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue