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

amg: support sync a single dashboard #6232

Merged
merged 3 commits into from
May 5, 2023
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
5 changes: 4 additions & 1 deletion src/amg/azext_amg/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@
type: command
short-summary: Sync Azure Managed Grafana dashboards from one instance to another instance. Note, dashboards with "provisioned" state will be skipped due to being read-only
examples:
- name: Sync only dashboardss under a few folders
- name: Sync only dashboards under a few folders
text: |
az grafana dashboard sync --source /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/source --destination /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/destination --folders-to-include "Azure Monitor Container Insights" "Azure Monitor"
- name: Sync a single dashboard
text: |
az grafana dashboard sync --source /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/source --destination /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/destination --folders-to-include "MyFolder" --dashboards-to-include "My Service Health"
- name: Preview the sync
text: |
az grafana dashboard sync --source /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/source --destination /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/workspaces/providers/Microsoft.Dashboard/grafana/destination --dry-run
Expand Down
2 changes: 2 additions & 0 deletions src/amg/azext_amg/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def load_arguments(self, _):
c.argument("destination", options_list=["--destination", "-d"], help="resource id of the destination workspace")
c.argument("dry_run", arg_type=get_three_state_flag(), help="preview changes w/o committing")
c.argument("folders", nargs="+", help="space separated folder list which sync command shall handle dashboards underneath")
c.argument("dashboards_to_include", nargs='+', help="Space separated titles of dashboards to include in sync. Pair with --folders-to-include for folders specific")
c.argument("dashboards_to_exclude", nargs='+', help="Space separated titles of dashboards to exclude in sync. Pair with --folders-to-exclude for folders specific")

with self.argument_context("grafana") as c:
c.argument("time_to_live", default="1d", help="The life duration. For example, 1d if your key is going to last fr one day. Supported units are: s,m,h,d,w,M,y")
Expand Down
11 changes: 8 additions & 3 deletions src/amg/azext_amg/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ def restore_grafana(cmd, grafana_name, archive_file, components=None, remap_data
destination_datasources=data_sources)


def sync_dashboard(cmd, source, destination, folders_to_include=None, folders_to_exclude=None, dry_run=None):
def sync_dashboard(cmd, source, destination, folders_to_include=None, folders_to_exclude=None,
dashboards_to_include=None, dashboards_to_exclude=None, dry_run=None):
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
if not is_valid_resource_id(source):
raise ArgumentUsageError(f"'{source}' isn't a valid resource id, please refer to example commands in help")
Expand Down Expand Up @@ -331,7 +332,8 @@ def sync_dashboard(cmd, source, destination, folders_to_include=None, folders_to
source_dashboard = show_dashboard(cmd, source_workspace, uid, resource_group_name=source_resource_group,
subscription=source_subscription)
folder_title = source_dashboard["meta"]["folderTitle"]
dashboard_path = folder_title + "/" + source_dashboard["dashboard"]["title"]
dashboard_title = source_dashboard["dashboard"]["title"]
dashboard_path = folder_title + "/" + dashboard_title

should_skip = False
if source_dashboard["meta"].get("provisioned"):
Expand All @@ -341,7 +343,10 @@ def sync_dashboard(cmd, source, destination, folders_to_include=None, folders_to
should_skip = not next((f for f in folders_to_include if folder_title.lower() == f.lower()), None)
if not should_skip and folders_to_exclude:
should_skip = next((f for f in folders_to_exclude if folder_title.lower() == f.lower()), None)

if dashboards_to_include:
should_skip = not next((p for p in dashboards_to_include if p.lower() == dashboard_title.lower()), None)
if dashboards_to_exclude:
should_skip = next((p for p in dashboards_to_exclude if p.lower() == dashboard_title.lower()), None)
if should_skip:
summary["dashboards_skipped"].append(dashboard_path)
continue
Expand Down
Loading