Skip to content

Commit 5699556

Browse files
Bihan  RanaBihan  Rana
authored andcommitted
Resolved Minor Review Comments
1 parent b8794f1 commit 5699556

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
from enum import Enum
2-
from typing import Union
3-
4-
from pydantic import Field
5-
from typing_extensions import Annotated, Literal
2+
from typing import Literal
63

74
from dstack._internal.core.models.common import CoreModel
85

96

107
class RouterType(str, Enum):
118
SGLANG = "sglang"
12-
VLLM = "vllm"
139

1410

1511
class SGLangRouterConfig(CoreModel):
1612
type: Literal["sglang"] = "sglang"
17-
policy: str = "cache_aware"
18-
19-
20-
class VLLMRouterConfig(CoreModel):
21-
type: Literal["vllm"] = "vllm"
22-
policy: str = "cache_aware"
13+
policy: Literal["random", "round_robin", "cache_aware", "power_of_two"] = "cache_aware"
2314

2415

25-
AnyRouterConfig = Annotated[
26-
Union[SGLangRouterConfig, VLLMRouterConfig], Field(discriminator="type")
27-
]
16+
AnyRouterConfig = SGLangRouterConfig

src/dstack/_internal/proxy/gateway/model_routers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from dstack._internal.core.models.routers import AnyRouterConfig
44
from dstack._internal.proxy.gateway.model_routers.sglang import SglangRouter
5+
from dstack._internal.proxy.lib.errors import ProxyError
56

67
from .base import Router, RouterContext
78

89

910
def get_router(router: AnyRouterConfig, context: Optional[RouterContext] = None) -> Router:
10-
"""Factory function to create a router instance from router configuration."""
1111
if router.type == "sglang":
1212
return SglangRouter(router=router, context=context)
13-
raise ValueError(f"Router type '{router.type}' is not available")
13+
raise ProxyError(f"Router type '{router.type}' is not available")
1414

1515

1616
__all__ = [

src/dstack/_internal/proxy/gateway/model_routers/sglang.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import urllib.parse
66
from typing import List, Optional
77

8-
from dstack._internal.core.models.routers import SGLangRouterConfig
8+
from dstack._internal.core.models.routers import RouterType, SGLangRouterConfig
99
from dstack._internal.proxy.gateway.const import DSTACK_DIR_ON_GATEWAY
10+
from dstack._internal.proxy.lib.errors import UnexpectedProxyError
1011
from dstack._internal.utils.logging import get_logger
1112

1213
from .base import Router, RouterContext
@@ -17,7 +18,7 @@
1718
class SglangRouter(Router):
1819
"""SGLang router implementation with 1:1 service-to-router."""
1920

20-
TYPE = "sglang"
21+
TYPE = RouterType.SGLANG
2122

2223
def __init__(self, router: SGLangRouterConfig, context: Optional[RouterContext] = None):
2324
"""Initialize SGLang router.
@@ -68,7 +69,9 @@ def start(self) -> None:
6869
time.sleep(2)
6970

7071
if not self.is_running():
71-
raise Exception(f"Failed to start sglang router on port {self.context.port}")
72+
raise UnexpectedProxyError(
73+
f"Failed to start sglang router on port {self.context.port}"
74+
)
7275

7376
logger.info(
7477
"Sglang router started successfully on port %s (prometheus on %s)",

src/dstack/_internal/proxy/gateway/services/nginx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pydantic import BaseModel
1111
from typing_extensions import Literal
1212

13-
from dstack._internal.core.models.routers import AnyRouterConfig
13+
from dstack._internal.core.models.routers import AnyRouterConfig, RouterType
1414
from dstack._internal.proxy.gateway.const import PROXY_PORT_ON_GATEWAY
1515
from dstack._internal.proxy.gateway.model_routers import (
1616
Router,
@@ -107,7 +107,7 @@ async def register(self, conf: SiteConfig, acme: ACMESettings) -> None:
107107
await run_async(self.run_certbot, conf.domain, acme)
108108

109109
if isinstance(conf, ServiceConfig) and conf.router:
110-
if conf.router.type == "sglang":
110+
if conf.router.type == RouterType.SGLANG:
111111
# Check if router already exists for this domain
112112
if conf.domain in self._domain_to_router:
113113
# Router already exists, reuse it
@@ -314,7 +314,7 @@ def _is_port_available(port: int) -> bool:
314314
return False
315315

316316
def _allocate_router_port(self) -> int:
317-
"""Allocate next available router port in fixed range (20000-24999).
317+
"""Allocate next available router port in fixed range.
318318
319319
Checks both our internal allocation map and actual port availability
320320
to avoid conflicts with other services. Range chosen to avoid ephemeral ports.
@@ -354,7 +354,7 @@ def _allocate_router_port(self) -> int:
354354
)
355355

356356
def _allocate_worker_ports(self, num_ports: int) -> list[int]:
357-
"""Allocate worker ports globally in fixed range (10001-11999).
357+
"""Allocate worker ports globally in fixed range.
358358
359359
Worker ports are used by nginx to listen and proxy to worker sockets.
360360
They must be unique across all router instances. Range chosen to avoid ephemeral ports.

0 commit comments

Comments
 (0)