From 5ba9765e88da7dd15700b211794f433a6f7ea0df Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 16 Mar 2022 11:32:37 +0100 Subject: [PATCH] changed error handling for prometheus endpoint --- pyinfra/flask.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pyinfra/flask.py b/pyinfra/flask.py index e225fdb..35e3d3a 100644 --- a/pyinfra/flask.py +++ b/pyinfra/flask.py @@ -7,6 +7,10 @@ from waitress import serve from pyinfra.config import CONFIG +logger = logging.getLogger(__file__) +logger.setLevel(CONFIG.service.logging_level) + + def run_probing_webserver(app, host=None, port=None, mode=None): if not host: host = CONFIG.probing_webserver.host @@ -43,13 +47,11 @@ def set_up_probing_webserver(): @app.route("/prometheus", methods=["GET"]) def get_metrics_from_analysis_endpoint(): try: - metric = requests.get(f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus") - metric.raise_for_status() - return metric.text - except requests.exceptions.ConnectionError as err: - logging.warning(f"Got no metrics from analysis prometheus endpoint: {err}") - resp = jsonify("no analysis metrics received") - resp.status_code = 504 + resp = requests.get(f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus") + resp.raise_for_status() + return resp.text + except Exception as err: + logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}") return resp return app