From 7cbe112e4e35927a42c09b0b298a6bdb1be0750a Mon Sep 17 00:00:00 2001 From: Elijah DeLee Date: Thu, 16 Jun 2022 13:15:25 -0400 Subject: [PATCH] possible work around for 500 on /api/v2/metrics (#12376) we've observed this in development and some users have reported experiencing 500's on /api/v2/metrics because of a key error here where a metric is missing from a certain instance --- awx/main/analytics/subsystem_metrics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awx/main/analytics/subsystem_metrics.py b/awx/main/analytics/subsystem_metrics.py index 2d6520c33c..02d7717c09 100644 --- a/awx/main/analytics/subsystem_metrics.py +++ b/awx/main/analytics/subsystem_metrics.py @@ -40,7 +40,9 @@ class BaseM: def to_prometheus(self, instance_data): output_text = f"# HELP {self.field} {self.help_text}\n# TYPE {self.field} gauge\n" for instance in instance_data: - output_text += f'{self.field}{{node="{instance}"}} {instance_data[instance][self.field]}\n' + if self.field in instance_data[instance]: + # on upgrade, if there are stale instances, we can end up with issues where new metrics are not present + output_text += f'{self.field}{{node="{instance}"}} {instance_data[instance][self.field]}\n' return output_text