From c358a2d586ebc6bd03f2060ac36295f003dfa17c Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Tue, 21 Dec 2021 11:43:23 +0000 Subject: [PATCH] Revert "Use friendly target names in Prometheus" This reverts commit 4ff65b7661ea06e9fa8631c4eb82232e03af77d7. Reason for revert: adds assumptions about inventory_hostname being resolvable. Closes-Bug: #1955563 Change-Id: Ifa2b2ea8622f56c34b8f7f37fee53133272ff925 --- .../prometheus/templates/prometheus.yml.j2 | 72 ++++--------------- .../notes/fix-1955563-42a14bb080e15df2.yaml | 9 +++ 2 files changed, 21 insertions(+), 60 deletions(-) create mode 100644 releasenotes/notes/fix-1955563-42a14bb080e15df2.yaml diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2 index 1e829648ac..ac11aa3869 100644 --- a/ansible/roles/prometheus/templates/prometheus.yml.j2 +++ b/ansible/roles/prometheus/templates/prometheus.yml.j2 @@ -17,24 +17,16 @@ scrape_configs: static_configs: - targets: {% for host in groups['prometheus'] %} - - '{{ host }}:{{ prometheus_port }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ prometheus_port }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% if enable_prometheus_node_exporter | bool %} - job_name: node static_configs: - targets: {% for host in groups['prometheus-node-exporter'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_node_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_mysqld_exporter | bool %} @@ -42,12 +34,8 @@ scrape_configs: static_configs: - targets: {% for host in groups['prometheus-mysqld-exporter'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_mysqld_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_haproxy_exporter | bool %} @@ -55,12 +43,8 @@ scrape_configs: static_configs: - targets: {% for host in groups['prometheus-haproxy-exporter'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_haproxy_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_rabbitmq_exporter | bool %} @@ -68,12 +52,8 @@ scrape_configs: static_configs: - targets: {% for host in groups['rabbitmq'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_rabbitmq_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_memcached_exporter | bool %} @@ -81,12 +61,8 @@ scrape_configs: static_configs: - targets: {% for host in groups['prometheus-memcached-exporter'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_memcached_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_cadvisor | bool %} @@ -94,12 +70,8 @@ scrape_configs: static_configs: - targets: {% for host in groups["prometheus-cadvisor"] %} - - '{{ host }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_cadvisor_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_fluentd_integration | bool %} @@ -107,12 +79,8 @@ scrape_configs: static_configs: - targets: {% for host in groups['fluentd'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_fluentd_integration_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_fluentd_integration_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_ceph_mgr_exporter | bool %} @@ -123,10 +91,6 @@ scrape_configs: {% for exporter in prometheus_ceph_mgr_exporter_endpoints %} - '{{ exporter }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_openstack_exporter | bool %} @@ -137,12 +101,8 @@ scrape_configs: static_configs: - targets: {% for host in groups["prometheus-openstack-exporter"] %} - - '{{ host }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_openstack_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_elasticsearch_exporter | bool %} @@ -151,12 +111,8 @@ scrape_configs: static_configs: - targets: {% for host in groups["prometheus-elasticsearch-exporter"] %} - - '{{ host }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_elasticsearch_exporter_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance {% endif %} {% if enable_prometheus_blackbox_exporter | bool and prometheus_blackbox_exporter_endpoints | length > 0 | bool %} @@ -194,18 +150,14 @@ scrape_configs: static_configs: - targets: {% for host in groups['prometheus-alertmanager'] %} - - '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}' {% endfor %} - relabel_configs: - - source_labels: [__address__] - regex: "([^:]+):\\d+" - target_label: instance alerting: alertmanagers: - static_configs: - targets: {% for host in groups["prometheus-alertmanager"] %} - - '{{ host }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}' + - '{{ 'api' | kolla_address(host) | put_address_in_context('url') }}:{{ hostvars[host]['prometheus_alertmanager_port'] }}' {% endfor %} {% endif %} diff --git a/releasenotes/notes/fix-1955563-42a14bb080e15df2.yaml b/releasenotes/notes/fix-1955563-42a14bb080e15df2.yaml new file mode 100644 index 0000000000..5b46927f30 --- /dev/null +++ b/releasenotes/notes/fix-1955563-42a14bb080e15df2.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixes an issue with Prometheus scraping when targets' Ansible inventory + hostnames (``inventory_hostname``) do not resolve to reachable IP + addresses. Reverts to the previous behaviour of using IP addresses to + communicate with targets. The side effect of this is that targets instances + will again be labelled using IP addresses rather than hostnames. + `LP#1955563 `__