From 51b2524b2548890f63b70fb5fe10e6bb5432d152 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 7 Oct 2025 08:52:50 -0400 Subject: [PATCH] Gracefully handle hostname change in metrics code * Previously, we would error out because we assumed that when we got a metrics payload from redis, that there was data in it and it was for the current host. * Now, we do not assume that since we got a metrics payload, that is well formed and for the current hostname because the hostname could have changed and we could have not yet collected metrics for the new host. --- awx/main/analytics/subsystem_metrics.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/awx/main/analytics/subsystem_metrics.py b/awx/main/analytics/subsystem_metrics.py index 5854460021..aed940bf5b 100644 --- a/awx/main/analytics/subsystem_metrics.py +++ b/awx/main/analytics/subsystem_metrics.py @@ -456,7 +456,10 @@ class CustomToPrometheusMetricsCollector(prometheus_client.registry.Collector): logger.debug(f"No metric data not found in redis for metric namespace '{self._metrics._namespace}'") return None - host_metrics = instance_data.get(my_hostname) + if not (host_metrics := instance_data.get(my_hostname)): + logger.debug(f"Metric data for this node '{my_hostname}' not found in redis for metric namespace '{self._metrics._namespace}'") + return None + for _, metric in self._metrics.METRICS.items(): entry = host_metrics.get(metric.field) if not entry: