Prhub

#26034 Fix SMG service discovery Clippy lint

原始 PR 作者 mmangkad 合并时间 2026-05-22 10:51 文件变更 1 提交数 1 评论 1 代码增减 +6 / -7

执行摘要

修复 SMG 服务发现 Clippy 警告

PR #25294 新增的 IGW 模式选择器条件引发了 Clippy lint 失败,如 CI 运行结果所示。此 PR 旨在修复该问题,确保 cargo clippy 检查通过。

可直接合并。代码量小、改动清晰,且已通过 CI 验证。

讨论亮点

无 review 评论。

实现拆解

  1. 修改 sgl-model-gateway/src/service_discovery.rsPodInfo::should_include 函数的条件判断逻辑。
  2. 将原来嵌套的 if 语句(先检查 prefill_selectordecode_selector 都为空,再检查是否非 IGW 模式)合并为一个单一复合条件:config.prefill_selector.is_empty() && config.decode_selector.is_empty() && (!config.igw_mode || config.selector.is_empty())
  3. 删除多余的嵌套和 if 内的 if,消除了 Clippy 关于复杂嵌套的警告。
  4. 功能行为保持不变:当 PD 模式启且选择器均为空时,仅当非 IGW 模式或 IGW 模式下选择器也为空时才发出警告并返回 false;否则继续正常逻辑。
文件 模块 状态 重要度
sgl-model-gateway/src/service_discovery.rs 服务发现 modified 6.04

关键符号

PodInfo::should_include

关键源码片段

sgl-model-gateway/src/service_discovery.rs data-contract

修改了 should_include 函数中的条件逻辑,修复 Clippy lint 警告。

// sgl-model-gateway/src/service_discovery.rs
impl PodInfo {
    pub fn should_include(pod: &Pod, config: &ServiceDiscoveryConfig) -> bool {
        if config.pd_mode {
            // 原来嵌套的 if 合并为一个复合条件:当 prefill 和 decode 都为空
            // 且(非 IGW 模式 或 IGW 模式下 selector 为空)时发出警告并排除
            if config.prefill_selector.is_empty()
                && config.decode_selector.is_empty()
                && (!config.igw_mode || config.selector.is_empty())
            {
                warn!("PD mode enabled but both prefill_selector and decode_selector are empty");
                return false;
            }
            let matches_pd = Self::matches_selector(pod, &config.prefill_selector)
                || Self::matches_selector(pod, &config.decode_selector);
            // 在 IGW 模式下,也通过 selector 发现常规 worker
            let matches_regular = config.igw_mode
                && !config.selector.is_empty()
                && Self::matches_selector(pod, &config.selector);
            matches_pd || matches_regular
        } else {
            if config.selector.is_empty() {
                warn!("Regular mode enabled but selector is empty");
                return false;
            }
            Self::matches_selector(pod, &config.selector)
        }
    }
}

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

低风险。变更仅涉及 Clippy lint 修复,逻辑等价性通过 CI 验证。但需注意条件重构的等价性:原始逻辑是 "当 prefill 和 decode 都为空且非 IGW 模式(或 IGW 模式但 selector 为空)时警告并返回 false",新逻辑同样实现了此效果,因此无回归风险。

影响范围仅限 sgl-model-gateway 模块的 Rust 源码,修复 CI 检查,无功能变更。对用户无感知。

关联 Issue

#25294 [SMG] Support regular worker discovery alongside PD workers in IGW mode

完整报告

参与讨论