mirror of
https://github.com/prometheus-community/ansible
synced 2025-02-16 12:48:26 +00:00
Merge pull request #333 from dpavle/main
enhancement(prometheus): support prometheus2 .yml rule file format
This commit is contained in:
commit
e4384eba3a
8 changed files with 24 additions and 9 deletions
|
@ -90,7 +90,8 @@ prometheus_scrape_configs:
|
|||
prometheus_config_file: 'prometheus.yml.j2'
|
||||
|
||||
prometheus_alert_rules_files:
|
||||
- prometheus/rules/*.rules
|
||||
- prometheus/rules/*.yml
|
||||
- prometheus/rules/*.yaml
|
||||
|
||||
prometheus_static_targets_files:
|
||||
- prometheus/targets/*.yml
|
||||
|
|
|
@ -125,19 +125,20 @@ argument_specs:
|
|||
default: "prometheus.yml.j2"
|
||||
prometheus_alert_rules:
|
||||
description:
|
||||
- "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/ansible_managed.rules)."
|
||||
- "Alerting rules can be also provided by other files located in C({{ prometheus_config_dir }}/rules/) which have C(*.rules) extension"
|
||||
- "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/ansible_managed.yml)."
|
||||
- "Alerting rules can be also provided by other files located in C({{ prometheus_config_dir }}/rules/) which have a C(*.yml) or C(*.yaml) extension"
|
||||
- "Please see default values in role defaults/main.yml"
|
||||
type: "list"
|
||||
elements: "dict"
|
||||
prometheus_alert_rules_files:
|
||||
description:
|
||||
- "List of folders where ansible will look for files containing alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/)."
|
||||
- "Files must have C(*.rules) extension"
|
||||
- "Files must have a C(*.yml) or C(*.yaml) extension"
|
||||
type: "list"
|
||||
elements: "str"
|
||||
default:
|
||||
- "prometheus/rules/*.rules"
|
||||
- "prometheus/rules/*.yml"
|
||||
- "prometheus/rules/*.yaml"
|
||||
prometheus_static_targets_files:
|
||||
description:
|
||||
- "List of folders where ansible will look for files containing custom static target configuration files which will be copied to C({{ prometheus_config_dir }}/file_sd/)."
|
||||
|
|
|
@ -27,7 +27,7 @@ def test_directories(host, dirs):
|
|||
"files",
|
||||
[
|
||||
"/opt/prom/etc/prometheus.yml",
|
||||
"/opt/prom/etc/rules/ansible_managed.rules",
|
||||
"/opt/prom/etc/rules/ansible_managed.yml",
|
||||
"/opt/prom/etc/file_sd/node.yml",
|
||||
"/opt/prom/etc/file_sd/docker.yml",
|
||||
"/opt/prom/etc/scrape_configs/empty_scrapes.yml",
|
||||
|
|
|
@ -52,7 +52,7 @@ def test_files(host, files):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("files", [
|
||||
"/etc/prometheus/rules/ansible_managed.rules"
|
||||
"/etc/prometheus/rules/ansible_managed.yml"
|
||||
])
|
||||
def test_absent(host, files):
|
||||
f = host.file(files)
|
||||
|
|
|
@ -65,8 +65,8 @@
|
|||
|
||||
- name: Alerting rules file
|
||||
ansible.builtin.template:
|
||||
src: "alert.rules.j2"
|
||||
dest: "{{ prometheus_config_dir }}/rules/ansible_managed.rules"
|
||||
src: "ansible_managed.yml.j2"
|
||||
dest: "{{ prometheus_config_dir }}/rules/ansible_managed.yml"
|
||||
owner: "{{ prometheus_system_user }}"
|
||||
group: "{{ prometheus_system_group }}"
|
||||
mode: 0640
|
||||
|
|
|
@ -65,6 +65,17 @@
|
|||
- prometheus_alertmanager_config == []
|
||||
- prometheus_alert_rules != []
|
||||
|
||||
- name: Alert when alert rules files are found in the old .rules format
|
||||
ansible.builtin.debug:
|
||||
msg: >
|
||||
prometheus_alert_rules_files contains rules in the old .rules file format.
|
||||
This format has been deprecated in favour of the new YAML format since Prometheus v2.x.
|
||||
You can update your rules using promtool: promtool update rules <filenames>
|
||||
|
||||
If your rules are already in the YAML format but with the .rules extension, you can safely ignore this message,
|
||||
or rename the files to <filename>.yaml or <filename>.yml to get rid of it.
|
||||
when: prometheus_alert_rules_files | select('search', '.rules$') | list | length > 0
|
||||
|
||||
- name: Discover latest version
|
||||
ansible.builtin.set_fact:
|
||||
prometheus_version: "{{ (lookup('url', 'https://api.github.com/repos/{{ _prometheus_repo}}/releases/latest', headers=_github_api_headers,
|
||||
|
|
|
@ -19,6 +19,8 @@ remote_read:
|
|||
|
||||
{% if not prometheus_agent_mode and prometheus_alert_rules_files != [] %}
|
||||
rule_files:
|
||||
- {{ prometheus_config_dir }}/rules/*.yml
|
||||
- {{ prometheus_config_dir }}/rules/*.yaml
|
||||
- {{ prometheus_config_dir }}/rules/*.rules
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue