]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monitoring/grafana: Replace missing legendFormat warning with error
authorPere Diaz Bou <pdiazbou@redhat.com>
Thu, 16 Dec 2021 12:34:35 +0000 (13:34 +0100)
committerPere Diaz Bou <pdiazbou@redhat.com>
Tue, 26 Apr 2022 07:29:56 +0000 (09:29 +0200)
Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
monitoring/ceph-mixin/tests_dashboards/util.py

index 1d8b57325eb05c42b05cda7c3b3fefeb1ac998f4..e52a36469e2c9f025e45d5e157817dd1d8a086b7 100644 (file)
@@ -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: