mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-27 14:38:49 +00:00
feat: add optional metrics under API /providers
- add field "metrcis" under API "/providers" - each provider can config "metrics" in run.yaml in "config" - if no "metrics": /provider/<provider_id> shows "metrics: null" in response - if has "metrics": /provider/<provider_id> show result in response - if has "metrics" but is not string type and not httpurl, raise ValidationError - add unit tests for providers - update "docs" Signed-off-by: Wen Zhou <wenzhou@redhat.com>
This commit is contained in:
parent
5400a2e2b1
commit
8563c76f88
7 changed files with 248 additions and 2 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
from typing import Any, Protocol, runtime_checkable
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, HttpUrl, field_validator
|
||||
|
||||
from llama_stack.providers.datatypes import HealthResponse
|
||||
from llama_stack.schema_utils import json_schema_type, webmethod
|
||||
|
@ -19,6 +19,16 @@ class ProviderInfo(BaseModel):
|
|||
provider_type: str
|
||||
config: dict[str, Any]
|
||||
health: HealthResponse
|
||||
metrics: str | None = None # define as string type than httpurl for openapi compatibility
|
||||
|
||||
@field_validator("metrics")
|
||||
@classmethod
|
||||
def validate_metrics_url(cls, v):
|
||||
if v is None:
|
||||
return None
|
||||
if isinstance(v, str):
|
||||
HttpUrl(v)
|
||||
return v
|
||||
|
||||
|
||||
class ListProvidersResponse(BaseModel):
|
||||
|
|
|
@ -51,18 +51,22 @@ class ProviderImpl(Providers):
|
|||
# Skip providers that are not enabled
|
||||
if p.provider_id is None:
|
||||
continue
|
||||
# Filter out "metrics" to be shown in config duplicated
|
||||
metrics_url = p.config.get("metrics")
|
||||
config = {k: v for k, v in p.config.items() if k != "metrics"}
|
||||
ret.append(
|
||||
ProviderInfo(
|
||||
api=api,
|
||||
provider_id=p.provider_id,
|
||||
provider_type=p.provider_type,
|
||||
config=p.config,
|
||||
config=config,
|
||||
health=providers_health.get(api, {}).get(
|
||||
p.provider_id,
|
||||
HealthResponse(
|
||||
status=HealthStatus.NOT_IMPLEMENTED, message="Provider does not implement health check"
|
||||
),
|
||||
),
|
||||
metrics=metrics_url,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue