@@ -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+
138156def 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