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

Error in build_dashboard if about to return empty object #122

Merged
merged 1 commit into from
Apr 13, 2024
Merged
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
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
Loading