Skip to content

Commit

Permalink
Merge pull request #122 from consideRatio/pr/error-if-return-empty
Browse files Browse the repository at this point in the history
Error in build_dashboard if about to return empty object
  • Loading branch information
consideRatio authored Apr 13, 2024
2 parents 1fda6d3 + 677b87e commit 0345d7f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -78,23 +78,24 @@ 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):
"""
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
# based on some hash that didn't get new input when deployed to the second
# 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
Expand Down

0 comments on commit 0345d7f

Please sign in to comment.