From 5f18212343f93eebdec57498a56f60a8065b2501 Mon Sep 17 00:00:00 2001 From: YuehuCao Date: Sat, 11 Oct 2025 09:42:40 +0800 Subject: [PATCH] feat(model): add usage_log_doc --- .../backend/models/user/__init__.py | 2 ++ .../backend/models/user/models.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/apps/authentication/backend/models/user/__init__.py b/apps/authentication/backend/models/user/__init__.py index 031589b..3ab3b72 100644 --- a/apps/authentication/backend/models/user/__init__.py +++ b/apps/authentication/backend/models/user/__init__.py @@ -4,6 +4,7 @@ from .models import ( UserEmailDoc, UserMobileDoc, AuthCodeDoc, + UsageLogDoc, ) user_models = [ @@ -12,4 +13,5 @@ user_models = [ UserEmailDoc, UserMobileDoc, AuthCodeDoc, + UsageLogDoc, ] diff --git a/apps/authentication/backend/models/user/models.py b/apps/authentication/backend/models/user/models.py index 2fe9c21..6fd8936 100644 --- a/apps/authentication/backend/models/user/models.py +++ b/apps/authentication/backend/models/user/models.py @@ -57,3 +57,24 @@ class AuthCodeDoc(Document): class Settings: name = "user_auth_code" + +class UsageLogDoc(Document): + timestamp: datetime = datetime.utcnow() # timestamp + tenant_id: str # tenant id + operation: str # operation type + request_id: str # request id # TODO: use true one + units: int # units + status: str # operation status + latency_ms: int # latency time(milliseconds) + bytes_in: int # input bytes + bytes_out: int # output bytes + key_id: Optional[str] = None # API Key ID + extra: dict = {} # extra information + + class Settings: + name = "usage_log_doc" + indexes = [ + "tenant_id", + "request_id", + "key_id" + ] \ No newline at end of file