fix a bug in the API metrics endpoint

The metrics JSON renderer shouldn't try to parse data that isn't
a string (generally, this represents things like HTTP 403)
This commit is contained in:
Ryan Petrello 2019-08-14 10:40:21 -04:00
parent 31308e3795
commit a45c93ed47
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -109,6 +109,11 @@ class AnsiDownloadRenderer(PlainTextRenderer):
class PrometheusJSONRenderer(renderers.JSONRenderer):
def render(self, data, accepted_media_type=None, renderer_context=None):
if isinstance(data, dict):
# HTTP errors are {'detail': ErrorDetail(string='...', code=...)}
return super(PrometheusJSONRenderer, self).render(
data, accepted_media_type, renderer_context
)
parsed_metrics = text_string_to_metric_families(data)
data = {}
for family in parsed_metrics: