24 lines
797 B
Python
24 lines
797 B
Python
# contains the router for the aggregates endpoint
|
|
from fastapi import APIRouter, Query, Request
|
|
from typing import List, Dict
|
|
from .aggregate_schema import AggregateSchema, MetricEnum
|
|
from .aggregate_service import get_aggregates
|
|
|
|
|
|
router = APIRouter(tags=["aggregates"])
|
|
|
|
|
|
@router.get("/aggregates", response_model=List[AggregateSchema])
|
|
async def aggregates_endpoint(
|
|
request: Request,
|
|
metric: MetricEnum = Query(MetricEnum.relative, description="Metric type"),
|
|
):
|
|
# Extract tag parameters from query string
|
|
tags: Dict[str, str] = {}
|
|
for param_name, param_value in request.query_params.items():
|
|
if param_name.startswith("tag."):
|
|
tag_key = param_name[4:]
|
|
tags[tag_key] = param_value
|
|
|
|
return await get_aggregates(request, metric, tags)
|