[Misc] add service discovery for sgl router

This commit is contained in:
Simo Lin
2025-04-29 10:21:19 -07:00
committed by GitHub
parent 91dda4cd06
commit 1468769bde
11 changed files with 1242 additions and 45 deletions

View File

@@ -38,6 +38,10 @@ class TestLaunchRouter(unittest.TestCase):
max_payload_size=4 * 1024 * 1024, # 4MB
verbose=False,
log_dir=None,
service_discovery=False,
selector=None,
service_discovery_port=80,
service_discovery_namespace=None,
)
def create_router_args(self, **kwargs):
@@ -79,6 +83,23 @@ class TestLaunchRouter(unittest.TestCase):
args = self.create_router_args(worker_urls=[])
self.run_router_process(args)
def test_launch_router_with_service_discovery(self):
# Test router startup with service discovery enabled but no selectors
args = self.create_router_args(
worker_urls=[], service_discovery=True, selector=["app=test-worker"]
)
self.run_router_process(args)
def test_launch_router_with_service_discovery_namespace(self):
# Test router startup with service discovery enabled and namespace specified
args = self.create_router_args(
worker_urls=[],
service_discovery=True,
selector=["app=test-worker"],
service_discovery_namespace="test-namespace",
)
self.run_router_process(args)
if __name__ == "__main__":
unittest.main()

View File

@@ -24,6 +24,10 @@ def popen_launch_router(
max_payload_size: int = None,
api_key: str = None,
log_dir: str = None,
service_discovery: bool = False,
selector: list = None,
service_discovery_port: int = 80,
service_discovery_namespace: str = None,
):
"""
Launch the router server process.
@@ -37,6 +41,10 @@ def popen_launch_router(
max_payload_size: Maximum payload size in bytes
api_key: API key for the router
log_dir: Directory to store log files. If None, logs are only output to console.
service_discovery: Enable Kubernetes service discovery
selector: List of label selectors in format ["key1=value1", "key2=value2"]
service_discovery_port: Port to use for service discovery
service_discovery_namespace: Kubernetes namespace to watch for pods. If None, watches all namespaces.
"""
_, host, port = base_url.split(":")
host = host[2:]
@@ -65,6 +73,20 @@ def popen_launch_router(
if max_payload_size is not None:
command.extend(["--router-max-payload-size", str(max_payload_size)])
if service_discovery:
command.append("--router-service-discovery")
if selector:
command.extend(["--router-selector"] + selector)
if service_discovery_port != 80:
command.extend(["--router-service-discovery-port", str(service_discovery_port)])
if service_discovery_namespace:
command.extend(
["--router-service-discovery-namespace", service_discovery_namespace]
)
if log_dir is not None:
command.extend(["--log-dir", log_dir])