Compare commits

..

14 Commits

Author SHA1 Message Date
5c0d2064a4 feat: update prometheus metrics capture 2025-11-11 16:28:29 +08:00
icecheng
c5507dd5a3 Merge pull request 'feat: update prometheus metrics capture' (#10) from feature/icecheng/prometheus into main
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/10
2025-11-10 08:41:26 +00:00
098b6a8e5b feat: update prometheus metrics capture 2025-11-10 16:40:27 +08:00
freeleaps-gitops-bot
6ad4d1694b ci(bump): bump authentication image version for alpha to snapshot-a2b3e4e 2025-11-10 07:59:47 +00:00
freeleaps-gitops-bot
849ac3bb1d ci(bump): bump authentication image version for prod to snapshot-5abb2a1 2025-11-10 07:59:35 +00:00
icecheng
5abb2a16ec Merge pull request 'dev' (#9) from dev into main
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/9
2025-11-10 07:56:17 +00:00
icecheng
a2b3e4e1aa Merge pull request 'feature/icecheng/prometheus' (#8) from feature/icecheng/prometheus into dev
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/8
2025-11-10 07:55:52 +00:00
34c1ad1da9 feat: update prometheus metrics capture 2025-11-10 15:55:12 +08:00
freeleaps-gitops-bot
8e789644b4 ci(bump): bump authentication image version for prod to snapshot-9a7fa21 2025-11-07 09:57:52 +00:00
9a7fa21df4 Merge pull request 'dev' (#7) from dev into main
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/7
2025-11-07 09:55:42 +00:00
e6b358e5d8 Merge pull request 'fix: fix a mongodb _id issue' (#6) from haolou_local into dev
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/6
2025-11-07 09:46:40 +00:00
haolou
77a37da90f fix: fix a mongodb _id issue 2025-11-07 17:45:43 +08:00
7b923c1702 Merge pull request 'fix: change some un-exist insert methods to create' (#5) from haolou_local into dev
Reviewed-on: https://gitea.freeleaps.mathmast.com/products/freeleaps-authentication/pulls/5
2025-11-07 09:35:38 +00:00
haolou
9f8892a8a9 fix: change some un-exist insert methods to create 2025-11-07 17:29:44 +08:00
11 changed files with 50 additions and 14 deletions

View File

@ -18,4 +18,6 @@ data:
MONGODB_PORT: {{ .Values.authentication.configs.mongodbPort | toString | b64enc }} MONGODB_PORT: {{ .Values.authentication.configs.mongodbPort | toString | b64enc }}
METRICS_ENABLED: {{ .Values.authentication.configs.metricsEnabled | default false | toString | b64enc }} METRICS_ENABLED: {{ .Values.authentication.configs.metricsEnabled | default false | toString | b64enc }}
PROBES_ENABLED: {{ .Values.authentication.configs.probesEnabled | default false | toString | b64enc }} PROBES_ENABLED: {{ .Values.authentication.configs.probesEnabled | default false | toString | b64enc }}
FREELEAPS_PRODUCT_ID: {{ .Values.authentication.configs.freeleapsProductId | b64enc | quote }}
ENVIRONMENT: {{ .Values.authentication.configs.environment | b64enc | quote }}

View File

@ -15,7 +15,7 @@ authentication:
registry: docker.io registry: docker.io
repository: null repository: null
name: 6901bcf4ed3725f39f11343d-authentication name: 6901bcf4ed3725f39f11343d-authentication
tag: snapshot-e6b358e tag: snapshot-a2b3e4e
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
ports: ports:
- name: http - name: http
@ -89,6 +89,8 @@ authentication:
mongodbPort: 27017 mongodbPort: 27017
metricsEnabled: 'false' metricsEnabled: 'false'
probesEnabled: 'true' probesEnabled: 'true'
freeleapsProductId: 6901bcf4ed3725f39f11343d
environment: alpha
secrets: secrets:
secretStoreRef: secretStoreRef:
kind: FreeleapsSecretStore kind: FreeleapsSecretStore

View File

@ -18,7 +18,7 @@ authentication:
registry: docker.io registry: docker.io
repository: null repository: null
name: 6901bcf4ed3725f39f11343d-authentication name: 6901bcf4ed3725f39f11343d-authentication
tag: snapshot-8584f90 tag: snapshot-5abb2a1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
ports: ports:
- name: http - name: http
@ -97,6 +97,8 @@ authentication:
mongodbPort: 27017 mongodbPort: 27017
metricsEnabled: 'true' metricsEnabled: 'true'
probesEnabled: 'true' probesEnabled: 'true'
freeleapsProductId: 6901bcf4ed3725f39f11343d
environment: prod
secrets: secrets:
secretStoreRef: secretStoreRef:
kind: FreeleapsSecretStore kind: FreeleapsSecretStore

View File

@ -82,6 +82,8 @@ authentication:
metricsEnabled: "false" metricsEnabled: "false"
# PROBES_ENABLED # PROBES_ENABLED
probesEnabled: "false" probesEnabled: "false"
freeleapsProductId: ""
environment: alpha
# AKV secrets configuration # AKV secrets configuration
secrets: secrets:
secretStoreRef: secretStoreRef:

View File

@ -7,7 +7,7 @@ metadata:
spec: spec:
layout: FAST_API_VUE_3 layout: FAST_API_VUE_3
serviceName: freeleaps-authentication serviceName: freeleaps-authentication
executeMode: fully executeMode: on-demand
branch: main branch: main
components: components:
- name: authentication - name: authentication

View File

@ -25,6 +25,9 @@ ENV LOG_BASE_PATH=$CONTAINER_APP_ROOT/log/$APP_NAME
ENV BACKEND_LOG_FILE_NAME=$APP_NAME ENV BACKEND_LOG_FILE_NAME=$APP_NAME
ENV APPLICATION_ACTIVITY_LOG=$APP_NAME-activity ENV APPLICATION_ACTIVITY_LOG=$APP_NAME-activity
ENV FREELEAPS_PRODUCT_ID="6901bcf4ed3725f39f11343d"
ENV ENVIRONMENT="alpha"
WORKDIR ${CONTAINER_APP_ROOT} WORKDIR ${CONTAINER_APP_ROOT}
COPY requirements.txt . COPY requirements.txt .

View File

@ -118,7 +118,7 @@ class RoleHandler:
raise RequestValidationError("Role with the provided ID already exists.") raise RequestValidationError("Role with the provided ID already exists.")
new_doc.id = custom_role_id new_doc.id = custom_role_id
await new_doc.insert() await new_doc.create()
return new_doc return new_doc
async def query_roles(self, role_key: Optional[str], role_name: Optional[str], skip: int = 0, limit: int = 10) -> \ async def query_roles(self, role_key: Optional[str], role_name: Optional[str], skip: int = 0, limit: int = 10) -> \

View File

@ -36,7 +36,7 @@ class UserRoleHandler:
user_id=user_id, user_id=user_id,
role_ids=unique_role_ids role_ids=unique_role_ids
) )
await user_role_doc.insert() await user_role_doc.create()
return user_role_doc return user_role_doc
async def get_role_and_permission_by_user_id(self, user_id: str) -> tuple[list[str], list[str]]: async def get_role_and_permission_by_user_id(self, user_id: str) -> tuple[list[str], list[str]]:

View File

@ -3,6 +3,7 @@ BaseDoc - A custom document class that provides Beanie-like interface using dire
""" """
import asyncio import asyncio
from datetime import datetime, timezone from datetime import datetime, timezone
from bson import ObjectId
from typing import Optional, List, Dict, Any, Type, Union from typing import Optional, List, Dict, Any, Type, Union
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
from pydantic import BaseModel from pydantic import BaseModel
@ -282,6 +283,14 @@ class BaseDoc(BaseModel, metaclass=QueryModelMeta):
# Convert Decimal objects to float for MongoDB compatibility # Convert Decimal objects to float for MongoDB compatibility
doc_dict = self._convert_decimals_to_float(doc_dict) doc_dict = self._convert_decimals_to_float(doc_dict)
# Respect pre-populated id by mapping to MongoDB _id
id_value = getattr(self, 'id', None)
if id_value and not isinstance(id_value, QueryExpression):
try:
doc_dict['_id'] = ObjectId(id_value)
except Exception:
doc_dict['_id'] = id_value
result = await collection.insert_one(doc_dict) result = await collection.insert_one(doc_dict)
# Set the id field from the inserted document # Set the id field from the inserted document
@ -314,7 +323,18 @@ class BaseDoc(BaseModel, metaclass=QueryModelMeta):
elif hasattr(self, 'auth_code'): elif hasattr(self, 'auth_code'):
query['auth_code'] = self.auth_code query['auth_code'] = self.auth_code
if query: id_value = getattr(self, 'id', None)
if id_value and not isinstance(id_value, QueryExpression):
# Update by primary key when available
try:
object_id = ObjectId(id_value)
except Exception:
object_id = id_value
result = await collection.update_one({"_id": object_id}, {"$set": doc_dict}, upsert=True)
if result.upserted_id:
self.id = str(result.upserted_id)
elif query:
# Update existing document # Update existing document
result = await collection.update_one(query, {"$set": doc_dict}, upsert=True) result = await collection.update_one(query, {"$set": doc_dict}, upsert=True)
# If it was an insert, set the id field # If it was an insert, set the id field

View File

@ -30,6 +30,9 @@ class AppSettings(BaseSettings):
BACKEND_LOG_FILE_NAME: str = APP_NAME BACKEND_LOG_FILE_NAME: str = APP_NAME
APPLICATION_ACTIVITY_LOG: str = APP_NAME + "-application-activity" APPLICATION_ACTIVITY_LOG: str = APP_NAME + "-application-activity"
FREELEAPS_PRODUCT_ID: str = ""
ENVIRONMENT: str = ""
class Config: class Config:
env_file = ".myapp.env" env_file = ".myapp.env"
env_file_encoding = "utf-8" env_file_encoding = "utf-8"

View File

@ -2,12 +2,14 @@ import logging
from prometheus_fastapi_instrumentator import Instrumentator from prometheus_fastapi_instrumentator import Instrumentator
from common.config.app_settings import app_settings from common.config.app_settings import app_settings
def register(app):
instrumentator = Instrumentator().instrument(app,
metric_namespace="freeleaps",
metric_subsystem=app_settings.APP_NAME)
@app.on_event("startup") def register(app):
async def startup(): instrumentator = Instrumentator().instrument(
instrumentator.expose(app, endpoint="/api/_/metrics", should_gzip=True) app,
logging.info("Metrics endpoint exposed at /api/_/metrics") metric_namespace="freeleaps_{}".format(app_settings.FREELEAPS_PRODUCT_ID),
metric_subsystem=app_settings.ENVIRONMENT)
@app.on_event("startup")
async def startup():
instrumentator.expose(app, endpoint="/api/_/metrics", should_gzip=True)
logging.info("Metrics endpoint exposed at /api/_/metrics")