Skip to content

增加监控导出看板清单结构化输出#7

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mxexporter-dashboard-inventory-json
Open

增加监控导出看板清单结构化输出#7
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mxexporter-dashboard-inventory-json

Conversation

@ghangz

@ghangz ghangz commented Jun 10, 2026

Copy link
Copy Markdown

这次改动补上了监控导出看板清单结构化输出,主要是为了解决监控导出与部署排查流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。

实现上补充了对应工具或脚本逻辑,同时尽量保持现有用法不变,避免影响已有流程。

这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Python script, tools/dashboard_inventory.py, to inventory Grafana dashboards by parsing JSON files in the deployment directory. The reviewer suggested improving the script's robustness by wrapping the JSON parsing in a try-except block to handle potential decoding errors gracefully. Additionally, they recommended breaking up a long line of code to comply with PEP 8 line length guidelines.

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.

Comment thread tools/dashboard_inventory.py Outdated
Comment on lines +14 to +16
data = json.loads(path.read_text(encoding="utf-8-sig"))
panels = data.get("panels", [])
dashboards.append({"path": path.relative_to(root).as_posix(), "title": data.get("title", ""), "uid": data.get("uid", ""), "panel_count": len(panels)})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这里有两个可以改进的地方:

  1. 健壮性(Robustness):直接调用 json.loads() 解析文件,如果某个 JSON 文件格式损坏,整个脚本会直接崩溃。建议添加 try-except 块捕获 json.JSONDecodeError,并抛出包含文件路径的友好错误信息,方便排查。
  2. 代码风格(PEP 8):原第 16 行的代码长度(161 字符)严重超出了 PEP 8 规范推荐的单行长度限制(79 或 120 字符)。建议将其折行以提高可读性。

以下是改进后的代码建议:

Suggested change
data = json.loads(path.read_text(encoding="utf-8-sig"))
panels = data.get("panels", [])
dashboards.append({"path": path.relative_to(root).as_posix(), "title": data.get("title", ""), "uid": data.get("uid", ""), "panel_count": len(panels)})
try:
data = json.loads(path.read_text(encoding="utf-8-sig"))
except json.JSONDecodeError as e:
raise RuntimeError(f"Failed to parse JSON file {path}: {e}") from e
panels = data.get("panels", [])
dashboards.append(
{
"path": path.relative_to(root).as_posix(),
"title": data.get("title", ""),
"uid": data.get("uid", ""),
"panel_count": len(panels),
}
)
References
  1. PEP 8: Limit all lines to a maximum of 79 characters (or 120 for relaxed projects) to maintain readability. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant