Skip to content

Commit

Permalink
- added client host (should be ip address) to api_runs log
Browse files Browse the repository at this point in the history
- fixed related_codeset_ids in logging (needed query_params.getlist
  instead of get)
  • Loading branch information
Sigfried committed Oct 30, 2023
1 parent 1044a86 commit 88b17e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
APP.add_middleware(GZipMiddleware, minimum_size=1000)

@APP.middleware("http")
async def query_param_inspect(request: Request, call_next):
async def set_schema_globally_and_log_calls(request: Request, call_next):
"""
This is middleware and will be EXECUTED ON EVERY API CALL
Its purpose is to log TermHub usage to help us prioritize performance improvements
Expand All @@ -47,7 +47,7 @@ async def query_param_inspect(request: Request, call_next):
url = request.url
query_params = request.query_params # Extracting query params as a dict

codeset_ids = query_params.get("codeset_ids")
codeset_ids = query_params.getlist("codeset_ids")
if not codeset_ids:
print(f"No codeset_ids provided, not sure what monitoring to do, if any for {url}")
return await call_next(request)
Expand All @@ -61,6 +61,7 @@ async def query_param_inspect(request: Request, call_next):

rpt['host'] = os.getenv('HOSTENV', gethostname())

rpt['client'] = request.client.host

schema = query_params.get("schema")
if schema:
Expand Down
1 change: 1 addition & 0 deletions backend/db/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

DDL_API_LOG = """CREATE TABLE IF NOT EXISTS public.api_runs (
host text,
client text,
schema text not null,
api_call text not null,
codeset_ids integer[],
Expand Down

0 comments on commit 88b17e3

Please sign in to comment.