Skip to content

Commit

Permalink
refactor(chalice): refactored heath-check package
Browse files Browse the repository at this point in the history
refactor(chalice): enhanced scope caching
dev(chalice): reduced Spot JWT TTL for testing purposes
  • Loading branch information
tahayk committed Aug 9, 2024
1 parent 0452da6 commit f4abefe
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 32 deletions.
4 changes: 2 additions & 2 deletions api/chalicelib/core/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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 = {
Expand Down Expand Up @@ -174,7 +174,7 @@ def __get_sessions_stats(*_):
}


def get_health():
def get_health(tenant_id=None):
health_map = {
"databases": {
"postgres": __check_database_pg
Expand Down
2 changes: 1 addition & 1 deletion api/chalicelib/core/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion api/env.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions api/routers/subs/health.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 1 addition & 0 deletions ee/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,4 @@ Pipfile.lock
/chalicelib/core/db_request_handler.py
/routers/subs/spot.py
/chalicelib/utils/or_cache/
/routers/subs/health.py
2 changes: 1 addition & 1 deletion ee/api/chalicelib/core/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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)
Expand Down
3 changes: 2 additions & 1 deletion ee/api/clean-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
rm -rf ./chalicelib/utils/or_cache
rm -rf ./routers/subs/health.py
2 changes: 1 addition & 1 deletion ee/api/env.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions ee/api/routers/subs/health.py

This file was deleted.

0 comments on commit f4abefe

Please sign in to comment.