Skip to content

Commit

Permalink
[IMPROVEMENT] Test metrics validity when testing Exporter #526
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Jul 3, 2024
2 parents 32f1bbd + cdfc716 commit 9d31e9d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from itertools import chain

import prometheus_client
from prometheus_client.parser import text_string_to_metric_families

import requests
from django.conf import settings
from django.contrib import messages
Expand Down Expand Up @@ -667,7 +669,16 @@ def query():
try:
result = future.result()
result.raise_for_status()
yield result.url, result.status_code
metrics = list(text_string_to_metric_families(result.text))
yield (
result.url,
{
"status_code": result.status_code,
"metric_count": len(list(metrics)),
},
)
except ValueError as e:
yield result.url, f"Unable to parse metrics: {e}"
except requests.ConnectionError as e:
logger.warning("Error connecting to server")
yield e.request.url, "Error connecting to server"
Expand Down

0 comments on commit 9d31e9d

Please sign in to comment.