Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard sync library panel version mismatch bug fix #7716

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading