Skip to content

Commit

Permalink
Dashboard sync library panel version mismatch bug fix (#7716)
Browse files Browse the repository at this point in the history
* Fix base directory folder UID

* Add version handling for library panel PATCH

Co-authored-by: Alan Zhang <[email protected]>
  • Loading branch information
ABZhang0 and Alan Zhang committed Jul 1, 2024
1 parent 78867bf commit 4112062
Show file tree
Hide file tree
Showing 5 changed files with 27,301 additions and 27,609 deletions.
6 changes: 5 additions & 1 deletion src/amg/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ Release History

1.3.4
++++++
* `az grafana dashboard sync`: use case-insensitive comparison for library panel folders
* `az grafana dashboard sync`: use case-insensitive comparison for library panel folders

1.3.5
++++++
* `az grafana dashboard sync`: fix version mismatch issue for library panel sync
16 changes: 10 additions & 6 deletions src/amg/azext_amg/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def sync(cmd, source, destination, folders_to_include=None, folders_to_exclude=N
continue

# Figure out whether we shall correct the data sources. It is possible the Uids are different
remap_datasource_uids(source_dashboard.get("dashboard"), uid_mapping, data_source_missed)
remap_datasource_uids(source_dashboard["dashboard"], uid_mapping, data_source_missed)

if not dry_run:
delete_dashboard(cmd, destination_workspace, dashboard_uid,
Expand All @@ -144,6 +144,7 @@ def sync(cmd, source, destination, folders_to_include=None, folders_to_exclude=N
continue

panel_name = content["result"]['name']
panel_folder_uid = content["result"]["folderUid"]
panel_folder_name = content["result"]["meta"]["folderName"]

# user error case where library panel in dashboard is not in an excluded folder
Expand All @@ -160,19 +161,22 @@ def sync(cmd, source, destination, folders_to_include=None, folders_to_exclude=N

if not dry_run:
logger.info("Syncing library panel: %s", panel_folder_name + "/" + panel_name)
endpoint = f'{destination_endpoint}/api/library-elements/'
payload = {
'uid': content["result"]["uid"],
'folderUid': content["result"]["folderUid"],
'folderUid': panel_folder_uid if panel_folder_uid != 'general' else '',
'name': panel_name,
'model': content["result"]["model"],
'kind': content["result"]["kind"],
}
(status, content) = send_grafana_post(f'{destination_endpoint}/api/library-elements/',
json.dumps(payload), http_headers)
(status, content) = send_grafana_post(endpoint, json.dumps(payload), http_headers)
if status >= 400:
if 'name or UID already exists' in content.get('message', ''):
send_grafana_patch(f'{destination_endpoint}/api/library-elements/{library_panel_uid}',
json.dumps(payload), http_headers)
endpoint = f'{destination_endpoint}/api/library-elements/{library_panel_uid}'
(status, content) = send_grafana_get(endpoint, http_headers)

payload["version"] = content["result"]["version"] # avoid version mismatch
(status, content) = send_grafana_patch(endpoint, json.dumps(payload), http_headers)
else:
logger.error(json.dumps(content))

Expand Down
Loading

0 comments on commit 4112062

Please sign in to comment.