From 8eb9dcfb0ff23d355ffc266718a3f3ecb119c8a4 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 25 Sep 2025 09:55:35 +0800 Subject: [PATCH] chore(docker): update Python version to 3.12 in Dockerfiles; enhance logging in content, devops, notification, and payment services --- apps/content/Dockerfile | 2 +- apps/content/backend/content/content_service.py | 15 ++++++++++++--- apps/content/webapi/bootstrap/application.py | 14 ++++++++++++++ apps/devops/Dockerfile | 2 +- apps/devops/app/bootstrap/application.py | 11 +++++++++++ apps/devops/app/common/config/app_settings.py | 6 +++--- apps/notification/Dockerfile | 2 +- apps/notification/webapi/bootstrap/application.py | 1 + .../webapi/bootstrap/freeleaps_app.py | 10 ++++++++++ apps/payment/Dockerfile | 2 +- apps/payment/webapi/bootstrap/application.py | 1 + apps/payment/webapi/bootstrap/freeleaps_app.py | 12 ++++++++++++ 12 files changed, 68 insertions(+), 10 deletions(-) diff --git a/apps/content/Dockerfile b/apps/content/Dockerfile index bfad1fd..efc13d4 100644 --- a/apps/content/Dockerfile +++ b/apps/content/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim-buster +FROM python:3.12-slim # docker settings ARG CONTAINER_APP_ROOT="/app" diff --git a/apps/content/backend/content/content_service.py b/apps/content/backend/content/content_service.py index b7c16ac..2179958 100644 --- a/apps/content/backend/content/content_service.py +++ b/apps/content/backend/content/content_service.py @@ -6,15 +6,18 @@ from common.constants.region import UserRegion from backend.document.document_manager import DocumentManager from .content_sharepoint_manager import ContentSharePointManager from backend.content.constants import ContentSource +from common.log.module_logger import ModuleLogger class ContentService: def __init__(self) -> None: - pass + self.module_logger = ModuleLogger(sender_id="ContentService") async def retrieve_content_directories_for_folder( self, folder_name: str, region: UserRegion ) -> List[ContentDirectory]: + await self.module_logger.log_info(f"Retrieving content directories for folder: {folder_name}, region: {region.name}") + folder = ( await ContentFolderDoc.find( ContentFolderDoc.folder_name == folder_name, @@ -26,12 +29,18 @@ class ContentService: if folder is None or folder.valid_thru.replace( tzinfo=timezone.utc ) < datetime.now(timezone.utc): + await self.module_logger.log_info(f"Folder cache expired or not found, fetching from SharePoint: {folder_name}") folder = await ContentSharePointManager().retrieve_directories_for_folder( folder_name=folder_name, region=region ) - return folder.content_directories if folder else None + result = folder.content_directories if folder else None + await self.module_logger.log_info(f"Successfully retrieved {len(result) if result else 0} content directories for folder: {folder_name}") + return result async def retrieve_content_as_media_data(self, document_id: str) -> Optional[str]: + await self.module_logger.log_info(f"Retrieving content as media data for document ID: {document_id}") document_manager = DocumentManager() - return await document_manager.retrieve_document_as_http_media(document_id) + result = await document_manager.retrieve_document_as_http_media(document_id) + await self.module_logger.log_info(f"Successfully retrieved media data for document ID: {document_id}") + return result diff --git a/apps/content/webapi/bootstrap/application.py b/apps/content/webapi/bootstrap/application.py index 038f61b..4c076d1 100644 --- a/apps/content/webapi/bootstrap/application.py +++ b/apps/content/webapi/bootstrap/application.py @@ -13,6 +13,7 @@ from webapi.providers import probes from webapi.providers import metrics from .freeleaps_app import FreeleapsApp from common.config.app_settings import app_settings +from common.log.module_logger import ModuleLogger def create_app() -> FastAPI: @@ -21,6 +22,10 @@ def create_app() -> FastAPI: app = FreeleapsApp() register_logger() + + # Create application logger for startup logging + app_logger = ModuleLogger(sender_id="ApplicationBootstrap") + register(app, exception_handler) register(app, database) register(app, router) @@ -37,6 +42,15 @@ def create_app() -> FastAPI: # Register metrics APIs if enabled if app_settings.METRICS_ENABLED: register(app, metrics) + + # Log application startup completion + import asyncio + async def log_startup(): + await app_logger.log_info("Content application initialized successfully") + + # Run the async logging + asyncio.create_task(log_startup()) + return app diff --git a/apps/devops/Dockerfile b/apps/devops/Dockerfile index 1d96106..6b07b97 100644 --- a/apps/devops/Dockerfile +++ b/apps/devops/Dockerfile @@ -15,7 +15,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Set environment variables -ENV LOG_BASE_PATH=/app/log/devsvc +ENV LOG_BASE_PATH=/app/log/devops # Create necessary directories RUN mkdir -p /app/log/devops diff --git a/apps/devops/app/bootstrap/application.py b/apps/devops/app/bootstrap/application.py index 3cf635b..0528ed0 100644 --- a/apps/devops/app/bootstrap/application.py +++ b/apps/devops/app/bootstrap/application.py @@ -11,6 +11,7 @@ from app.providers import probes from app.providers import exception_handler from app.providers import message_queue from app.common.config.app_settings import app_settings +from app.common.log.module_logger import ModuleLogger def create_app() -> FastAPI: logging.info("App initializing") @@ -33,6 +34,16 @@ def create_app() -> FastAPI: # Register metrics APIs if enabled if app_settings.METRICS_ENABLED: register(app, metrics) + + # Add startup logging + @app.on_event("startup") + async def startup_logging(): + module_logger = ModuleLogger(sender_id="ApplicationBootstrap") + await module_logger.log_info( + text=f"DevOps service started successfully in {app_settings.APP_ENV} environment", + data={"app_name": app_settings.APP_NAME, "environment": app_settings.APP_ENV} + ) + return app diff --git a/apps/devops/app/common/config/app_settings.py b/apps/devops/app/common/config/app_settings.py index d7b3c7d..8717b20 100644 --- a/apps/devops/app/common/config/app_settings.py +++ b/apps/devops/app/common/config/app_settings.py @@ -2,7 +2,7 @@ from pydantic_settings import BaseSettings # NOTE: The values fall backs to your environment variables when not set here class AppSettings(BaseSettings): - NAME: str = "YOUR_APP_NAME" + NAME: str = "devops" APP_NAME: str = NAME APP_ENV: str = "alpha" @@ -17,8 +17,8 @@ class AppSettings(BaseSettings): APP_MONGODB_NAME: str = "testdb" LOG_BASE_PATH: str = "./log" - BACKEND_LOG_FILE_NAME: str = APP_NAME - APPLICATION_ACTIVITY_LOG: str = APP_NAME + "-application-activity"\ + BACKEND_LOG_FILE_NAME: str = "devops" + APPLICATION_ACTIVITY_LOG: str = "devops-application-activity"\ RABBITMQ_HOST: str = "localhost" RABBITMQ_PORT: int = 5672 diff --git a/apps/notification/Dockerfile b/apps/notification/Dockerfile index dce32fc..810fa6d 100644 --- a/apps/notification/Dockerfile +++ b/apps/notification/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim-buster +FROM python:3.12-slim # docker settings ARG CONTAINER_APP_ROOT=/app diff --git a/apps/notification/webapi/bootstrap/application.py b/apps/notification/webapi/bootstrap/application.py index 65adca9..130ff17 100644 --- a/apps/notification/webapi/bootstrap/application.py +++ b/apps/notification/webapi/bootstrap/application.py @@ -14,6 +14,7 @@ from webapi.providers import metrics from webapi.providers import middleware from .freeleaps_app import FreeleapsApp from common.config.app_settings import app_settings +from common.log.module_logger import ModuleLogger from prometheus_fastapi_instrumentator import Instrumentator diff --git a/apps/notification/webapi/bootstrap/freeleaps_app.py b/apps/notification/webapi/bootstrap/freeleaps_app.py index dca6d6e..02488fa 100644 --- a/apps/notification/webapi/bootstrap/freeleaps_app.py +++ b/apps/notification/webapi/bootstrap/freeleaps_app.py @@ -3,6 +3,8 @@ from backend.infra.rabbitmq.async_subscriber import AsyncMQSubscriber from backend.models.constants import NotificationChannel from webapi.utils.email_consumer import EmailMQConsumer from webapi.utils.sms_consumer import SmsMQConsumer +from common.log.module_logger import ModuleLogger +from common.config.app_settings import app_settings class FreeleapsApp(FastAPI): @@ -21,6 +23,14 @@ class FreeleapsApp(FastAPI): @self.on_event("startup") async def start_consumers(): print("starting up!") + + # Add startup logging + module_logger = ModuleLogger(sender_id="ApplicationBootstrap") + await module_logger.log_info( + text=f"Notification service started successfully in {app_settings.APP_ENV} environment", + data={"app_name": app_settings.APP_NAME, "environment": app_settings.APP_ENV} + ) + await self.sms_handler.register_consumer() await self.email_handler.register_consumer() diff --git a/apps/payment/Dockerfile b/apps/payment/Dockerfile index f5ac56d..d5e55d5 100644 --- a/apps/payment/Dockerfile +++ b/apps/payment/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim-buster +FROM python:3.12-slim # docker settings ARG CONTAINER_APP_ROOT=/app diff --git a/apps/payment/webapi/bootstrap/application.py b/apps/payment/webapi/bootstrap/application.py index 2c87d5c..b287a94 100644 --- a/apps/payment/webapi/bootstrap/application.py +++ b/apps/payment/webapi/bootstrap/application.py @@ -12,6 +12,7 @@ from webapi.providers import probes from webapi.providers import exception_handler from .freeleaps_app import FreeleapsApp from common.config.app_settings import app_settings +from common.log.module_logger import ModuleLogger def create_app() -> FastAPI: logging.info("App initializing") diff --git a/apps/payment/webapi/bootstrap/freeleaps_app.py b/apps/payment/webapi/bootstrap/freeleaps_app.py index 496633a..cbedece 100644 --- a/apps/payment/webapi/bootstrap/freeleaps_app.py +++ b/apps/payment/webapi/bootstrap/freeleaps_app.py @@ -1,6 +1,18 @@ from fastapi import FastAPI +from common.log.module_logger import ModuleLogger +from common.config.app_settings import app_settings class FreeleapsApp(FastAPI): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.register_startup_event() + + def register_startup_event(self): + @self.on_event("startup") + async def startup_logging(): + module_logger = ModuleLogger(sender_id="ApplicationBootstrap") + await module_logger.log_info( + text=f"Payment service started successfully in {app_settings.APP_ENV} environment", + data={"app_name": app_settings.APP_NAME, "environment": app_settings.APP_ENV} + )