Skip to content
Snippets Groups Projects
Commit 2d5ee54b authored by Christoph Alt's avatar Christoph Alt
Browse files

removed more occurances of lower cased list

parent 17a6c3b6
No related branches found
No related tags found
1 merge request!11Adding Dashboards for Percolation and for the roofline dashboard
Pipeline #68841 passed
from dataclasses import dataclass, field from dataclasses import dataclass, field
# from collections import namedtuple # from collections import namedtuple
from dashboards.influx_queries import Query from dashboards.influx_queries import Query
from grafanalib.core import TimeSeries, Text, Stat, Template, Repeat, Threshold, Table, BarChart, PieChartv2 from grafanalib.core import (
TimeSeries,
Text,
Stat,
Template,
Repeat,
Threshold,
Table,
BarChart,
PieChartv2,
)
from dashboards.dashboard_base import get_influx_target from dashboards.dashboard_base import get_influx_target
from dashboards.legends import Units from dashboards.legends import Units
from numbers import Number from numbers import Number
from typing import List
# PanelInfos = namedtuple("PanelInfos", ("name", "unit")) # PanelInfos = namedtuple("PanelInfos", ("name", "unit"))
...@@ -20,30 +32,49 @@ def is_regex(name): ...@@ -20,30 +32,49 @@ def is_regex(name):
return name[0] == "/" and name[-1] == "/" return name[0] == "/" and name[-1] == "/"
def get_time_series_panel(panel_infos: PanelInfos, def get_time_series_panel(
data_source: str, panel_infos: PanelInfos,
query_list: list[Query], data_source: str,
*, query_list: List[Query],
overrides=None, *,
pointSize: int = 9, overrides=None,
**kwargs): pointSize: int = 9,
**kwargs,
):
targets = [get_influx_target(str(query)) for query in query_list] targets = [get_influx_target(str(query)) for query in query_list]
new_kwargs = {**kwargs} new_kwargs = {**kwargs}
if panel_infos.absthreshold is not None: if panel_infos.absthreshold is not None:
if 'thresholdsStyleMode' not in new_kwargs: if "thresholdsStyleMode" not in new_kwargs:
new_kwargs.update({ new_kwargs.update(
'thresholdType': 'absolute', {
'thresholds': [Threshold('green', 0, 0.0), "thresholdType": "absolute",
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt')], "thresholds": [
'thresholdsStyleMode': 'line' Threshold("green", 0, 0.0),
}) Threshold(
"red",
index=1,
value=float(panel_infos.absthreshold),
op="lt",
),
],
"thresholdsStyleMode": "line",
}
)
else: else:
new_kwargs.update({ new_kwargs.update(
'thresholdType': 'absolute', {
'thresholds': [Threshold('green', 0, 0.0), "thresholdType": "absolute",
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt')] "thresholds": [
}) Threshold("green", 0, 0.0),
Threshold(
"red",
index=1,
value=float(panel_infos.absthreshold),
op="lt",
),
],
}
)
return TimeSeries( return TimeSeries(
title=panel_infos.name, title=panel_infos.name,
...@@ -53,71 +84,85 @@ def get_time_series_panel(panel_infos: PanelInfos, ...@@ -53,71 +84,85 @@ def get_time_series_panel(panel_infos: PanelInfos,
pointSize=pointSize, pointSize=pointSize,
overrides=overrides, overrides=overrides,
**new_kwargs, **new_kwargs,
) )
def get_text_panel(content: str, *, mode='markdown', **kwargs) -> Text: def get_text_panel(content: str, *, mode="markdown", **kwargs) -> Text:
return Text( return Text(content=content, mode=mode, **kwargs)
content=content,
mode=mode,
**kwargs
)
def get_stat_panel(title: str, def get_stat_panel(
dataSource: str, title: str,
stat_query: Query, dataSource: str,
repeat: Template = None, stat_query: Query,
alias: str = "", repeat: Template = None,
*, alias: str = "",
maxPerRow=0, *,
**kwargs): maxPerRow=0,
**kwargs,
):
new_kwargs = { new_kwargs = {
'alignment': 'center', "alignment": "center",
'colorMode': 'value', "colorMode": "value",
'graphMode': 'area', "graphMode": "area",
'reduceCalc': 'last', "reduceCalc": "last",
'orientation': 'auto', "orientation": "auto",
'transparent': True, "transparent": True,
} }
new_kwargs.update(kwargs) new_kwargs.update(kwargs)
if repeat: if repeat:
rep_args = ['h', repeat.name] rep_args = ["h", repeat.name]
if maxPerRow: if maxPerRow:
rep_args.append(maxPerRow) rep_args.append(maxPerRow)
new_kwargs.setdefault('repeat', Repeat(*rep_args)) new_kwargs.setdefault("repeat", Repeat(*rep_args))
return Stat( return Stat(
title=title, title=title,
dataSource=dataSource, dataSource=dataSource,
targets=[get_influx_target(str(stat_query), alias=alias)], targets=[get_influx_target(str(stat_query), alias=alias)],
thresholdType='percentage', thresholdType="percentage",
thresholds=[Threshold('green', 0, 0.0), Threshold('yellow', 1, 50.0), Threshold('red', 2, 80.0)], thresholds=[
** new_kwargs, Threshold("green", 0, 0.0),
Threshold("yellow", 1, 50.0),
Threshold("red", 2, 80.0),
],
**new_kwargs,
) )
def get_table_panel(panel_infos: PanelInfos, def get_table_panel(
data_source: str, panel_infos: PanelInfos,
query_list: list[Query], data_source: str,
*, query_list: List[Query],
result_format_list: list[str] = None, *,
alias_list: list[str] = None, result_format_list: List[str] = None,
transformations=[], alias_list: List[str] = None,
overrides=None, transformations=[],
**kwargs): overrides=None,
**kwargs,
):
if not alias_list: if not alias_list:
alias_list = [''] * len(query_list) alias_list = [""] * len(query_list)
if not result_format_list: if not result_format_list:
result_format_list = ['table'] * len(query_list) result_format_list = ["table"] * len(query_list)
targets = [get_influx_target(str(query), result_format=result_format, alias=alias) for query, result_format, alias in zip(query_list, result_format_list, alias_list)] targets = [
get_influx_target(str(query), result_format=result_format, alias=alias)
for query, result_format, alias in zip(
query_list, result_format_list, alias_list
)
]
new_kwargs = {**kwargs} new_kwargs = {**kwargs}
if panel_infos.absthreshold is not None: if panel_infos.absthreshold is not None:
new_kwargs.update({'thresholdType': 'absolute', new_kwargs.update(
'thresholds': [Threshold('green', 0, 0.0), {
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt'), ], "thresholdType": "absolute",
} "thresholds": [
) Threshold("green", 0, 0.0),
Threshold(
"red", index=1, value=float(panel_infos.absthreshold), op="lt"
),
],
}
)
return Table( return Table(
title=panel_infos.name, title=panel_infos.name,
...@@ -127,80 +172,106 @@ def get_table_panel(panel_infos: PanelInfos, ...@@ -127,80 +172,106 @@ def get_table_panel(panel_infos: PanelInfos,
unit=panel_infos.unit, unit=panel_infos.unit,
overrides=overrides, overrides=overrides,
**new_kwargs, **new_kwargs,
) )
def get_bar_chart_panel(panel_infos: PanelInfos, def get_bar_chart_panel(
data_source: str, panel_infos: PanelInfos,
query_list: list[Query], data_source: str,
*, query_list: List[Query],
result_format_list: list[str] = None, *,
alias_list: list[str] = None, result_format_list: List[str] = None,
transformations=[], alias_list: List[str] = None,
overrides=None, transformations=[],
**kwargs): overrides=None,
**kwargs,
):
if not alias_list: if not alias_list:
alias_list = [''] * len(query_list) alias_list = [""] * len(query_list)
if not result_format_list: if not result_format_list:
result_format_list = ['table'] * len(query_list) result_format_list = ["table"] * len(query_list)
targets = [get_influx_target(str(query), result_format=result_format, alias=alias) for query, result_format, alias in zip(query_list, result_format_list, alias_list)] targets = [
get_influx_target(str(query), result_format=result_format, alias=alias)
for query, result_format, alias in zip(
query_list, result_format_list, alias_list
)
]
new_kwargs = {**kwargs} new_kwargs = {**kwargs}
if panel_infos.absthreshold is not None: if panel_infos.absthreshold is not None:
new_kwargs.update({'thresholdType': 'absolute', new_kwargs.update(
'thresholds': [Threshold('green', 0, 0.0), {
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt'), ], "thresholdType": "absolute",
} "thresholds": [
) Threshold("green", 0, 0.0),
extraJson = {"fieldConfig": { Threshold(
"defaults": { "red", index=1, value=float(panel_infos.absthreshold), op="lt"
"fieldMinMax": True, ),
"max": 1, ],
"unit": panel_infos.unit }
)
extraJson = {
"fieldConfig": {
"defaults": {"fieldMinMax": True, "max": 1, "unit": panel_infos.unit}
} }
} }
}
return BarChart( return BarChart(
title=panel_infos.name, title=panel_infos.name,
dataSource=data_source, dataSource=data_source,
targets=targets, targets=targets,
transformations=transformations, transformations=transformations,
xTickLabelRotation=-45, xTickLabelRotation=-45,
extraJson=extraJson, extraJson=extraJson,
**new_kwargs, **new_kwargs,
) )
def get_pie_chart_panel(panel_infos: PanelInfos, def get_pie_chart_panel(
data_source: str, panel_infos: PanelInfos,
query_list: list[Query], data_source: str,
*, query_list: List[Query],
result_format_list: list[str] = None, *,
alias_list: list[str] = None, result_format_list: List[str] = None,
transformations=[], alias_list: List[str] = None,
overrides=[], transformations=[],
**kwargs): overrides=[],
**kwargs,
):
targets = [get_influx_target(str(query)) for query in query_list] targets = [get_influx_target(str(query)) for query in query_list]
new_kwargs = {**kwargs} new_kwargs = {**kwargs}
if panel_infos.absthreshold is not None: if panel_infos.absthreshold is not None:
if 'thresholdsStyleMode' not in new_kwargs: if "thresholdsStyleMode" not in new_kwargs:
new_kwargs.update({ new_kwargs.update(
'thresholdType': 'absolute', {
'thresholds': [Threshold('green', 0, 0.0), "thresholdType": "absolute",
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt')], "thresholds": [
'thresholdsStyleMode': 'line' Threshold("green", 0, 0.0),
}) Threshold(
"red",
index=1,
value=float(panel_infos.absthreshold),
op="lt",
),
],
"thresholdsStyleMode": "line",
}
)
else: else:
new_kwargs.update({ new_kwargs.update(
'thresholdType': 'absolute', {
'thresholds': [Threshold('green', 0, 0.0), "thresholdType": "absolute",
Threshold('red', index=1, value=float(panel_infos.absthreshold), op='lt')] "thresholds": [
}) Threshold("green", 0, 0.0),
Threshold(
"red",
index=1,
value=float(panel_infos.absthreshold),
op="lt",
),
],
}
)
return PieChartv2( return PieChartv2(
title=panel_infos.name, title=panel_infos.name,
dataSource=data_source, dataSource=data_source,
...@@ -209,5 +280,4 @@ def get_pie_chart_panel(panel_infos: PanelInfos, ...@@ -209,5 +280,4 @@ def get_pie_chart_panel(panel_infos: PanelInfos,
unit=panel_infos.unit, unit=panel_infos.unit,
overrides=overrides, overrides=overrides,
**new_kwargs, **new_kwargs,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment