Add native Traefik support to matrix-prometheus-nginxlog-exporter

This commit is contained in:
Slavi Pantaleev
2024-01-13 16:50:44 +02:00
parent a78a749f75
commit 262caf0d59
10 changed files with 165 additions and 63 deletions

View File

@ -1,23 +0,0 @@
---
- name: Fail if matrix-nginx-proxy role already executed
ansible.builtin.fail:
msg: >-
Trying to append prometheus-nginxlog-exporter's configuration to matrix-nginx-proxy,
but it's pointless since the matrix-nginx-proxy role is already executed.
To fix this, please change the order of roles in your playbook to make sure that
the matrix-nginx-proxy role is run after the prometheus-nginxlog-exporter role.
when: matrix_nginx_proxy_role_executed | default(False) | bool
- name: Generate prometheus-nginxlog-exporter's metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/nginxlog)
ansible.builtin.set_fact:
matrix_prometheus_nginxlog_exporter_matrix_nginx_proxy_metrics_configuration_matrix_domain: |
location /metrics/nginxlog {
{# Use the embedded DNS resolver in Docker containers to discover the service #}
resolver 127.0.0.11 valid=5s;
set $backend "{{ matrix_prometheus_nginxlog_exporter_container_hostname }}:{{ matrix_prometheus_nginxlog_exporter_container_metrics_port }}";
proxy_pass http://$backend/metrics;
}
when: matrix_prometheus_nginxlog_exporter_metrics_proxying_enabled | bool and matrix_nginx_proxy_enabled | bool
# Injection code was here

View File

@ -1,14 +1,5 @@
---
- tags:
- setup-all
- setup-prometheus-nginxlog-exporter
- install-all
- install-prometheus-nginxlog-exporter
block:
- when: matrix_prometheus_nginxlog_exporter_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/inject_into_nginx_proxy.yml"
- tags:
- setup-all
- setup-prometheus-nginxlog-exporter

View File

@ -30,6 +30,16 @@
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
- name: Ensure prometheus-nginxlog-exporter support files installed
ansible.builtin.template:
src: "{{ role_path }}/templates/{{ item }}.j2"
dest: "{{ matrix_prometheus_nginxlog_exporter_base_path }}/{{ item }}"
mode: 0640
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
with_items:
- labels
- name: Ensure prometheus-nginxlog-exporter container network is created
community.general.docker_network:
name: "{{ matrix_prometheus_nginxlog_exporter_container_network }}"

View File

@ -1,5 +1,14 @@
---
- name: (Deprecation) Catch and report renamed prometheus-nginxlog-exporter settings
ansible.builtin.fail:
msg: >-
Your configuration contains a variable, which now has a different name.
Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
when: "item.old in vars"
with_items:
- {'old': 'matrix_prometheus_nginxlog_exporter_container_hostname', 'new': 'matrix_prometheus_nginxlog_exporter_identifier'}
- name: Fail if docker image not availble for arch
ansible.builtin.fail:
msg: >
@ -16,3 +25,13 @@
in vars.yml
when: matrix_prometheus_nginxlog_exporter_docker_image_arch_check_enabled and matrix_architecture not in matrix_prometheus_nginxlog_exporter_docker_image_arch
- name: Fail if required prometheus-nginxlog-exporter settings not defined
ansible.builtin.fail:
msg: >-
You need to define a required configuration setting (`{{ item.name }}`).
when: "item.when | bool and vars[item.name] == ''"
with_items:
- {'name': 'matrix_prometheus_nginxlog_exporter_metrics_proxying_hostname', when: "{{ matrix_prometheus_nginxlog_exporter_metrics_proxying_enabled }}"}
- {'name': 'matrix_prometheus_nginxlog_exporter_metrics_proxying_path_prefix', when: "{{ matrix_prometheus_nginxlog_exporter_metrics_proxying_enabled }}"}
- {'name': 'matrix_prometheus_nginxlog_exporter_container_network', when: true}