[Anthropic] Fix clock mismatch in received_time causing negative Prometheus metrics (#22247)

Signed-off-by: Xuwei Li <lixuwei.xy@gmail.com>
This commit is contained in:
Xuwei
2026-04-13 21:22:00 -07:00
committed by GitHub
parent bc16130a17
commit a9a2ae4a68
@@ -36,6 +36,7 @@ from sglang.srt.entrypoints.openai.protocol import (
ToolChoice, ToolChoice,
ToolChoiceFuncName, ToolChoiceFuncName,
) )
from sglang.srt.observability.req_time_stats import monotonic_time
if TYPE_CHECKING: if TYPE_CHECKING:
from sglang.srt.entrypoints.openai.serving_chat import OpenAIServingChat from sglang.srt.entrypoints.openai.serving_chat import OpenAIServingChat
@@ -313,7 +314,7 @@ class AnthropicServing:
raw_request: Request, raw_request: Request,
) -> JSONResponse: ) -> JSONResponse:
"""Handle non-streaming Anthropic request by delegating to OpenAI handler.""" """Handle non-streaming Anthropic request by delegating to OpenAI handler."""
received_time = time.time() received_time = monotonic_time()
received_time_perf = time.perf_counter() received_time_perf = time.perf_counter()
# Validate # Validate
@@ -369,7 +370,7 @@ class AnthropicServing:
raw_request: Request, raw_request: Request,
) -> Union[StreamingResponse, JSONResponse]: ) -> Union[StreamingResponse, JSONResponse]:
"""Handle streaming Anthropic request.""" """Handle streaming Anthropic request."""
received_time = time.time() received_time = monotonic_time()
received_time_perf = time.perf_counter() received_time_perf = time.perf_counter()
# Validate # Validate