Skip to content

Commit

Permalink
Fix overwriting of dashboards in other folders
Browse files Browse the repository at this point in the history
Without this, we end up overwriting some but not all dashboards in a
folder we don't add the dashboard to. This is probably related to naming
and generated uid's overlapping or similar. This has been tested to work
well though.
  • Loading branch information
consideRatio committed Apr 12, 2024
1 parent 7118877 commit 49a0bed
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import argparse
import hashlib
import json
import os
import re
Expand Down Expand Up @@ -69,13 +70,19 @@ def build_dashboard(dashboard_path, api):

def deploy_dashboard(dashboard_path, folder_uid, api):
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)

data = {'dashboard': db, 'folderId': folder_uid, 'overwrite': True}
data = {'dashboard': db, 'folderUid': folder_uid, 'overwrite': True}
api('/dashboards/db', data)


Expand Down Expand Up @@ -187,10 +194,10 @@ def main():
grafana_token,
no_tls_verify=args.no_tls_verify,
)
folder = ensure_folder(args.folder_name, args.folder_uid, api)
ensure_folder(args.folder_name, args.folder_uid, api)

for dashboard in glob(f'{args.dashboards_dir}/*.jsonnet'):
deploy_dashboard(dashboard, folder['id'], api)
deploy_dashboard(dashboard, args.folder_uid, api)
print(f'Deployed {dashboard}')


Expand Down

0 comments on commit 49a0bed

Please sign in to comment.