From de79f77ef003a0e771548a6f2dab4e3b8ee58e19 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Mon, 9 Sep 2024 16:52:31 +0200 Subject: [PATCH] Add option to enable proxysql's prometheus exporter From version 2.1, ProxySQL has a built-in ProxySQL Prometheus exporter. This patch adds an option to easily enable this exporter [1]. [1] https://proxysql.com/documentation/prometheus-exporter Change-Id: I8776cdc0a6ec9e4e35a2424dd0984488514a711f --- ansible/group_vars/all.yml | 2 ++ ansible/roles/loadbalancer/defaults/main.yml | 3 +++ ansible/roles/loadbalancer/tasks/precheck.yml | 27 +++++++++++++++++++ .../templates/proxysql/proxysql.yaml.j2 | 3 +++ .../prometheus/templates/prometheus.yml.j2 | 13 +++++++++ ...-prometheus-exporter-7eec65a67a61f724.yaml | 7 +++++ tests/templates/globals-default.j2 | 1 + tests/test-core-openstack.sh | 14 ++++++++++ 8 files changed, 70 insertions(+) create mode 100644 releasenotes/notes/proxysql-prometheus-exporter-7eec65a67a61f724.yaml diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 2280985c87..8458005656 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -584,6 +584,7 @@ prometheus_cadvisor_port: "18080" prometheus_fluentd_integration_port: "24231" prometheus_libvirt_exporter_port: "9177" prometheus_etcd_integration_port: "{{ etcd_client_port }}" +proxysql_prometheus_exporter_port: "6070" # Prometheus alertmanager ports prometheus_alertmanager_internal_fqdn: "{{ kolla_internal_fqdn }}" @@ -1237,6 +1238,7 @@ enable_prometheus_blackbox_exporter: "{{ enable_prometheus | bool }}" enable_prometheus_rabbitmq_exporter: "{{ enable_prometheus | bool and enable_rabbitmq | bool }}" enable_prometheus_libvirt_exporter: "{{ enable_prometheus | bool and enable_nova | bool and nova_compute_virt_type in ['kvm', 'qemu'] }}" enable_prometheus_etcd_integration: "{{ enable_prometheus | bool and enable_etcd | bool }}" +enable_prometheus_proxysql_exporter: "{{ enable_prometheus | bool and enable_proxysql | bool }}" prometheus_alertmanager_user: "admin" prometheus_ceph_exporter_interval: "{{ prometheus_scrape_interval }}" diff --git a/ansible/roles/loadbalancer/defaults/main.yml b/ansible/roles/loadbalancer/defaults/main.yml index e055993187..bf6024511d 100644 --- a/ansible/roles/loadbalancer/defaults/main.yml +++ b/ansible/roles/loadbalancer/defaults/main.yml @@ -162,6 +162,9 @@ proxysql_backend_max_replication_lag: "0" proxysql_admin_user: "kolla-admin" proxysql_stats_user: "kolla-stats" +# Proxysql prometheus exporter +proxysql_prometheus_exporter_memory_metrics_interval: "60" + # Default timeout values haproxy_http_request_timeout: "10s" haproxy_http_keep_alive_timeout: "10s" diff --git a/ansible/roles/loadbalancer/tasks/precheck.yml b/ansible/roles/loadbalancer/tasks/precheck.yml index b5ff808958..e29b5ef2f4 100644 --- a/ansible/roles/loadbalancer/tasks/precheck.yml +++ b/ansible/roles/loadbalancer/tasks/precheck.yml @@ -190,6 +190,33 @@ - inventory_hostname in groups['loadbalancer'] - api_interface_address != kolla_internal_vip_address +- name: Checking free port for ProxySQL prometheus exporter (api interface) + wait_for: + host: "{{ api_interface_address }}" + port: "{{ proxysql_prometheus_exporter_port }}" + connect_timeout: 1 + timeout: 1 + state: stopped + when: + - enable_proxysql | bool + - enable_prometheus_proxysql_exporter | bool + - container_facts['proxysql'] is not defined + - inventory_hostname in groups['loadbalancer'] + +- name: Checking free port for ProxySQL prometheus exporter (vip interface) + wait_for: + host: "{{ kolla_internal_vip_address }}" + port: "{{ proxysql_prometheus_exporter_port }}" + connect_timeout: 1 + timeout: 1 + state: stopped + when: + - enable_proxysql | bool + - enable_prometheus_proxysql_exporter | bool + - proxysql_vip_prechecks + - inventory_hostname in groups['loadbalancer'] + - api_interface_address != kolla_internal_vip_address + # FIXME(yoctozepto): this req seems arbitrary, they need not be, just routable is fine - name: Checking if kolla_internal_vip_address is in the same network as api_interface on all nodes become: true diff --git a/ansible/roles/loadbalancer/templates/proxysql/proxysql.yaml.j2 b/ansible/roles/loadbalancer/templates/proxysql/proxysql.yaml.j2 index f5c6f38a31..1f8550d4f0 100644 --- a/ansible/roles/loadbalancer/templates/proxysql/proxysql.yaml.j2 +++ b/ansible/roles/loadbalancer/templates/proxysql/proxysql.yaml.j2 @@ -12,6 +12,9 @@ admin_variables: admin_credentials: "{{ proxysql_admin_user }}:{{ proxysql_admin_password }}" mysql_ifaces: "{{ api_interface_address }}:{{ proxysql_admin_port }};{{ kolla_internal_vip_address }}:{{ proxysql_admin_port }};/var/lib/kolla/proxysql/admin.sock" stats_credentials: "{{ proxysql_stats_user }}:{{ proxysql_stats_password }}" + restapi_enabled: "{{ enable_prometheus_proxysql_exporter | bool }}" + restapi_port: "{{ proxysql_prometheus_exporter_port }}" + prometheus_memory_metrics_interval: "{{ proxysql_prometheus_exporter_memory_metrics_interval }}" mysql_variables: threads: {{ proxysql_workers }} diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2 index a5d9080669..99d1298a61 100644 --- a/ansible/roles/prometheus/templates/prometheus.yml.j2 +++ b/ansible/roles/prometheus/templates/prometheus.yml.j2 @@ -252,6 +252,19 @@ scrape_configs: {% endif %} {% endfor %} +{% if enable_prometheus_proxysql_exporter | bool %} + - job_name: proxysql + static_configs: +{% for host in groups["loadbalancer"] %} + - targets: + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['proxysql_prometheus_exporter_port'] }}' +{% if hostvars[host].prometheus_instance_label | default(false, true) %} + labels: + instance: "{{ hostvars[host].prometheus_instance_label }}" +{% endif %} +{% endfor %} +{% endif %} + alerting: alertmanagers: - static_configs: diff --git a/releasenotes/notes/proxysql-prometheus-exporter-7eec65a67a61f724.yaml b/releasenotes/notes/proxysql-prometheus-exporter-7eec65a67a61f724.yaml new file mode 100644 index 0000000000..23974cdbef --- /dev/null +++ b/releasenotes/notes/proxysql-prometheus-exporter-7eec65a67a61f724.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Add ``proxysql_prometheus_exporter`` configuration parameter which + can be used to configure Prometheus to scrape ProxySQL metrics endpoints. + The default value of ``proxysql_prometheus_exporter`` is set to + the combined values of ``enable_prometheus`` and ``enable_proxysql``. diff --git a/tests/templates/globals-default.j2 b/tests/templates/globals-default.j2 index 379be37f4b..d45283b04e 100644 --- a/tests/templates/globals-default.j2 +++ b/tests/templates/globals-default.j2 @@ -129,6 +129,7 @@ enable_masakari: "yes" {% if scenario == "cells" %} enable_cells: "yes" enable_proxysql: "yes" +enable_prometheus_proxysql_exporter: "yes" {% endif %} {% if scenario == "mariadb" %} diff --git a/tests/test-core-openstack.sh b/tests/test-core-openstack.sh index 59b219cb27..083564dc26 100755 --- a/tests/test-core-openstack.sh +++ b/tests/test-core-openstack.sh @@ -481,6 +481,19 @@ function test_internal_dns_integration { fi } +function test_proxysql_prometheus_exporter { + if [[ $SCENARIO == "cells" ]]; then + if curl -v http://127.0.0.1:6070/metrics 2>/dev/null | grep '^proxysql_'; then + echo "[i] Proxysql prometheus exporter - PASS" + mkdir -p /tmp/logs/prometheus-exporters/proxysql + curl -v http://127.0.0.1:6070/metrics 2>/dev/null -o /tmp/logs/prometheus-exporters/proxysql/exporter.txt + else + echo "[e] Proxysql prometheus exporter - FAIL" + exit 1 + fi + fi +} + function test_openstack_logged { . /etc/kolla/admin-openrc.sh . ~/openstackclient-venv/bin/activate @@ -488,6 +501,7 @@ function test_openstack_logged { test_neutron_modules test_instance_boot test_internal_dns_integration + test_proxysql_prometheus_exporter # Check for x86_64 architecture to run q35 tests if [[ $(uname -m) == "x86_64" ]]; then