Skip to content

[Feature]: 插件 entry point 加载失败时补充可见日志,便于定位插件未注册问题 #708

In review

Description

@SJTUyh

💻 需求背景、当前现状、期望实现的功能内容、具体的设计方案、以及测试方案

需求背景

AISBench 通过 Python entry point(group ais_bench.benchmark_plugins)把插件包里的 models/、clients/ 等子包追加到对应注册器的 locations。按 plugin_examples/README.md 安装插件后,如果插件包导入失败(依赖缺失、setup.py 中 entry point 指向错误模块、包名与目录不一致等),当前实现不会输出任何日志:用户只会在后续使用 MODELS / CLIENTS 等注册器时报 KeyError: 'xxx is not in the model registry',无法区分「插件没装」「插件结构不对」「插件导入报错」,排查成本高。

当前现状

  • ais_bench/benchmark/registry.py 第 53-59 行:entry_point.load() 抛出的异常被 except Exception: continue 直接跳过,没有任何日志。
  • 同文件第 60-61 行:外层 entry_points() 整体失败时被 except Exception: pass 吞掉,无法区分「没有安装插件」和「元数据读取失败」。
  • 同文件第 56-57 行:插件包被成功加载但 _submodule_exists() 返回 False(例如插件只提供 models/,而本次探测的是 clients)时同样静默跳过,用户不知道插件已被发现但结构不匹配。
  • tests/UT/test_registry.py 第 86-103 行已经固定了「broken entry point 被忽略且不导入插件代码」的行为,但没有校验日志输出。

期望实现的功能内容

  1. 插件 entry point 加载失败时输出一条 warning:包含 entry point 名称、目标值(entry_point.value)、异常类型与摘要,并提示该插件提供的模块将不可用。
  2. entry_points() 整体发现失败时输出 warning(含异常摘要),便于区分「没有插件」与「元数据读取失败」。
  3. 插件被发现但缺少目标子模块时输出 debug 日志(带插件名与缺失子目录),正常启动不刷屏。
  4. 全部插件加载成功时不新增 INFO 级日志,保持现有终端输出;get_plugin_locations() 的返回值和导入时机完全不变,保证兼容性。
  5. 失败日志中提示可通过 --debug 查看完整 traceback(或在 debug 级别补一条带 exc_info=True 的记录),让用户可以自助定位插件导入错误。

具体的设计方案

在 ais_bench/benchmark/registry.py 中:

  1. 增加模块级 logger = AISLogger()。utils/logging/logger.py 只依赖 error_codes 与 global_consts,不反向依赖 registry,不会引入循环导入,也不会触发插件代码导入。
  2. 改造 get_plugin_locations():
for entry_point in entry_points().select(group='ais_bench.benchmark_plugins'):
    try:
        pkg = entry_point.load()
    except Exception as exc:
        logger.warning(
            "Failed to load AISBench plugin entry point '%s' (%s): %s; "
            "modules provided by this plugin will be unavailable. "
            "Re-run with --debug for the full traceback.",
            entry_point.name, entry_point.value, exc,
        )
        logger.debug("Plugin entry point load failed", exc_info=True)
        continue
    if _submodule_exists(pkg, module_dir):
        locations.append(f'{pkg.__name__}.{module_dir}')
    else:
        logger.debug(
            "AISBench plugin '%s' has no submodule '%s', skipped.",
            pkg.__name__, module_dir,
        )
  1. 外层 except Exception: 改为 logger.warning("Failed to discover AISBench plugin entry points: %s", exc, exc_info=True) 后返回已收集的 locations(保持「插件探测失败不影响主流程」的既有约定)。
  2. 不改变 _submodule_exists() 的纯文件系统检查语义,仍然不导入插件子模块。

测试方案

  • 在 tests/UT/test_registry.py 扩展 test_get_plugin_locations_uses_physical_packages_without_import:用 self.assertLogs 断言 broken entry point 产生 warning,内容包含插件名、目标值与 broken plugin,同时 locations 仍只包含有效插件、mock_import.assert_not_called() 保持成立。
  • 新增「entry_points() 抛异常」用例:断言产生 warning 且返回 [](沿用现有 test_get_plugin_locations_handles_discovery_failure 的 mock 方式)。
  • 新增「插件缺少目标子模块」用例:断言产生 debug 日志、locations 为空。
  • 手工验证:在 plugin_examples 环境下把 setup.py 的 entry point 目标包名改错后 pip install -e .,运行 ais_bench config_example/perf_example.py --mode perf --debug,确认启动阶段输出警告并给出插件名与异常;恢复正确包名后不再出现该警告。
  • 回归:python -m pytest tests/UT/test_registry.py 全部通过。

替代方案

  • 直接抛错:单个插件损坏会导致整个 AISBench 无法启动,破坏现有「插件探测失败不影响主流程」的行为,不采用。
  • 在注册器 KeyError 时反查 entry points:需要重复遍历元数据,且拿不到原始异常,定位信息比在加载点记录更少。
  • 新增 ais_bench plugin list/check 子命令:能力更完整,但超出「日志可读性小改进」的范围,可作为后续增强。

补充说明

  • 本改动只新增日志,不改变插件导入时机、注册器 locations 内容和返回值,风险低。
  • 可同步在 plugin_examples/README.md 的「插件安装使用」章节补一段「插件未生效时如何排查」,指向上述 warning 与 --debug 用法。
  • 日志中的 entry_point.value 在旧版本 importlib.metadata 下也可用,不依赖 entry_point.dist,避免兼容性问题。

本 Issue 由 Agent「我的 Agent」生成(模型:trae-agent),经 @SJTUyh 审核后以本人身份创建。

Activity

  1. github-actions commented on Nov 24, 2026

    @github-actions

    🌟欢迎给AISBench benchmark测评工具提issue,我们会尽快处理您的诉求~

  2. github-actions commented on Nov 24, 2026

    @github-actions

    🤖 基于AI机器人的issue内容完整性检查结果:

    问题内容检查结果

    检查状态

    PASS

    详细检查

    • 问题/痛点描述: COMPLETE
    • 建议方案: COMPLETE
    • 预期价值: COMPLETE

    改进建议

    所有内容已完备!

    补充说明

    该 Issue 内容非常完整,清晰地阐述了问题背景、当前现状、期望实现的功能、具体的设计方案、测试方案以及替代方案。虽然没有明确的“预期价值”标题,但其内容(如“便于定位插件未注册问题”、“排查成本高”的解决、“风险低”等)已充分体现在“需求背景”、“期望实现的功能内容”和“补充说明”中,信息量充足。

    👉 如果想重新检查,在评论区@issue_checker即可。

    【强烈推荐❤️‍🔥】确保issue描述完整后,可以试着将issue交给Ask DeepWiki回答,deepwiki包含了和工具相关的所有知识库

  3. added
    content_check_passed
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    content_check_passedfeature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions