From 3e6a1e5468226a529d3a862aaf99050866eefc7f Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Fri, 9 Aug 2024 11:50:50 +0200 Subject: [PATCH] Dev (#2476) * refactor(chalice): upgraded dependencies * refactor(chalice): upgraded dependencies feat(chalice): support heatmaps * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * refactor(chalice): upgraded dependencies * refactor(chalice): upgraded dependencies feat(chalice): support heatmaps * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * refactor(chalice): upgraded dependencies refactor(crons): upgraded dependencies refactor(alerts): upgraded dependencies * feat(chalice): get top 10 values for autocomplete CH * refactor(chalice): cleaned code refactor(chalice): upgraded dependencies refactor(alerts): upgraded dependencies refactor(crons): upgraded dependencies * feat(chalice): autocomplete return top 10 with stats * fix(chalice): fixed autocomplete top 10 meta-filters * refactor(chalice): refactored heath-check package refactor(chalice): enhanced scope caching dev(chalice): reduced Spot JWT TTL for testing purposes --- api/chalicelib/core/health.py | 4 ++-- api/chalicelib/core/scope.py | 2 +- api/env.default | 2 +- api/routers/subs/health.py | 7 +++++-- ee/api/.gitignore | 1 + ee/api/chalicelib/core/scope.py | 2 +- ee/api/clean-dev.sh | 3 ++- ee/api/env.default | 2 +- ee/api/routers/subs/health.py | 23 ----------------------- 9 files changed, 14 insertions(+), 32 deletions(-) delete mode 100644 ee/api/routers/subs/health.py diff --git a/api/chalicelib/core/health.py b/api/chalicelib/core/health.py index 6734021fe..574b2649a 100644 --- a/api/chalicelib/core/health.py +++ b/api/chalicelib/core/health.py @@ -11,7 +11,7 @@ from chalicelib.utils.TimeUTC import TimeUTC def app_connection_string(name, port, path): namespace = config("POD_NAMESPACE", default="app") conn_string = config("CLUSTER_URL", default="svc.cluster.local") - return f"http://{'.'.join(filter(None,[name,namespace,conn_string]))}:{port}/{path}" + return f"http://{'.'.join(filter(None, [name, namespace, conn_string]))}:{port}/{path}" HEALTH_ENDPOINTS = { @@ -174,7 +174,7 @@ def __get_sessions_stats(*_): } -def get_health(): +def get_health(tenant_id=None): health_map = { "databases": { "postgres": __check_database_pg diff --git a/api/chalicelib/core/scope.py b/api/chalicelib/core/scope.py index 8e9046602..44d3a8963 100644 --- a/api/chalicelib/core/scope.py +++ b/api/chalicelib/core/scope.py @@ -4,7 +4,7 @@ import schemas from chalicelib.utils import helper from chalicelib.utils import pg_client -cache = TTLCache(maxsize=1, ttl=24 * 60 * 60) +cache = TTLCache(maxsize=1, ttl=60) @cached(cache) diff --git a/api/env.default b/api/env.default index eee43e4fb..7351d6352 100644 --- a/api/env.default +++ b/api/env.default @@ -33,7 +33,7 @@ JWT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_REFRESH_EXPIRATION=604800 JWT_SPOT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_SECRET=SECRET -JWT_SPOT_EXPIRATION=6000 +JWT_SPOT_EXPIRATION=300 jwt_secret="SET A RANDOM STRING HERE" pg_dbname=postgres pg_host=postgresql.db.svc.cluster.local diff --git a/api/routers/subs/health.py b/api/routers/subs/health.py index 245f039c7..3a41feb45 100644 --- a/api/routers/subs/health.py +++ b/api/routers/subs/health.py @@ -1,17 +1,20 @@ from decouple import config +from fastapi import Depends from fastapi import HTTPException, status +import schemas from chalicelib.core import health, tenants +from or_dependencies import OR_context from routers.base import get_routers public_app, app, app_apikey = get_routers() @app.get('/healthz', tags=["health-check"]) -def get_global_health_status(): +def get_global_health_status(context: schemas.CurrentContext = Depends(OR_context)): if config("LOCAL_DEV", cast=bool, default=False): return {"data": ""} - return {"data": health.get_health()} + return {"data": health.get_health(context.tenant_id)} if not tenants.tenants_exists_sync(use_pool=False): diff --git a/ee/api/.gitignore b/ee/api/.gitignore index c6060a76e..8d6bc0036 100644 --- a/ee/api/.gitignore +++ b/ee/api/.gitignore @@ -275,3 +275,4 @@ Pipfile.lock /chalicelib/core/db_request_handler.py /routers/subs/spot.py /chalicelib/utils/or_cache/ +/routers/subs/health.py diff --git a/ee/api/chalicelib/core/scope.py b/ee/api/chalicelib/core/scope.py index 4494d7105..9c8e48fd5 100644 --- a/ee/api/chalicelib/core/scope.py +++ b/ee/api/chalicelib/core/scope.py @@ -4,7 +4,7 @@ import schemas from chalicelib.utils import helper from chalicelib.utils import pg_client -cache = TTLCache(maxsize=1, ttl=24 * 60 * 60) +cache = TTLCache(maxsize=1000, ttl=60) @cached(cache) diff --git a/ee/api/clean-dev.sh b/ee/api/clean-dev.sh index c9858ca36..ccc3d402f 100755 --- a/ee/api/clean-dev.sh +++ b/ee/api/clean-dev.sh @@ -95,4 +95,5 @@ rm -rf ./chalicelib/core/usability_testing/ rm -rf ./chalicelib/core/db_request_handler.py rm -rf ./chalicelib/core/db_request_handler.py rm -rf ./routers/subs/spot.py -rm -rf ./chalicelib/utils/or_cache \ No newline at end of file +rm -rf ./chalicelib/utils/or_cache +rm -rf ./routers/subs/health.py \ No newline at end of file diff --git a/ee/api/env.default b/ee/api/env.default index e4d6f1948..baad697cd 100644 --- a/ee/api/env.default +++ b/ee/api/env.default @@ -51,7 +51,7 @@ JWT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_REFRESH_EXPIRATION=604800 JWT_SPOT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_SECRET=SECRET -JWT_SPOT_EXPIRATION=6000 +JWT_SPOT_EXPIRATION=300 jwt_secret="SET A RANDOM STRING HERE" KAFKA_SERVERS=kafka.db.svc.cluster.local:9092 KAFKA_USE_SSL=false diff --git a/ee/api/routers/subs/health.py b/ee/api/routers/subs/health.py deleted file mode 100644 index 21f9433b7..000000000 --- a/ee/api/routers/subs/health.py +++ /dev/null @@ -1,23 +0,0 @@ -from fastapi import Depends -from fastapi import HTTPException, status - -import schemas -from chalicelib.core import health, tenants -from or_dependencies import OR_context -from routers.base import get_routers - -public_app, app, app_apikey = get_routers() - - -@app.get('/healthz', tags=["health-check"]) -def get_global_health_status(context: schemas.CurrentContext = Depends(OR_context)): - return {"data": health.get_health(tenant_id=context.tenant_id)} - - -if not tenants.tenants_exists_sync(use_pool=False): - @public_app.get('/health', tags=["health-check"]) - async def get_public_health_status(): - if await tenants.tenants_exists(): - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Not Found") - - return {"data": health.get_health()}