From: Pere Diaz Bou Date: Thu, 16 Dec 2021 12:34:35 +0000 (+0100) Subject: monitoring/grafana: Replace missing legendFormat warning with error X-Git-Tag: v16.2.8~6^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5684e73d82f4f8a9ae6c2b05299d2a94c16ba4c7;p=ceph.git monitoring/grafana: Replace missing legendFormat warning with error Signed-off-by: Pere Diaz Bou --- diff --git a/monitoring/ceph-mixin/tests_dashboards/util.py b/monitoring/ceph-mixin/tests_dashboards/util.py index 1d8b57325eb0..e52a36469e2c 100644 --- a/monitoring/ceph-mixin/tests_dashboards/util.py +++ b/monitoring/ceph-mixin/tests_dashboards/util.py @@ -41,6 +41,8 @@ def add_dashboard_queries(data: Dict[str, Any], dashboard_data: Dict[str, Any], """ if 'panels' not in dashboard_data: return + error = 0 + dashboard_title = dashboard_data['title'] for panel in dashboard_data['panels']: if ( 'title' in panel @@ -51,15 +53,21 @@ def add_dashboard_queries(data: Dict[str, Any], dashboard_data: Dict[str, Any], for target in panel['targets']: title = panel['title'] legend_format = target['legendFormat'] if 'legendFormat' in target else "" - query_id = title + '-' + legend_format + query_id = f'{title}-{legend_format}' if query_id in data['queries']: # NOTE: If two or more panels have the same name and legend it # might suggest a refactoring is needed or add something else # to identify each query. - cprint((f'WARNING: Query in panel "{title}" with legend "{legend_format}"' - ' already exists'), 'yellow') + conflict_file = data['queries'][query_id]['path'].split('/')[-1] + file = path.split('/')[-1] + cprint((f'ERROR: Query in panel "{title}" with legend "{legend_format}"' + f' already exists. Conflict "{conflict_file}" ' + f'with: "{file}"'), 'red') + error = 1 data['queries'][query_id] = {'query': target['expr'], 'path': path} data['stats'][path]['total'] += 1 + if error: + raise RuntimeError(f'Missing legend_format in queries, please add a proper value.') def add_dashboard_variables(data: Dict[str, Any], dashboard_data: Dict[str, Any]) -> None: