mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-28 06:21:59 +00:00
feat: add metrics query API
This commit is contained in:
parent
d27a0f276c
commit
ba6334475f
2 changed files with 64 additions and 0 deletions
|
|
@ -203,6 +203,45 @@ class QuerySpanTreeResponse(BaseModel):
|
|||
data: dict[str, SpanWithStatus]
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class MetricQueryType(Enum):
|
||||
RANGE = "range"
|
||||
INSTANT = "instant"
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class MetricLabelOperator(Enum):
|
||||
EQUALS = "="
|
||||
NOT_EQUALS = "!="
|
||||
REGEX_MATCH = "=~"
|
||||
REGEX_NOT_MATCH = "!~"
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class MetricLabelMatcher(BaseModel):
|
||||
name: str
|
||||
value: str
|
||||
operator: MetricLabelOperator = MetricLabelOperator.EQUALS
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class MetricDataPoint(BaseModel):
|
||||
timestamp: datetime
|
||||
value: float
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class MetricSeries(BaseModel):
|
||||
metric: str
|
||||
labels: Dict[str, str]
|
||||
values: List[MetricDataPoint]
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class GetMetricsResponse(BaseModel):
|
||||
data: List[MetricSeries]
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class Telemetry(Protocol):
|
||||
@webmethod(route="/telemetry/events", method="POST")
|
||||
|
|
@ -247,3 +286,14 @@ class Telemetry(Protocol):
|
|||
dataset_id: str,
|
||||
max_depth: int | None = None,
|
||||
) -> None: ...
|
||||
|
||||
@webmethod(route="/telemetry/metrics/{metric_name}", method="POST")
|
||||
async def get_metrics(
|
||||
self,
|
||||
metric_name: str,
|
||||
start_time: int,
|
||||
end_time: Optional[int] = None,
|
||||
step: Optional[str] = "1d",
|
||||
query_type: MetricQueryType = MetricQueryType.RANGE,
|
||||
label_matchers: Optional[List[MetricLabelMatcher]] = None,
|
||||
) -> GetMetricsResponse: ...
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue