Unverified Commit 3dbab3f1 authored by dmitrygx's avatar dmitrygx Committed by GitHub
Browse files

fix(sglang): fix IPv6 support for ZMQ endpoint (#4403)


Signed-off-by: default avatarDmitrii Gabor <dmitryg1709@gmail.com>
parent 21f6d1e6
...@@ -10,7 +10,7 @@ import sglang as sgl ...@@ -10,7 +10,7 @@ import sglang as sgl
import zmq import zmq
import zmq.asyncio import zmq.asyncio
from prometheus_client import CollectorRegistry, multiprocess from prometheus_client import CollectorRegistry, multiprocess
from sglang.srt.utils import get_local_ip_auto, get_zmq_socket from sglang.srt.utils import get_local_ip_auto, get_zmq_socket, maybe_wrap_ipv6_address
from dynamo.common.utils.prometheus import register_engine_metrics_callback from dynamo.common.utils.prometheus import register_engine_metrics_callback
from dynamo.llm import ( from dynamo.llm import (
...@@ -26,6 +26,30 @@ from dynamo.runtime import Component, Endpoint ...@@ -26,6 +26,30 @@ from dynamo.runtime import Component, Endpoint
from dynamo.sglang.args import Config from dynamo.sglang.args import Config
def format_zmq_endpoint(endpoint_template: str, ip_address: str) -> str:
"""Format ZMQ endpoint by replacing wildcard with IP address.
Properly handles IPv6 addresses by wrapping them in square brackets.
Uses SGLang's maybe_wrap_ipv6_address for consistent formatting.
Args:
endpoint_template: ZMQ endpoint template with wildcard (e.g., "tcp://*:5557")
ip_address: IP address to use (can be IPv4 or IPv6)
Returns:
Formatted ZMQ endpoint string
Example:
>>> format_zmq_endpoint("tcp://*:5557", "192.168.1.1")
'tcp://192.168.1.1:5557'
>>> format_zmq_endpoint("tcp://*:5557", "2a02:6b8:c46:2b4:0:74c1:75b0:0")
'tcp://[2a02:6b8:c46:2b4:0:74c1:75b0:0]:5557'
"""
# Use SGLang's utility to wrap IPv6 addresses in brackets
formatted_ip = maybe_wrap_ipv6_address(ip_address)
return endpoint_template.replace("*", formatted_ip)
class DynamoSglangPublisher: class DynamoSglangPublisher:
""" """
Handles SGLang kv events and metrics reception and publishing. Handles SGLang kv events and metrics reception and publishing.
...@@ -121,7 +145,7 @@ class DynamoSglangPublisher: ...@@ -121,7 +145,7 @@ class DynamoSglangPublisher:
if self.server_args.kv_events_config: if self.server_args.kv_events_config:
kv_events = json.loads(self.server_args.kv_events_config) kv_events = json.loads(self.server_args.kv_events_config)
ep = kv_events.get("endpoint") ep = kv_events.get("endpoint")
zmq_ep = ep.replace("*", get_local_ip_auto()) if ep else None zmq_ep = format_zmq_endpoint(ep, get_local_ip_auto()) if ep else None
zmq_config = ZmqKvEventPublisherConfig( zmq_config = ZmqKvEventPublisherConfig(
worker_id=self.generate_endpoint.connection_id(), worker_id=self.generate_endpoint.connection_id(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment