From 677b87ea74ee8566ee98621930a37a647fd25f71 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sat, 13 Apr 2024 12:02:16 +0200 Subject: [PATCH] Error in build_dashboard if about to return empty object --- deploy.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/deploy.py b/deploy.py index f896026..2954171 100755 --- a/deploy.py +++ b/deploy.py @@ -66,7 +66,7 @@ def build_dashboard(dashboard_path, api): datasources = api("/datasources") datasources_names = [ds["name"] for ds in datasources] - return json.loads( + dashboard = json.loads( subprocess.check_output( [ "jsonnet", @@ -78,6 +78,9 @@ def build_dashboard(dashboard_path, api): ] ).decode() ) + if not dashboard: + raise ValueError(f"jsonnet render of {dashboard_path} led to an empty object") + return dashboard def deploy_dashboard(dashboard_path, folder_uid, api): @@ -85,6 +88,7 @@ def deploy_dashboard(dashboard_path, folder_uid, api): Creates a new dashboard or updates an existing dashboard. """ db = build_dashboard(dashboard_path, api) + # without this modification, deploying to a second folder deletes deployed # dashboards in another folder, likely due to generated dashboard UID is the # same as an already existing dashboard UID. They are probably generated @@ -92,9 +96,6 @@ def deploy_dashboard(dashboard_path, folder_uid, api): # folder compared to initially deployed to the first folder. db['uid'] = hashlib.sha256((dashboard_path + folder_uid).encode()).hexdigest()[:16] - if not db: - return - db = populate_template_variables(api, db) # api ref: https://grafana.com/docs/grafana/latest/developers/http_api/dashboard/#create--update-dashboard