From 82bd48a7545b9b244bdcdebf7ce976947eecf580 Mon Sep 17 00:00:00 2001 From: Julius Unverfehrt Date: Mon, 21 Mar 2022 15:19:15 +0100 Subject: [PATCH] fix handling of missing prometheus endpoint --- pyinfra/flask.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pyinfra/flask.py b/pyinfra/flask.py index 8196c07..fcddb97 100644 --- a/pyinfra/flask.py +++ b/pyinfra/flask.py @@ -50,11 +50,15 @@ def set_up_probing_webserver(): try: resp = requests.get(f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus") resp.raise_for_status() - return resp.text - except Exception as err: - if not informed_about_missing_prometheus_endpoint: - logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}") - informed_about_missing_prometheus_endpoint = True - return resp + except ConnectionError: + return "" + except requests.exceptions.HTTPError as err: + if resp.status_code == 404: + if not informed_about_missing_prometheus_endpoint: + logger.warning(f"Got no metrics from analysis prometheus endpoint: {err}") + informed_about_missing_prometheus_endpoint = True + else: + raise err + return resp.text return app