feat: add metrics query API (#1394)

# What does this PR do?
Adds the API to query metrics from telemetry.

## Test Plan
llama stack run ~/.llama/distributions/fireworks/fireworks-run.yaml

---------

Co-authored-by: Ashwin Bharambe <ashwin.bharambe@gmail.com>
This commit is contained in:
Dinesh Yeduguru 2025-05-07 10:11:26 -07:00 committed by GitHub
parent 6371bb1b33
commit fe5f5e530c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 387 additions and 0 deletions

View file

@ -3475,6 +3475,58 @@
}
}
},
"/v1/telemetry/metrics/{metric_name}": {
"post": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/QueryMetricsResponse"
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest400"
},
"429": {
"$ref": "#/components/responses/TooManyRequests429"
},
"500": {
"$ref": "#/components/responses/InternalServerError500"
},
"default": {
"$ref": "#/components/responses/DefaultError"
}
},
"tags": [
"Telemetry"
],
"description": "",
"parameters": [
{
"name": "metric_name",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/QueryMetricsRequest"
}
}
},
"required": true
}
}
},
"/v1/telemetry/spans": {
"post": {
"responses": {
@ -11270,6 +11322,143 @@
],
"title": "QueryChunksResponse"
},
"QueryMetricsRequest": {
"type": "object",
"properties": {
"start_time": {
"type": "integer"
},
"end_time": {
"type": "integer"
},
"granularity": {
"type": "string"
},
"query_type": {
"type": "string",
"enum": [
"range",
"instant"
],
"title": "MetricQueryType"
},
"label_matchers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
},
"operator": {
"type": "string",
"enum": [
"=",
"!=",
"=~",
"!~"
],
"title": "MetricLabelOperator",
"default": "="
}
},
"additionalProperties": false,
"required": [
"name",
"value",
"operator"
],
"title": "MetricLabelMatcher"
}
}
},
"additionalProperties": false,
"required": [
"start_time",
"query_type"
],
"title": "QueryMetricsRequest"
},
"MetricDataPoint": {
"type": "object",
"properties": {
"timestamp": {
"type": "integer"
},
"value": {
"type": "number"
}
},
"additionalProperties": false,
"required": [
"timestamp",
"value"
],
"title": "MetricDataPoint"
},
"MetricLabel": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name",
"value"
],
"title": "MetricLabel"
},
"MetricSeries": {
"type": "object",
"properties": {
"metric": {
"type": "string"
},
"labels": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MetricLabel"
}
},
"values": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MetricDataPoint"
}
}
},
"additionalProperties": false,
"required": [
"metric",
"labels",
"values"
],
"title": "MetricSeries"
},
"QueryMetricsResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MetricSeries"
}
}
},
"additionalProperties": false,
"required": [
"data"
],
"title": "QueryMetricsResponse"
},
"QueryCondition": {
"type": "object",
"properties": {

View file

@ -2397,6 +2397,40 @@ paths:
schema:
$ref: '#/components/schemas/QueryChunksRequest'
required: true
/v1/telemetry/metrics/{metric_name}:
post:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/QueryMetricsResponse'
'400':
$ref: '#/components/responses/BadRequest400'
'429':
$ref: >-
#/components/responses/TooManyRequests429
'500':
$ref: >-
#/components/responses/InternalServerError500
default:
$ref: '#/components/responses/DefaultError'
tags:
- Telemetry
description: ''
parameters:
- name: metric_name
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/QueryMetricsRequest'
required: true
/v1/telemetry/spans:
post:
responses:
@ -7762,6 +7796,104 @@ components:
- chunks
- scores
title: QueryChunksResponse
QueryMetricsRequest:
type: object
properties:
start_time:
type: integer
end_time:
type: integer
granularity:
type: string
query_type:
type: string
enum:
- range
- instant
title: MetricQueryType
label_matchers:
type: array
items:
type: object
properties:
name:
type: string
value:
type: string
operator:
type: string
enum:
- '='
- '!='
- =~
- '!~'
title: MetricLabelOperator
default: '='
additionalProperties: false
required:
- name
- value
- operator
title: MetricLabelMatcher
additionalProperties: false
required:
- start_time
- query_type
title: QueryMetricsRequest
MetricDataPoint:
type: object
properties:
timestamp:
type: integer
value:
type: number
additionalProperties: false
required:
- timestamp
- value
title: MetricDataPoint
MetricLabel:
type: object
properties:
name:
type: string
value:
type: string
additionalProperties: false
required:
- name
- value
title: MetricLabel
MetricSeries:
type: object
properties:
metric:
type: string
labels:
type: array
items:
$ref: '#/components/schemas/MetricLabel'
values:
type: array
items:
$ref: '#/components/schemas/MetricDataPoint'
additionalProperties: false
required:
- metric
- labels
- values
title: MetricSeries
QueryMetricsResponse:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/MetricSeries'
additionalProperties: false
required:
- data
title: QueryMetricsResponse
QueryCondition:
type: object
properties: