- further healthz improvements
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
from flask import Blueprint, current_app, request
|
from flask import Blueprint, current_app, request
|
||||||
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
|
||||||
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
||||||
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'])
|
||||||
@@ -18,7 +17,7 @@ def liveness():
|
|||||||
# Basic check to see if the app is running
|
# Basic check to see if the app is running
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HealthError("Liveness check failed")
|
raise Exception("Liveness check failed")
|
||||||
|
|
||||||
|
|
||||||
def readiness():
|
def readiness():
|
||||||
@@ -30,7 +29,7 @@ def readiness():
|
|||||||
}
|
}
|
||||||
|
|
||||||
if not all(checks.values()):
|
if not all(checks.values()):
|
||||||
raise HealthError("Readiness check failed")
|
raise Exception("Readiness check failed")
|
||||||
|
|
||||||
|
|
||||||
def check_database():
|
def check_database():
|
||||||
@@ -72,11 +71,3 @@ def check_minio():
|
|||||||
def prometheus_metrics():
|
def prometheus_metrics():
|
||||||
return generate_latest(), 200, {'Content-Type': CONTENT_TYPE_LATEST}
|
return generate_latest(), 200, {'Content-Type': CONTENT_TYPE_LATEST}
|
||||||
|
|
||||||
|
|
||||||
def init_healtz(app):
|
|
||||||
app.config.update(
|
|
||||||
HEALTHZ={
|
|
||||||
"live": "healthz_views.liveness",
|
|
||||||
"ready": "healthz_views.readiness",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -86,14 +86,6 @@ def create_app(config_file=None):
|
|||||||
# Register Cache Handlers
|
# Register Cache Handlers
|
||||||
register_cache_handlers(app)
|
register_cache_handlers(app)
|
||||||
|
|
||||||
# Register standard health endpoints at /healthz (liveness/readiness)
|
|
||||||
# These must be public and not require authentication.
|
|
||||||
# try:
|
|
||||||
# from flask_healthz import healthz as healthz_blueprint
|
|
||||||
# app.register_blueprint(healthz_blueprint, url_prefix="/healthz")
|
|
||||||
# except Exception as 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
|
||||||
def override_url_for():
|
def override_url_for():
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from flask import Blueprint, current_app, request, jsonify
|
from flask import Blueprint, current_app, request, jsonify
|
||||||
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
|
||||||
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
from prometheus_client import Counter, Histogram, generate_latest, CONTENT_TYPE_LATEST
|
||||||
@@ -20,7 +19,7 @@ def liveness():
|
|||||||
# Basic check to see if the app is running
|
# Basic check to see if the app is running
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HealthError("Liveness check failed")
|
raise Exception("Liveness check failed")
|
||||||
|
|
||||||
|
|
||||||
def readiness():
|
def readiness():
|
||||||
@@ -32,7 +31,7 @@ def readiness():
|
|||||||
}
|
}
|
||||||
|
|
||||||
if not all(checks.values()):
|
if not all(checks.values()):
|
||||||
raise HealthError("Readiness check failed")
|
raise Exception("Readiness check failed")
|
||||||
|
|
||||||
|
|
||||||
def check_database():
|
def check_database():
|
||||||
|
|||||||
Reference in New Issue
Block a user