From d2f4708663762fc945b6834dca1fd49604816ef3 Mon Sep 17 00:00:00 2001 From: OG T Date: Tue, 31 Mar 2026 11:39:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(cicd):=20#46c=20OTEL=20Tracing=20=E9=81=B7?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20Gitea=20workflows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CD: awoooi-cd service (192.168.0.188:24318) - E2E: awoooi-e2e service - 環境變數: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES 原 GitHub workflows (cd7d63e) → Gitea workflows (ADR-039) Co-Authored-By: Claude Opus 4.5 --- .gitea/workflows/cd.yaml | 4 ++++ .gitea/workflows/e2e-health.yaml | 6 ++++++ apps/api/src/main.py | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/cd.yaml b/.gitea/workflows/cd.yaml index b2989bf6..adae33c9 100644 --- a/.gitea/workflows/cd.yaml +++ b/.gitea/workflows/cd.yaml @@ -23,6 +23,10 @@ env: HARBOR: 192.168.0.110:5000 # Harbor Proxy Cache (指向 DockerHub 的內部 Mirror,避免拉取限額) HARBOR_MIRROR: 192.168.0.110:5001 + # OTEL CI/CD 監控 (2026-03-31 #46c - 遷移到 Gitea) + OTEL_EXPORTER_OTLP_ENDPOINT: http://192.168.0.188:24318 + OTEL_SERVICE_NAME: awoooi-cd + OTEL_RESOURCE_ATTRIBUTES: service.version=${{ github.sha }},deployment.environment=production jobs: build-and-deploy: diff --git a/.gitea/workflows/e2e-health.yaml b/.gitea/workflows/e2e-health.yaml index ffad4731..6b8acdbd 100644 --- a/.gitea/workflows/e2e-health.yaml +++ b/.gitea/workflows/e2e-health.yaml @@ -14,6 +14,12 @@ on: schedule: - cron: '0 16 * * *' # 每日 00:00 台北 (UTC+8) +# OTEL CI/CD 監控 (2026-03-31 #46c) +env: + OTEL_EXPORTER_OTLP_ENDPOINT: http://192.168.0.188:24318 + OTEL_SERVICE_NAME: awoooi-e2e + OTEL_RESOURCE_ATTRIBUTES: deployment.environment=production + jobs: e2e-health: runs-on: ubuntu-latest diff --git a/apps/api/src/main.py b/apps/api/src/main.py index bce369cd..5b67acd3 100644 --- a/apps/api/src/main.py +++ b/apps/api/src/main.py @@ -26,7 +26,8 @@ import sentry_sdk import structlog from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import JSONResponse +from fastapi.responses import JSONResponse, Response +from prometheus_client import CONTENT_TYPE_LATEST, generate_latest from sentry_sdk.integrations.fastapi import FastApiIntegration from sentry_sdk.integrations.starlette import StarletteIntegration @@ -437,6 +438,21 @@ app.include_router( ) +# ============================================================================= +# Prometheus Metrics Endpoint +# ============================================================================= +# 2026-03-31 ogt: 暴露 Prometheus 指標供告警系統使用 + + +@app.get("/metrics", include_in_schema=False) +async def prometheus_metrics() -> Response: + """Prometheus metrics endpoint for alerting""" + return Response( + content=generate_latest(), + media_type=CONTENT_TYPE_LATEST, + ) + + # ============================================================================= # Root Endpoint # =============================================================================