feat(CG5): add /billing/by-service endpoint
This commit is contained in:
parent
963d0aadf1
commit
97f0ead1fb
|
|
@ -2,6 +2,7 @@
|
|||
# OSVauco-NMTMD-GCOS — FastAPI HTTP entrypoint for Cloud Run
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
|
|
@ -12,6 +13,9 @@ from pydantic import BaseModel
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Allow imports from repo root (e.g. ml.billing_agent)
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
try:
|
||||
from google.adk.runners import Runner
|
||||
from google.adk.sessions import InMemorySessionService
|
||||
|
|
@ -167,10 +171,11 @@ async def billing_tokens_summary():
|
|||
logger.error(f"[/billing/tokens/summary] Failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@app.get("/billing/recommendations")
|
||||
async def billing_recommendations(budget: float = 500.0):
|
||||
"""
|
||||
CG4 — Kjører anbefalings- og anomali-motoren.
|
||||
CG4 — Kjorer anbefalings- og anomali-motoren.
|
||||
Returnerer en liste med anbefalinger og estimert besparelse.
|
||||
"""
|
||||
try:
|
||||
|
|
@ -179,3 +184,18 @@ async def billing_recommendations(budget: float = 500.0):
|
|||
except Exception as e:
|
||||
logger.error(f"[/billing/recommendations] Failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@app.get("/billing/by-service")
|
||||
async def billing_by_service(days: int = 30):
|
||||
"""
|
||||
CG5 — Returnerer kostnad per tjeneste gruppert med SKU-detaljer.
|
||||
Brukes av dashboard for grouped drill-down visning.
|
||||
"""
|
||||
try:
|
||||
from ml.billing_agent import BillingAgent
|
||||
agent = BillingAgent()
|
||||
return JSONResponse(agent.get_service_totals(days))
|
||||
except Exception as e:
|
||||
logger.error(f"[/billing/by-service] Failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user