mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
use service logger for tracking pod lock status
This commit is contained in:
parent
8405fcb748
commit
e09ef4afc7
1 changed files with 67 additions and 1 deletions
|
@ -1,8 +1,15 @@
|
|||
import enum
|
||||
import uuid
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class ServiceMetrics(enum.Enum):
|
||||
COUNTER = "counter"
|
||||
HISTOGRAM = "histogram"
|
||||
GAUGE = "gauge"
|
||||
|
||||
|
||||
class ServiceTypes(str, enum.Enum):
|
||||
|
@ -18,6 +25,62 @@ class ServiceTypes(str, enum.Enum):
|
|||
ROUTER = "router"
|
||||
AUTH = "auth"
|
||||
PROXY_PRE_CALL = "proxy_pre_call"
|
||||
POD_LOCK_MANAGER = "pod_lock_manager"
|
||||
|
||||
|
||||
class ServiceConfig(TypedDict):
|
||||
"""
|
||||
Configuration for services and their metrics
|
||||
"""
|
||||
|
||||
metrics: List[ServiceMetrics] # What metrics this service should support
|
||||
|
||||
|
||||
"""
|
||||
Metric types to use for each service
|
||||
|
||||
- REDIS only needs Counter, Histogram
|
||||
- Pod Lock Manager only needs a gauge metric
|
||||
"""
|
||||
DEFAULT_SERVICE_CONFIGS = {
|
||||
ServiceTypes.REDIS.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.DB.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.BATCH_WRITE_TO_DB.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.RESET_BUDGET_JOB.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.LITELLM.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.ROUTER.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.AUTH.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.PROXY_PRE_CALL.value: {
|
||||
"metrics": [ServiceMetrics.COUNTER, ServiceMetrics.HISTOGRAM]
|
||||
},
|
||||
ServiceTypes.POD_LOCK_MANAGER.value: {"metrics": [ServiceMetrics.GAUGE]},
|
||||
}
|
||||
|
||||
|
||||
class ServiceEventMetadata(TypedDict, total=False):
|
||||
"""
|
||||
The metadata logged during service success/failure
|
||||
|
||||
Add any extra fields you expect to access in the service_success_hook/service_failure_hook
|
||||
"""
|
||||
|
||||
# Dynamically control gauge labels and values
|
||||
gauge_labels: Optional[str]
|
||||
gauge_value: Optional[float]
|
||||
|
||||
|
||||
class ServiceLoggerPayload(BaseModel):
|
||||
|
@ -30,6 +93,9 @@ class ServiceLoggerPayload(BaseModel):
|
|||
service: ServiceTypes = Field(description="who is this for? - postgres/redis")
|
||||
duration: float = Field(description="How long did the request take?")
|
||||
call_type: str = Field(description="The call of the service, being made")
|
||||
event_metadata: Optional[dict] = Field(
|
||||
description="The metadata logged during service success/failure"
|
||||
)
|
||||
|
||||
def to_json(self, **kwargs):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue