From b4f73629f53e67e99a39567f3f274cee9c27f7ba Mon Sep 17 00:00:00 2001 From: Hamzah Qudsi Date: Mon, 26 Sep 2022 18:05:47 -0400 Subject: [PATCH] fix: have diagnostics endpoint always return a string for hmetric Previously the diagnositcs endpoint would return either a string or number for hmetric. The agent always assumed it was a string. We have not ran into this previously due to cluster_stats being somewhat broken and would always returns string. But now that has been fixedwith 79a29b3 and e139053 it can now return a number which was breaking the agent. This change makes it that hmetric is always a string. Due to this, we also move the 'Unknown health' prefix if there are no requests yet to envoy_stats.py instead if in the diag jinja template. Signed-off-by: Hamzah Qudsi --- python/ambassador/diagnostics/envoy_stats.py | 10 ++++++++-- python/templates/diag.html | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/ambassador/diagnostics/envoy_stats.py b/python/ambassador/diagnostics/envoy_stats.py index 2d3ecbb209..4a8c954c85 100644 --- a/python/ambassador/diagnostics/envoy_stats.py +++ b/python/ambassador/diagnostics/envoy_stats.py @@ -130,9 +130,15 @@ def cluster_stats(self, name: str) -> Dict[str, Union[str, bool]]: elif pct < 90: color = "yellow" - cstat.update({"health": "%d%% healthy" % pct, "hmetric": int(pct), "hcolor": color}) + cstat.update({"health": "%d%% healthy" % pct, "hmetric": str(pct), "hcolor": color}) else: - cstat.update({"health": "no requests yet", "hmetric": "waiting", "hcolor": "grey"}) + cstat.update( + { + "health": "Unknown health: no requests yet", + "hmetric": "waiting", + "hcolor": "grey", + } + ) return cstat diff --git a/python/templates/diag.html b/python/templates/diag.html index b1cbeb3cfb..d35396f134 100644 --- a/python/templates/diag.html +++ b/python/templates/diag.html @@ -166,7 +166,6 @@

DEBUG MODE



{% if cluster_stats[cluster.name].valid %} - {{ 'Unknown health: ' if cluster._hmetric is not number }} {{ cluster._health }} {% else %} Unknown health: {{ cluster_stats[cluster.name].reason }}