Skip to content

Commit

Permalink
fix: have diagnostics endpoint always return a string for hmetric
Browse files Browse the repository at this point in the history
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 <hqudsi@datawire.io>
  • Loading branch information
Hamzah Qudsi committed Sep 26, 2022
1 parent aa70060 commit b4f7362
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 8 additions & 2 deletions python/ambassador/diagnostics/envoy_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion python/templates/diag.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ <h1 style="color: red; text-align: right">DEBUG MODE</h1>
<br/><br/>
<span style="color:{{ cluster._hcolor }}">
{% if cluster_stats[cluster.name].valid %}
{{ 'Unknown health: ' if cluster._hmetric is not number }}
{{ cluster._health }}
{% else %}
Unknown health: {{ cluster_stats[cluster.name].reason }}
Expand Down

0 comments on commit b4f7362

Please sign in to comment.