[gRPC] Expose native pause status (#37488)
Co-authored-by: ishandhanani <82981111+ishandhanani@users.noreply.github.com>
This commit is contained in:
co-authored by
ishandhanani
parent
35b7589e1a
commit
f45aad44bd
@@ -446,6 +446,9 @@ class RuntimeHandle:
|
||||
ServerStatus.UnHealthy,
|
||||
)
|
||||
|
||||
def get_is_ready(self) -> bool:
|
||||
return self.tokenizer_manager.is_ready()
|
||||
|
||||
def tokenize(self, text: str, add_special_tokens: bool = True) -> str:
|
||||
tokenizer = self.tokenizer_manager.tokenizer
|
||||
tokens = tokenizer.encode(text, add_special_tokens=add_special_tokens)
|
||||
|
||||
@@ -659,6 +659,13 @@ async def validate_json_request(raw_request: Request):
|
||||
##### Native API endpoints #####
|
||||
|
||||
|
||||
@app.get("/ready")
|
||||
async def ready() -> Response:
|
||||
"""Report whether the server is ready to receive new requests."""
|
||||
status_code = 200 if _global_state.tokenizer_manager.is_ready() else 503
|
||||
return Response(status_code=status_code)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@app.get("/health_generate")
|
||||
async def health_generate(request: Request) -> Response:
|
||||
|
||||
@@ -626,6 +626,14 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
|
||||
# Subprocess liveness watchdog — set by Engine or http_server after construction
|
||||
self._subprocess_watchdog = None
|
||||
|
||||
def is_ready(self) -> bool:
|
||||
"""Return whether this server should receive new requests."""
|
||||
return (
|
||||
not self.is_pause
|
||||
and not self.gracefully_exit
|
||||
and self.server_status == ServerStatus.Up
|
||||
)
|
||||
|
||||
def init_request_logging_and_dumping(self):
|
||||
# TODO: Refactor and organize the log export code.
|
||||
# Request logging
|
||||
|
||||
@@ -90,14 +90,19 @@ def decide_request_auth(
|
||||
it must be rejected (403) even if api_key is provided.
|
||||
|
||||
NOTE :
|
||||
- Health/metrics endpoints are always allowed (even when api_key/admin_api_key is set),
|
||||
to support k8s/liveness/readiness and Prometheus scraping without embedding secrets.
|
||||
- Health/readiness/metrics endpoints are always allowed (even when
|
||||
api_key/admin_api_key is set), to support k8s probes and Prometheus
|
||||
scraping without embedding secrets.
|
||||
- We match them by prefix to cover common variants like /health_generate.
|
||||
"""
|
||||
if method == "OPTIONS":
|
||||
return AuthDecision(allowed=True)
|
||||
|
||||
if path.startswith("/health") or path.startswith("/metrics"):
|
||||
if (
|
||||
path.startswith("/health")
|
||||
or path.startswith("/ready")
|
||||
or path.startswith("/metrics")
|
||||
):
|
||||
return AuthDecision(allowed=True)
|
||||
|
||||
def _check_bearer_token(
|
||||
|
||||
Reference in New Issue
Block a user