56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import logging
|
|
|
|
import requests
|
|
from flask import Flask, jsonify
|
|
from waitress import serve
|
|
|
|
from pyinfra.config import CONFIG
|
|
|
|
|
|
def run_probing_webserver(app, host=None, port=None, mode=None):
|
|
if not host:
|
|
host = CONFIG.probing_webserver.host
|
|
|
|
if not port:
|
|
port = CONFIG.probing_webserver.port
|
|
|
|
if not mode:
|
|
mode = CONFIG.probing_webserver.mode
|
|
|
|
if mode == "development":
|
|
app.run(host=host, port=port, debug=True)
|
|
|
|
elif mode == "production":
|
|
serve(app, host=host, port=port)
|
|
|
|
|
|
def set_up_probing_webserver():
|
|
# TODO: implement meaningful checks
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/ready", methods=["GET"])
|
|
def ready():
|
|
resp = jsonify("OK")
|
|
resp.status_code = 200
|
|
return resp
|
|
|
|
@app.route("/health", methods=["GET"])
|
|
def healthy():
|
|
resp = jsonify("OK")
|
|
resp.status_code = 200
|
|
return resp
|
|
|
|
@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
|
|
return resp
|
|
|
|
return app
|