Fix exporter URL to support multinode deployments

A previous change (cf2d127) set SERVICE_HOST for constructing
exporter URLs, but SERVICE_HOST references to the controller
node IP. This breaks multinode deployments where exporters are
running on subnodes, as the health checks would try to reach the
controller instead of the local node.

This change properly checks SERVICE_IP_VERSION and uses HOST_IPV6
for IPv6 environments or HOST_IP for IPv4, ensuring the URL points
to the correct node where the exporter is actually running.

Additionally, IPv6 addresses are wrapped in square brackets as
required for URLs (e.g., http://[2001:db8::1]:9100/metrics).

A common get_host_ip_for_url function is introduced in lib/common
to centralize IP version handling and avoid code duplication across
all exporter modules.

Assisted-By: Claude (claude-sonnet-4-5)

Closes-Bug: #2141918
Change-Id: Icff76c7dc52d6444aa1c049dd6eada27016f4166
Signed-off-by: Douglas Viroel <viroel@gmail.com>
This commit is contained in:
Douglas Viroel
2026-02-25 10:10:39 -03:00
parent cf2d127fef
commit 428b9050c1
6 changed files with 43 additions and 7 deletions

27
devstack/lib/common Normal file
View File

@@ -0,0 +1,27 @@
# lib/common
# Common functions for devstack-plugin-prometheus
# Save trace setting
_XTRACE_COMMON=$(set +o | grep xtrace)
set +o xtrace
# get_host_ip_for_url
# Returns the appropriate host IP for use in URLs.
# For IPv6, ensures the IP is wrapped in brackets as required for URLs.
# For IPv4, returns the IP as-is.
function get_host_ip_for_url {
local host_ip
if [[ "$SERVICE_IP_VERSION" == 6 ]]; then
host_ip=$HOST_IPV6
# Add brackets if not already present (required for IPv6 URLs)
if [[ "$host_ip" != \[* ]]; then
host_ip="[$host_ip]"
fi
else
host_ip=$HOST_IP
fi
echo "$host_ip"
}
# Restore xtrace
$_XTRACE_COMMON

View File

@@ -84,9 +84,11 @@ function wait_for_data {
sleep 60
}
function check_data_node_exporter {
if curl -s --head --request GET "http://$SERVICE_HOST:$NODE_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
local host_ip
host_ip=$(get_host_ip_for_url)
if curl -s --head --request GET "http://$host_ip:$NODE_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
echo "#### Metrics data ####"
curl "http://$SERVICE_HOST:$NODE_EXPORTER_PORT/metrics"
curl "http://$host_ip:$NODE_EXPORTER_PORT/metrics"
else
die $LINENO "Couldn't get data from node_exporter"
fi

View File

@@ -74,9 +74,11 @@ function wait_for_data {
}
function check_data_openstack_exporter {
if curl -s --head --request GET "http://$SERVICE_HOST:$OPENSTACK_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
local host_ip
host_ip=$(get_host_ip_for_url)
if curl -s --head --request GET "http://$host_ip:$OPENSTACK_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
echo "#### Metrics data ####"
curl "http://$SERVICE_HOST:$OPENSTACK_EXPORTER_PORT/metrics"
curl "http://$host_ip:$OPENSTACK_EXPORTER_PORT/metrics"
else
die $LINENO "Couldn't get data from openstack_exporter"
fi

View File

@@ -70,9 +70,11 @@ function wait_for_podman_data {
}
function check_data_podman_exporter {
if curl -s --head --request GET "http://$SERVICE_HOST:$PODMAN_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
local host_ip
host_ip=$(get_host_ip_for_url)
if curl -s --head --request GET "http://$host_ip:$PODMAN_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
echo "#### Metrics data ####"
curl "http://$SERVICE_HOST:$PODMAN_EXPORTER_PORT/metrics"
curl "http://$host_ip:$PODMAN_EXPORTER_PORT/metrics"
else
die $LINENO "Couldn't get data from podman_exporter"
fi

View File

@@ -141,7 +141,9 @@ function wait_for_data {
}
function check_data_prometheus {
local url="http://$SERVICE_HOST:$PROMETHEUS_PORT/api/v1/label/__name__/values"
local host_ip
host_ip=$(get_host_ip_for_url)
local url="http://$host_ip:$PROMETHEUS_PORT/api/v1/label/__name__/values"
if curl -s --head --request GET "$url" | grep "200 OK" > /dev/null; then
echo "#### List of metrics names ####"

View File

@@ -5,6 +5,7 @@ _XTRACE_PROMETHEUS_PLUGIN=$(set +o | grep xtrace)
set -o xtrace
echo_summary "devstack-plugin-prometheus's plugin.sh was called..."
. $DEST/devstack-plugin-prometheus/devstack/lib/common
. $DEST/devstack-plugin-prometheus/devstack/lib/prometheus
. $DEST/devstack-plugin-prometheus/devstack/lib/node_exporter
. $DEST/devstack-plugin-prometheus/devstack/lib/openstack_exporter