2022-09-07 21:32:33 -07:00
|
|
|
import time
|
|
|
|
|
import traceback
|
|
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
from flask import current_app, jsonify, request
|
2016-04-15 11:04:35 +01:00
|
|
|
from notifications_python_client.errors import HTTPError
|
2022-09-07 21:32:33 -07:00
|
|
|
from redis import RedisError
|
2016-01-11 14:54:23 +00:00
|
|
|
|
2018-02-20 11:22:17 +00:00
|
|
|
from app import status_api_client, version
|
2022-09-07 21:32:33 -07:00
|
|
|
from app.extensions import redis_client
|
2018-02-20 11:22:17 +00:00
|
|
|
from app.status import status
|
|
|
|
|
|
2016-03-03 16:50:06 +00:00
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@status.route("/_status", methods=["GET"])
|
2016-03-03 16:41:21 +00:00
|
|
|
def show_status():
|
2023-08-25 09:12:23 -07:00
|
|
|
if request.args.get("elb", None) or request.args.get("simple", None):
|
2016-03-03 16:41:21 +00:00
|
|
|
return jsonify(status="ok"), 200
|
|
|
|
|
else:
|
2016-04-06 16:36:03 +01:00
|
|
|
try:
|
|
|
|
|
api_status = status_api_client.get_status()
|
2022-09-07 21:32:33 -07:00
|
|
|
except HTTPError as err:
|
2017-11-16 16:35:24 +00:00
|
|
|
current_app.logger.exception("API failed to respond")
|
2022-09-07 21:32:33 -07:00
|
|
|
return jsonify(status="error", message=str(err.message)), 500
|
2023-08-25 09:12:23 -07:00
|
|
|
return (
|
|
|
|
|
jsonify(
|
|
|
|
|
status="ok",
|
|
|
|
|
api=api_status,
|
|
|
|
|
git_commit=version.__git_commit__,
|
|
|
|
|
build_time=version.__time__,
|
|
|
|
|
),
|
|
|
|
|
200,
|
|
|
|
|
)
|
2022-09-07 21:32:33 -07:00
|
|
|
|
|
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
@status.route("/_status/redis", methods=["GET"])
|
2022-09-07 21:32:33 -07:00
|
|
|
def show_redis_status():
|
|
|
|
|
try:
|
|
|
|
|
try:
|
|
|
|
|
api_status = {"error": "unexpected error"}
|
2023-08-25 09:12:23 -07:00
|
|
|
redis_uri = current_app.config["REDIS_URL"]
|
2022-09-07 21:32:33 -07:00
|
|
|
current_app.logger.info(f"config['REDIS_URL']: {redis_uri}")
|
2023-08-25 09:12:23 -07:00
|
|
|
redis_enabled = current_app.config["REDIS_ENABLED"]
|
2022-09-07 21:32:33 -07:00
|
|
|
current_app.logger.info(f"config['REDIS_ENABLED']: {redis_enabled}")
|
|
|
|
|
if redis_enabled:
|
|
|
|
|
current_app.logger.info("config['REDIS_ENABLED'] evaluates as True")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
now = time.time()
|
2023-08-25 09:12:23 -07:00
|
|
|
redis_client.set("mytestkey", now)
|
|
|
|
|
val = redis_client.get("mytestkey")
|
|
|
|
|
current_app.logger.info(
|
|
|
|
|
f"Retrieved value from redis for mytestkey is: {val}"
|
|
|
|
|
)
|
2022-09-07 21:32:33 -07:00
|
|
|
except RedisError as err:
|
2023-08-25 09:12:23 -07:00
|
|
|
current_app.logger.exception(
|
|
|
|
|
f"Redis service failed to respond with {err}"
|
|
|
|
|
)
|
2022-09-07 21:32:33 -07:00
|
|
|
|
2023-08-25 09:12:23 -07:00
|
|
|
api_status = (
|
|
|
|
|
status_api_client.get_count_of_live_services_and_organizations_cached()
|
|
|
|
|
)
|
2022-09-07 21:32:33 -07:00
|
|
|
except HTTPError as err:
|
|
|
|
|
current_app.logger.exception("API failed to respond")
|
|
|
|
|
return jsonify(status="error", message=str(err.message)), 500
|
2023-08-25 09:12:23 -07:00
|
|
|
return (
|
|
|
|
|
jsonify(
|
|
|
|
|
status="ok",
|
|
|
|
|
api=api_status,
|
|
|
|
|
git_commit=version.__git_commit__,
|
|
|
|
|
build_time=version.__time__,
|
|
|
|
|
),
|
|
|
|
|
200,
|
|
|
|
|
)
|
2022-09-07 21:32:33 -07:00
|
|
|
except Exception as err:
|
2023-08-25 09:12:23 -07:00
|
|
|
current_app.logger.exception(
|
|
|
|
|
f"Unhandled exception: {err} - {traceback.format_exc()}"
|
|
|
|
|
)
|
|
|
|
|
return (
|
|
|
|
|
jsonify(
|
|
|
|
|
status=f"error: {err}",
|
|
|
|
|
api=api_status,
|
|
|
|
|
git_commit=version.__git_commit__,
|
|
|
|
|
build_time=version.__time__,
|
|
|
|
|
),
|
|
|
|
|
500,
|
|
|
|
|
)
|