增加监控导出端口一致性audit#10
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a port alignment auditing tool (tools/port_alignment.py) and its corresponding unit tests (tests/test_port_alignment.py) to ensure consistent port configuration across code, scripts, and deployment files. The review feedback highlights opportunities to improve robustness by handling potential regex match failures (which could lead to AttributeError) and verifying that ports are actually found in the YAML configuration to avoid false-positive alignment results.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| cli_default = int(CLI_RE.search(cli_text).group(1)) | ||
| script_default = int(SCRIPT_RE.search(script_text).group(1)) |
There was a problem hiding this comment.
如果 CLI_RE.search(cli_text) 或 SCRIPT_RE.search(script_text) 未能匹配到任何内容(返回 None),直接调用 .group(1) 会抛出 AttributeError: 'NoneType' object has no attribute 'group' 异常。
建议在提取端口前先进行非空校验,并在未匹配时抛出更具可读性的异常或进行优雅处理。
cli_match = CLI_RE.search(cli_text)
script_match = SCRIPT_RE.search(script_text)
if not cli_match:
raise ValueError("Failed to find CLI default port in mx_exporter/__init__.py")
if not script_match:
raise ValueError("Failed to find HOST_PORT in start_mxexporter.sh")
cli_default = int(cli_match.group(1))
script_default = int(script_match.group(1))| static_ports = sorted({int(value) for value in YAML_PORT_RE.findall(static_text)}) | ||
| aligned = script_default == cli_default and all(port == cli_default for port in static_ports) |
There was a problem hiding this comment.
如果 YAML_PORT_RE.findall(static_text) 没有匹配到任何端口(例如 YAML 格式发生变化导致正则失效),static_ports 将为空列表,此时 aligned 仍会返回 True。
建议增加对 static_ports 是否为空的校验,以避免因匹配失败导致的一致性误判。
static_ports = sorted({int(value) for value in YAML_PORT_RE.findall(static_text)})
if not static_ports:
raise ValueError("Failed to find any ports in mx-exporter-daemonset.yaml")
aligned = script_default == cli_default and all(port == cli_default for port in static_ports)
这次改动补上了监控导出端口一致性audit,主要是为了解决监控导出与部署排查流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。