From 34b438622bb0c16ce2a75975fbfa5bd7db55c098 Mon Sep 17 00:00:00 2001 From: Christoph Alt <christoph.alt@fau.de> Date: Tue, 11 Oct 2022 18:56:57 +0200 Subject: [PATCH] fixed annotations datasource and added extra function for commit annotion --- dashboards/annotations.py | 4 ++-- dashboards/dashboard_base.py | 18 ++++++++++++------ dashboards/dashboard_list.py | 22 +++++++++------------- tests/test_annotation.py | 5 +++-- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/dashboards/annotations.py b/dashboards/annotations.py index 541173d..710e415 100644 --- a/dashboards/annotations.py +++ b/dashboards/annotations.py @@ -5,14 +5,14 @@ from dataclasses import dataclass class Annotation: # type: str = "influx" # uid: str - dataSource: str + datasource: str iconColor: str name: str query: str def to_json_data(self): return { - "dataSource": self.dataSource, + "datasource": self.datasource, "enable": True, "iconColor": self.iconColor, "name": self.name, diff --git a/dashboards/dashboard_base.py b/dashboards/dashboard_base.py index d1fb497..0f758ff 100644 --- a/dashboards/dashboard_base.py +++ b/dashboards/dashboard_base.py @@ -1,13 +1,13 @@ from dataclasses import asdict, dataclass from typing import List, Union -from grafanalib.core import (Dashboard, GridPos, Panel, Repeat, RowPanel, Stat, - Template, Templating, Time, TimeSeries, - Annotations) +from grafanalib.core import (Annotations, Dashboard, GridPos, Panel, Repeat, + RowPanel, Stat, Template, Templating, Time, + TimeSeries) from grafanalib.influxdb import InfluxDBTarget -from dashboards.influx_queries import Query from dashboards.annotations import Annotation +from dashboards.influx_queries import Query def get_influx_target(target_query: str, **kwargs) -> InfluxDBTarget: @@ -21,6 +21,13 @@ def get_annotation(*args, **kwargs): return Annotations([Annotation(*args, **kwargs).to_json_data()]) +def get_commit_annotation(datasource: str, name: str, color: str, measurment_name: str): + query = ("SELECT \"commit\" from " + f"( SELECT first(\"mlupsPerProcess\") FROM \"{measurment_name}\" " + "WHERE host =~ /^$host$/ AND $timeFilter GROUP BY \"commit\" )") + return get_annotation(datasource, color, name, query) + + def get_dashboard_variable_query(name: str, template_query: str, dataSource: str, **kwargs) -> Template: return Template(name, @@ -58,8 +65,7 @@ def build_row_repeat_dashboard( title=f'{row_repeat_var.name}: ${row_repeat_var.name}', panels=[ TimeSeries( - title= - f'{panel_repeat_var.name}: ${panel_repeat_var.name}', + title=f'{panel_repeat_var.name}: ${panel_repeat_var.name}', dataSource=dataSource, targets=[get_influx_target(str(panel_query))], repeat=Repeat('h', panel_repeat_var.name), diff --git a/dashboards/dashboard_list.py b/dashboards/dashboard_list.py index 611a9dd..abace5a 100644 --- a/dashboards/dashboard_list.py +++ b/dashboards/dashboard_list.py @@ -1,14 +1,15 @@ from typing import List -from dashboards.units import Units from dashboards.dashboard_base import (DashboardOptions, build_dashboard, build_row_repeat_dashboard, + get_commit_annotation, get_dashboard_variable_query, get_grid_pos, get_stat_panel, - pack_in_row, get_annotation) + pack_in_row) from dashboards.influx_queries import (Query, get_variable_condition, join_conditions, join_variable_and, show_tag_values) +from dashboards.units import Units def _uniform_grid(arch: str, group_by: List[str]): @@ -34,8 +35,7 @@ def _uniform_grid(arch: str, group_by: List[str]): group_by=group_by) options = DashboardOptions( title=f'Uniform Grid {arch}', - description= - f"Benchmark dashboard for the Uniform Grid {arch} Benchmark from walberla", + description=f"Benchmark dashboard for the Uniform Grid {arch} Benchmark from walberla", tags=[arch, 'benchmark', 'walberla', 'Uniform Grid'], timezone="browser", ) @@ -103,8 +103,7 @@ def dashboard_granular_gas(): group_by=['mpi_num_processes', 'omp_max_threads']) options = DashboardOptions( title='Granular Gas Kernel Benchmark', - description= - "Benchmark dashboard for the Granular Gas Benchmark from walberla", + description="Benchmark dashboard for the Granular Gas Benchmark from walberla", tags=['CPU', 'benchmark', 'walberla', 'Granular Gas'], timezone="browser", ) @@ -122,8 +121,7 @@ def dashboard_phasefieldallenchan(): options = DashboardOptions( title='Phase Field Allen Chan', - description= - "Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla", + description="Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla", tags=['CPU', 'benchmark', 'walberla', 'PhaseField Allen Cahn'], timezone="browser", ) @@ -156,9 +154,8 @@ def dashboard_phasefieldallenchan(): dashboard.rows = [ pack_in_row("Power Consumption", panel_power), *dashboard.rows ] - annotation_query = "SELECT \"commit\" from( SELECT first(\"mlupsPerProcess\") FROM \"PhaseFieldAllenCahn\" WHERE host =~ /^$host$/ AND $timeFilter GROUP BY \"commit\" )" - dashboard.annotations = get_annotation("InfluxDB-1", "red", "commits", - annotation_query) + dashboard.annotations = get_commit_annotation("InfluxDB-1", "red", "commits", + measurment_name) return dashboard.auto_panel_ids() @@ -171,8 +168,7 @@ def dashboard_phasefieldallenchangpu(): options = DashboardOptions( title='Phase Field Allen Chan GPU', - description= - "Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla", + description="Benchmark dashboard for the Phasefield Allen Cahn Benchmark from walberla", tags=['GPU', 'benchmark', 'walberla', 'PhaseField Allen Cahn'], timezone="browser", ) diff --git a/tests/test_annotation.py b/tests/test_annotation.py index 83265e8..e7a7794 100644 --- a/tests/test_annotation.py +++ b/tests/test_annotation.py @@ -1,9 +1,10 @@ -from dashboards.annotations import Annotation import json +from dashboards.annotations import Annotation + expected_str = r""" { - "dataSource": "InfluxDB-1", + "datasource": "InfluxDB-1", "enable": true, "iconColor": "red", "name": "commit", -- GitLab