Spaces:
Build error
Build error
File size: 1,274 Bytes
1c75c98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# tracklight_server/api/ingest.py
from fastapi import APIRouter, Depends, HTTPException
from typing import List
from pydantic import BaseModel
from ..db import duckdb
from .auth import verify_token
router = APIRouter()
class Metric(BaseModel):
run_id: str
project: str
user: str
metric_name: str
value: float
timestamp: str
class Config(BaseModel):
run_id: str
config_name: str
value: str
@router.post("/log", status_code=200)
def log_metrics(metrics: List[Metric], token: str = Depends(verify_token)):
"""
Receives a list of metrics and logs them to the database.
"""
try:
duckdb.insert_metrics([metric.dict() for metric in metrics])
return {"message": "Metrics logged successfully."}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.post("/log_config", status_code=200)
def log_config(configs: List[Config], token: str = Depends(verify_token)):
"""
Receives a list of config values and logs them to the database.
"""
try:
duckdb.insert_config([config.dict() for config in configs])
return {"message": "Configs logged successfully."}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
|