Skip to content

Commit

Permalink
Test metrics validity when testing Exporter
Browse files Browse the repository at this point in the history
When using the 'test' button for an exporter, we previously *only*
checked the status code and assumed things were good. It is very possible
for an incorrect endpoint to be registered, so we should ensure that the
registered endpoint produces correct Prometheus metrics.

Right now, we will return a somewhat *developer* like output, but I
expect to make the output more user friendly as we cleanup some of our
internal test URLs.
  • Loading branch information
kfdm committed Jul 3, 2024
1 parent 32f1bbd commit cdfc716
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 cdfc716

Please sign in to comment.