Skip to content

Commit 6a67536

Browse files
committed
update dashboards and claude instructions
1 parent b21192f commit 6a67536

File tree

6 files changed

+544
-498
lines changed

6 files changed

+544
-498
lines changed

claude/grafana-dashboard-sync-instructions.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This script will:
4949
- Use upstream dashboards as the base structure
5050
- Add K8s variables (env, service) to all dashboards - NO pod variable
5151
- Transform all PromQL queries to use service-only label selectors
52+
- Hardcode datasource UID `o59qe-zVz` in all panels
5253
- Preserve Scroll UIDs
5354
- Save updated dashboards to `etc/grafana/scroll/`
5455

@@ -163,7 +164,24 @@ All Scroll dashboards must include these variables (2 only - NO pod variable):
163164
}
164165
```
165166

166-
**Important:** No `pod` variable - queries aggregate by service only, enabling data continuity when pods are replaced.
167+
**Important:**
168+
- No `pod` variable - queries aggregate by service only, enabling data continuity when pods are replaced
169+
- No `datasource` variable - datasource UID is hardcoded in all panels
170+
171+
### Hardcoded Datasource
172+
173+
All panels and targets use a hardcoded Prometheus datasource UID:
174+
175+
```json
176+
{
177+
"datasource": {
178+
"type": "prometheus",
179+
"uid": "o59qe-zVz"
180+
}
181+
}
182+
```
183+
184+
This matches the Scroll deployment's Prometheus datasource configuration.
167185

168186
### Query Transformation Rules
169187

@@ -399,4 +417,7 @@ For questions about this process:
399417

400418
**Last updated:** 2025-12-01
401419
**Last sync:** 2025-12-01 (Converged with upstream, service-only pattern for data continuity)
402-
**Pattern:** 2 variables (env, service) - NO pod variable - enables seamless pod replacement
420+
**Pattern:**
421+
- 2 variables only: `env`, `service` (NO pod variable)
422+
- Hardcoded datasource UID: `o59qe-zVz`
423+
- Enables seamless pod replacement with data continuity

claude/tools/sync_dashboard.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,33 @@ def transform_target(target: Dict) -> Dict:
135135
target['expr'] = transform_query(target['expr'])
136136
return target
137137

138+
def set_hardcoded_datasource(obj: Any) -> Any:
139+
"""Replace all datasource references with hardcoded UID"""
140+
if isinstance(obj, dict):
141+
# If this is a datasource object, replace with hardcoded UID
142+
if 'datasource' in obj:
143+
obj['datasource'] = {
144+
"type": "prometheus",
145+
"uid": "o59qe-zVz"
146+
}
147+
# Recursively process all dict values
148+
for key, value in obj.items():
149+
obj[key] = set_hardcoded_datasource(value)
150+
elif isinstance(obj, list):
151+
# Recursively process all list items
152+
return [set_hardcoded_datasource(item) for item in obj]
153+
154+
return obj
155+
138156
def transform_panel(panel: Dict) -> Dict:
139157
"""Transform all queries in a panel recursively"""
140158
# Transform targets in this panel
141159
if 'targets' in panel:
142160
panel['targets'] = [transform_target(t) for t in panel['targets']]
143161

162+
# Set hardcoded datasource for panel and all nested objects
163+
panel = set_hardcoded_datasource(panel)
164+
144165
# Recursively handle nested panels (rows with collapsed panels)
145166
if 'panels' in panel:
146167
panel['panels'] = [transform_panel(p) for p in panel['panels']]
@@ -173,8 +194,10 @@ def sync_dashboard(upstream_path: str, scroll_uid: str = None, output_path: str
173194
panel_count = 0
174195
target_count = 0
175196

197+
transformed_panels = []
176198
for panel in dashboard.get('panels', []):
177199
panel = transform_panel(panel)
200+
transformed_panels.append(panel)
178201
panel_count += 1
179202
if 'targets' in panel:
180203
target_count += len(panel['targets'])
@@ -184,6 +207,8 @@ def sync_dashboard(upstream_path: str, scroll_uid: str = None, output_path: str
184207
if 'targets' in subpanel:
185208
target_count += len(subpanel['targets'])
186209

210+
dashboard['panels'] = transformed_panels
211+
187212
print(f" Transformed panels: {panel_count}")
188213
print(f" Transformed queries: {target_count}")
189214
print(f" Variables: {len(dashboard['templating']['list'])}")

0 commit comments

Comments
 (0)