changed error handling for prometheus endpoint

This commit is contained in:
Matthias Bisping 2022-03-16 11:32:37 +01:00
parent 894a6b5d4c
commit 5ba9765e88

View File

@ -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