Skip to content
Snippets Groups Projects
Commit eaf6f584 authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Fix provisioning of static eumetsat dashboard

Fix datasource comparison after 11.2
Add more useful logging for deletion of dashboards
parent 89082cc3
No related branches found
No related tags found
No related merge requests found
......@@ -116,5 +116,6 @@
},
"timezone": "",
"title": "EUMETSAT",
"uid": "eumetsat",
"version": 1
}
......@@ -207,16 +207,7 @@ def create_dashboard(request: TokenRequest, dashboard: dict, folder_id=None):
has_uid = dashboard.get('uid') is not None
if has_uid:
existing_dashboard = _get_dashboard(request, uid=dashboard['uid'])
# The title might not match the one that's provisioned with that UID.
# Try to find it by searching for the title instead.
if existing_dashboard is not None:
grafana_title = existing_dashboard['title']
different = grafana_title != title
else:
different = False
if existing_dashboard is None or different:
existing_dashboard = _search_dashboard(request, dashboard, folder_id)
if existing_dashboard:
......
......@@ -25,7 +25,7 @@ def _datasource_exists(datasource_to_check, provisioned_datasources):
return True
for datasource in provisioned_datasources:
exists = all(datasource.get(key) == datasource_to_check.get(key)
for key in datasource_to_check)
for key in datasource_to_check if key != 'secureJsonData') # we can't compare secureJsonData
if exists:
return True
return False
......
......@@ -220,7 +220,7 @@ def set_home_dashboard(request: TokenRequest, is_staff):
"""
payload = render_homedashboard(staff=is_staff)
dashboard = create_dashboard(request, payload)
r = request.put('api/org/preferences', json={
request.put('api/org/preferences', json={
'homeDashboardId': dashboard.get('id')
}).json()
return r and r.get('message') == 'Preferences updated'
return dashboard
......@@ -674,20 +674,18 @@ def _provision_static_dashboards(config, org_config, ds_name, token):
logger.info('Provisioning static dashboards')
for dashboard in get_dashboard_definitions():
if dashboard['title'] not in excluded_dashboards:
logger.info(f'Provisioning static {dashboard["title"]} dashboard')
res = create_dashboard(token, dashboard)
if res:
# yield a fake dashboard dict
# ... only the 'uid' element is referenced
yield {'uid': res.get('uid')}
yield res
else:
logger.info(f'Ensuring {dashboard["title"]} static dashboard is deleted')
delete_dashboard(token, dashboard)
# Home dashboard is always called "Home"
# Make sure it's set for the organization
logger.info('Configuring Home dashboard')
set_home_dashboard(token, is_staff=org_config['name'] == 'GÉANT Staff')
yield {'uid': 'home'}
yield set_home_dashboard(token, is_staff=org_config['name'] == 'GÉANT Staff')
def _get_ignored_dashboards(config, org_config, token):
......@@ -716,9 +714,7 @@ def _get_ignored_dashboards(config, org_config, token):
continue
for dash in to_ignore:
# return a hard-coded fake dashboard dict
# ... only the 'uid' element is referenced
yield {'uid': dash['uid']} # could just yield dash
yield dash
def _provision_datasource(config, token):
......@@ -857,8 +853,7 @@ def provision(config, raise_exceptions=False):
logger.debug(accounts)
all_original_dashboards = list_dashboards(token_request)
all_original_dashboard_uids = {
d['uid'] for d in all_original_dashboards}
all_original_dashboard_uids = {d['uid']: d.get('folderUrl', '') + d['url'] for d in all_original_dashboards}
datasource = _provision_datasource(config, token_request)
ds_name = datasource.get('name', 'PollerInfluxDB')
......@@ -882,17 +877,21 @@ def provision(config, raise_exceptions=False):
config, org_config, token_request)
)
managed_dashboard_uids = set()
managed_dashboard_uids = {}
for dashboard in managed_dashboards:
if isinstance(dashboard, Future):
dashboard = dashboard.result()
if dashboard is None:
continue
managed_dashboard_uids.add(dashboard['uid'])
assert dashboard['uid'] not in managed_dashboard_uids, \
f'Dashboard with UID {dashboard["uid"]} already exists: {dashboard}'
managed_dashboard_uids[dashboard['uid']] = dashboard['url']
for uid in all_original_dashboard_uids - managed_dashboard_uids:
difference = set(all_original_dashboard_uids.keys()) - set(managed_dashboard_uids.keys())
for uid in difference:
info = all_original_dashboard_uids[uid]
# delete unmanaged dashboards
logger.info(f'Deleting stale dashboard with UID {uid}')
logger.info(f'Deleting stale dashboard {info} with UID {uid}')
delete_dashboard(token_request, {'uid': uid})
folders_to_keep = {
......
......@@ -223,11 +223,12 @@ def mock_grafana(data_config):
def _create_object(self, obj, all_objects):
id = obj.get("id")
uid = obj.get("uid")
uid = obj.get("uid") or next(self.uids)
obj = {
'url': '/fake/grafana/' + str(uid),
**obj,
"id": id if id is not None else next(self.ids),
"uid": str(uid if uid is not None else next(self.uids)),
"uid": str(uid),
}
all_objects[obj["uid"]] = obj
return obj
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment