[monitor-config] fix: config optim#92
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the documentation and runtime logic for Grafana dashboards in RL-Insight. Specifically, it introduces a staging step (_stage_grafana_dashboards) that copies bundled dashboard JSON files from the package directory to a runtime directory (~/.rl-insight/runtime/dashboards) at startup, and configures Grafana to provision from there. It also cleans up the default Prometheus scrape configurations. The review feedback highlights several edge cases in the new staging function that could lead to runtime errors, such as handling missing configuration values, safely removing existing files or symlinks at the target path, and ensuring the source path is a directory before iterating over it.
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.
| source = Path(str(OmegaConf.select(conf, "grafana.dashboards_dir"))).resolve() | ||
| target = (runtime_dir / "dashboards").resolve() | ||
| if source == target: | ||
| target.mkdir(parents=True, exist_ok=True) | ||
| return target |
There was a problem hiding this comment.
If grafana.dashboards_dir is not configured or is set to None, OmegaConf.select will return None. Converting None to a string results in "None", which then resolves to a path named "None" in the current working directory. We should safely handle the case where grafana.dashboards_dir is missing or None before resolving it.
| source = Path(str(OmegaConf.select(conf, "grafana.dashboards_dir"))).resolve() | |
| target = (runtime_dir / "dashboards").resolve() | |
| if source == target: | |
| target.mkdir(parents=True, exist_ok=True) | |
| return target | |
| target = (runtime_dir / "dashboards").resolve() | |
| dashboards_dir = OmegaConf.select(conf, "grafana.dashboards_dir") | |
| if not dashboards_dir: | |
| target.mkdir(parents=True, exist_ok=True) | |
| return target | |
| source = Path(str(dashboards_dir)).resolve() | |
| if source == target: | |
| target.mkdir(parents=True, exist_ok=True) | |
| return target |
There was a problem hiding this comment.
fix. the code removed
| if target.exists(): | ||
| shutil.rmtree(target) | ||
| target.mkdir(parents=True, exist_ok=True) |
There was a problem hiding this comment.
If target exists but is a file or a symlink, calling shutil.rmtree(target) will raise an exception (e.g., NotADirectoryError). It is safer to check if target is a directory and not a symlink before calling shutil.rmtree, and otherwise use target.unlink() to remove it.
| if target.exists(): | |
| shutil.rmtree(target) | |
| target.mkdir(parents=True, exist_ok=True) | |
| if target.exists() or target.is_symlink(): | |
| if target.is_dir() and not target.is_symlink(): | |
| shutil.rmtree(target) | |
| else: | |
| target.unlink() | |
| target.mkdir(parents=True, exist_ok=True) |
There was a problem hiding this comment.
fix. the code removed
| if not source.exists(): | ||
| return target |
There was a problem hiding this comment.
If source exists but is a file instead of a directory, calling source.iterdir() on the next line will raise a NotADirectoryError. We should ensure that source is a directory before attempting to iterate over its contents.
| if not source.exists(): | |
| return target | |
| if not source.exists() or not source.is_dir(): | |
| return target |
There was a problem hiding this comment.
fix. the code removed
25741bd to
18a3c17
Compare
What does this PR do?
This PR cleans the bundled Prometheus config by removing accidentally committed runtime scrape targets. It also stages bundled Grafana dashboards into the runtime directory and provisions Grafana from that runtime copy, while preserving user-added runtime dashboard files.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}include:monitor-api,monitor-cli,monitor-collector,monitor-server,monitor-configfor online monitor changesrecipefor offline analysis changes, including pipeline, parser, visualizer, data checker, recipe config, examples, and sample datadoc,ci,perf,deployment,miscfor cross-cutting changes,like[recipe, ci]or[monitor-server, monitor-config]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][mstx, torch_profile] feat: support timeline parsingTest
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always