[Bug fix] trace: fix import error in mini_lb if sgl-router image does not install sglang (#12338)
This commit is contained in:
@@ -38,15 +38,6 @@ def launch_router(args: argparse.Namespace) -> Optional[Router]:
|
|||||||
router_args = args
|
router_args = args
|
||||||
|
|
||||||
if router_args.mini_lb:
|
if router_args.mini_lb:
|
||||||
if router_args.enable_trace:
|
|
||||||
from sglang.srt.tracing.trace import (
|
|
||||||
process_tracing_init,
|
|
||||||
trace_set_thread_info,
|
|
||||||
)
|
|
||||||
|
|
||||||
process_tracing_init(router_args.otlp_traces_endpoint, "sglang")
|
|
||||||
trace_set_thread_info("Mini lb")
|
|
||||||
|
|
||||||
mini_lb = MiniLoadBalancer(router_args)
|
mini_lb = MiniLoadBalancer(router_args)
|
||||||
mini_lb.start()
|
mini_lb.start()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -18,14 +18,21 @@ from fastapi import FastAPI, HTTPException
|
|||||||
from fastapi.responses import ORJSONResponse, Response, StreamingResponse
|
from fastapi.responses import ORJSONResponse, Response, StreamingResponse
|
||||||
from sglang_router.router_args import RouterArgs
|
from sglang_router.router_args import RouterArgs
|
||||||
|
|
||||||
|
try:
|
||||||
from sglang.srt.tracing.trace import (
|
from sglang.srt.tracing.trace import (
|
||||||
|
process_tracing_init,
|
||||||
trace_get_remote_propagate_context,
|
trace_get_remote_propagate_context,
|
||||||
trace_req_finish,
|
trace_req_finish,
|
||||||
trace_req_start,
|
trace_req_start,
|
||||||
|
trace_set_thread_info,
|
||||||
trace_slice_end,
|
trace_slice_end,
|
||||||
trace_slice_start,
|
trace_slice_start,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
trace_package_imported = True
|
||||||
|
except ImportError:
|
||||||
|
trace_package_imported = False
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
AIOHTTP_STREAM_READ_CHUNK_SIZE = (
|
AIOHTTP_STREAM_READ_CHUNK_SIZE = (
|
||||||
@@ -54,7 +61,13 @@ class MiniLoadBalancer:
|
|||||||
self.prefill_urls = [url[0] for url in router_args.prefill_urls]
|
self.prefill_urls = [url[0] for url in router_args.prefill_urls]
|
||||||
self.prefill_bootstrap_ports = [url[1] for url in router_args.prefill_urls]
|
self.prefill_bootstrap_ports = [url[1] for url in router_args.prefill_urls]
|
||||||
self.decode_urls = router_args.decode_urls
|
self.decode_urls = router_args.decode_urls
|
||||||
|
self.otlp_traces_endpoint = router_args.otlp_traces_endpoint
|
||||||
self.enable_trace = router_args.enable_trace
|
self.enable_trace = router_args.enable_trace
|
||||||
|
if self.enable_trace and not trace_package_imported:
|
||||||
|
logger.warning(
|
||||||
|
"Tracing is not supported in this environment. Please install sglang."
|
||||||
|
)
|
||||||
|
self.enable_trace = False
|
||||||
|
|
||||||
def _validate_router_args(self, router_args: RouterArgs):
|
def _validate_router_args(self, router_args: RouterArgs):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@@ -77,6 +90,9 @@ class MiniLoadBalancer:
|
|||||||
def start(self):
|
def start(self):
|
||||||
global lb
|
global lb
|
||||||
lb = self
|
lb = self
|
||||||
|
if self.enable_trace:
|
||||||
|
process_tracing_init(self.otlp_traces_endpoint, "sglang")
|
||||||
|
trace_set_thread_info("Mini lb")
|
||||||
uvicorn.run(app, host=self.host, port=self.port)
|
uvicorn.run(app, host=self.host, port=self.port)
|
||||||
|
|
||||||
def select_pair(self):
|
def select_pair(self):
|
||||||
@@ -441,6 +457,7 @@ async def handle_completion_request(request_data: dict):
|
|||||||
|
|
||||||
def _generate_bootstrap_room():
|
def _generate_bootstrap_room():
|
||||||
bootstrap_room = random.randint(0, 2**63 - 1)
|
bootstrap_room = random.randint(0, 2**63 - 1)
|
||||||
|
if lb.enable_trace:
|
||||||
trace_req_start(bootstrap_room, bootstrap_room, role="router")
|
trace_req_start(bootstrap_room, bootstrap_room, role="router")
|
||||||
trace_slice_start("mini_lb_launch", bootstrap_room)
|
trace_slice_start("mini_lb_launch", bootstrap_room)
|
||||||
return bootstrap_room
|
return bootstrap_room
|
||||||
|
|||||||
Reference in New Issue
Block a user