Skip to content

Commit

Permalink
separate fastapi debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Jan 24, 2025
1 parent 378823d commit 26a6ee0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"filename": "gen3workflow/config-default.yaml",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 37
"line_number": 39
}
],
"migrations/versions/e1886270d9d2_create_system_key_table.py": [
Expand Down Expand Up @@ -209,5 +209,5 @@
}
]
},
"generated_at": "2025-01-09T21:36:04Z"
"generated_at": "2025-01-24T22:23:07Z"
}
13 changes: 9 additions & 4 deletions gen3workflow/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI
import httpx
from importlib.metadata import version
import logging
import os

from cdislogging import get_logger
Expand All @@ -18,22 +19,26 @@ def get_app(httpx_client=None) -> FastAPI:
logger.info("Initializing app")
config.validate()

debug = config["DEBUG"]
log_level = "debug" if debug else "info"

print('config["APP_DEBUG"]', config["APP_DEBUG"])
print('config["FASTAPI_DEBUG"]', config["FASTAPI_DEBUG"])
app = FastAPI(
title="Gen3Workflow",
version=version("gen3workflow"),
debug=debug,
debug=config["FASTAPI_DEBUG"],
root_path=config["DOCS_URL_PREFIX"],
)

httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING)
app.async_client = httpx_client or httpx.AsyncClient()

app.include_router(ga4gh_tes_router, tags=["GA4GH TES"])
app.include_router(s3_router, tags=["S3"])
app.include_router(storage_router, tags=["Storage"])
app.include_router(system_router, tags=["System"])

# Following will update logger level, propagate, and handlers
log_level = "debug" if config["APP_DEBUG"] else "info"
get_logger("gen3workflow", log_level=log_level)

logger.info("Initializing Arborist client")
Expand Down
4 changes: 3 additions & 1 deletion gen3workflow/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
##########

HOSTNAME: localhost
DEBUG: false
APP_DEBUG: false
# fastapi debug mode is very verbose, so the setting is separate from the main app debug mode
FASTAPI_DEBUG: false
DOCS_URL_PREFIX: /gen3workflow

# override the default Arborist URL; ignored if already set as an environment variable
Expand Down
3 changes: 2 additions & 1 deletion gen3workflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def validate_top_level_configs(self) -> None:
"additionalProperties": False,
"properties": {
"HOSTNAME": {"type": "string"},
"DEBUG": {"type": "boolean"},
"APP_DEBUG": {"type": "boolean"},
"FASTAPI_DEBUG": {"type": "boolean"},
"DOCS_URL_PREFIX": {"type": "string"},
"ARBORIST_URL": {"type": ["string", "null"]},
"MOCK_AUTH": {"type": "boolean"},
Expand Down
4 changes: 2 additions & 2 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def __init__(self, cfg):

self._remove_handlers(logging.getLogger())
cdislogging.get_logger(
None, log_level="debug" if app_config["DEBUG"] else "warn"
None, log_level="debug" if app_config["APP_DEBUG"] else "warn"
)
for logger_name in ["gunicorn", "gunicorn.error", "gunicorn.access"]:
self._remove_handlers(logging.getLogger(logger_name))
cdislogging.get_logger(
logger_name,
log_level="debug" if app_config["DEBUG"] else "info",
log_level="debug" if app_config["APP_DEBUG"] else "info",
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test-gen3workflow-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEBUG: true
APP_DEBUG: true
ARBORIST_URL: http://test-arborist-server

S3_ENDPOINTS_AWS_ACCESS_KEY_ID: test-aws-key-id
Expand Down

0 comments on commit 26a6ee0

Please sign in to comment.