- further healthz improvements
This commit is contained in:
@@ -323,6 +323,7 @@ class Config(object):
|
|||||||
r'^/healthz($|/.*)',
|
r'^/healthz($|/.*)',
|
||||||
r'^/_healthz($|/.*)',
|
r'^/_healthz($|/.*)',
|
||||||
]
|
]
|
||||||
|
SECURITY_LOGIN_WITHOUT_VIEWS = True # Dit voorkomt automatische redirects
|
||||||
|
|
||||||
|
|
||||||
class DevConfig(Config):
|
class DevConfig(Config):
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ def create_app(config_file=None):
|
|||||||
|
|
||||||
# Register standard health endpoints at /healthz (liveness/readiness)
|
# Register standard health endpoints at /healthz (liveness/readiness)
|
||||||
# These must be public and not require authentication.
|
# These must be public and not require authentication.
|
||||||
try:
|
# try:
|
||||||
from flask_healthz import healthz as healthz_blueprint
|
# from flask_healthz import healthz as healthz_blueprint
|
||||||
app.register_blueprint(healthz_blueprint, url_prefix="/healthz")
|
# app.register_blueprint(healthz_blueprint, url_prefix="/healthz")
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
app.logger.warning(f"Failed to register /healthz blueprint: {e}")
|
# app.logger.warning(f"Failed to register /healthz blueprint: {e}")
|
||||||
|
|
||||||
# Custom url_for function for templates
|
# Custom url_for function for templates
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
@@ -130,11 +130,11 @@ def create_app(config_file=None):
|
|||||||
app.logger.debug(f"Before request - URL: {request.url}")
|
app.logger.debug(f"Before request - URL: {request.url}")
|
||||||
app.logger.debug(f"Before request - Session permanent: {session.permanent}")
|
app.logger.debug(f"Before request - Session permanent: {session.permanent}")
|
||||||
|
|
||||||
# Log session expiry tijd als deze bestaat
|
# # Log session expiry tijd als deze bestaat
|
||||||
if current_user.is_authenticated:
|
# if current_user.is_authenticated:
|
||||||
# Controleer of sessie permanent is (nodig voor PERMANENT_SESSION_LIFETIME)
|
# # Controleer of sessie permanent is (nodig voor PERMANENT_SESSION_LIFETIME)
|
||||||
if not session.permanent:
|
# if not session.permanent:
|
||||||
session.permanent = True
|
# session.permanent = True
|
||||||
|
|
||||||
@app.route('/debug/session')
|
@app.route('/debug/session')
|
||||||
def debug_session():
|
def debug_session():
|
||||||
@@ -201,9 +201,8 @@ def register_blueprints(app):
|
|||||||
app.register_blueprint(entitlements_bp)
|
app.register_blueprint(entitlements_bp)
|
||||||
from .views.partner_views import partner_bp
|
from .views.partner_views import partner_bp
|
||||||
app.register_blueprint(partner_bp)
|
app.register_blueprint(partner_bp)
|
||||||
from .views.healthz_views import healthz_bp, init_healtz
|
from .views.healthz_views import healthz_bp
|
||||||
app.register_blueprint(healthz_bp)
|
app.register_blueprint(healthz_bp)
|
||||||
init_healtz(app)
|
|
||||||
|
|
||||||
|
|
||||||
def register_cache_handlers(app):
|
def register_cache_handlers(app):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, current_app, request
|
from flask import Blueprint, current_app, request, jsonify
|
||||||
from flask_healthz import HealthError
|
from flask_healthz import HealthError
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from celery.exceptions import TimeoutError as CeleryTimeoutError
|
from celery.exceptions import TimeoutError as CeleryTimeoutError
|
||||||
@@ -8,7 +8,7 @@ import time
|
|||||||
from common.extensions import db, metrics, minio_client
|
from common.extensions import db, metrics, minio_client
|
||||||
from common.utils.celery_utils import current_celery
|
from common.utils.celery_utils import current_celery
|
||||||
|
|
||||||
healthz_bp = Blueprint('healthz', __name__, url_prefix='/_healthz')
|
healthz_bp = Blueprint('healthz', __name__, url_prefix='/healthz')
|
||||||
|
|
||||||
# Define Prometheus metrics
|
# Define Prometheus metrics
|
||||||
api_request_counter = Counter('api_request_count', 'API Request Count', ['method', 'endpoint'])
|
api_request_counter = Counter('api_request_count', 'API Request Count', ['method', 'endpoint'])
|
||||||
@@ -69,6 +69,22 @@ def check_minio():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@healthz_bp.route('/ready')
|
||||||
|
def ready():
|
||||||
|
"""
|
||||||
|
Health check endpoint for readiness probe
|
||||||
|
"""
|
||||||
|
return jsonify({"status": "ok"})
|
||||||
|
|
||||||
|
|
||||||
|
@healthz_bp.route('/live')
|
||||||
|
def live():
|
||||||
|
"""
|
||||||
|
Health check endpoint for liveness probe
|
||||||
|
"""
|
||||||
|
return jsonify({"status": "ok"})
|
||||||
|
|
||||||
|
|
||||||
@healthz_bp.route('/metrics')
|
@healthz_bp.route('/metrics')
|
||||||
@metrics.do_not_track()
|
@metrics.do_not_track()
|
||||||
def prometheus_metrics():
|
def prometheus_metrics():
|
||||||
@@ -76,7 +92,7 @@ def prometheus_metrics():
|
|||||||
|
|
||||||
|
|
||||||
# Custom metrics example
|
# Custom metrics example
|
||||||
@healthz_bp.before_app_request
|
@healthz_bp.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
request.start_time = time.time()
|
request.start_time = time.time()
|
||||||
api_request_counter.labels(
|
api_request_counter.labels(
|
||||||
@@ -84,17 +100,8 @@ def before_request():
|
|||||||
).inc()
|
).inc()
|
||||||
|
|
||||||
|
|
||||||
@healthz_bp.after_app_request
|
@healthz_bp.after_request
|
||||||
def after_request(response):
|
def after_request(response):
|
||||||
request_duration = time.time() - request.start_time
|
request_duration = time.time() - request.start_time
|
||||||
api_request_latency.observe(request_duration)
|
api_request_latency.observe(request_duration)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def init_healtz(app):
|
|
||||||
app.config.update(
|
|
||||||
HEALTHZ={
|
|
||||||
"live": "healthz_views.liveness",
|
|
||||||
"ready": "healthz_views.readiness",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
from flask import Blueprint, jsonify
|
from flask import Blueprint, jsonify
|
||||||
|
|
||||||
healthz_bp = Blueprint('healthz', __name__)
|
healthz_bp = Blueprint('healthz', __name__, url_prefix='/healthz')
|
||||||
|
|
||||||
@healthz_bp.route('/healthz/ready')
|
@healthz_bp.route('/ready')
|
||||||
def ready():
|
def ready():
|
||||||
"""
|
"""
|
||||||
Health check endpoint for readiness probe
|
Health check endpoint for readiness probe
|
||||||
"""
|
"""
|
||||||
return jsonify({"status": "ok"})
|
return jsonify({"status": "ok"})
|
||||||
|
|
||||||
@healthz_bp.route('/healthz/live')
|
@healthz_bp.route('/live')
|
||||||
def live():
|
def live():
|
||||||
"""
|
"""
|
||||||
Health check endpoint for liveness probe
|
Health check endpoint for liveness probe
|
||||||
|
|||||||
Reference in New Issue
Block a user