diff --git a/dashboards/dashboard_base.py b/dashboards/dashboard_base.py index ccbc81c197a6a187a144a2b5f15ea9549c215fe7..80d161ef07342491c6f61408c3733d3728113370 100644 --- a/dashboards/dashboard_base.py +++ b/dashboards/dashboard_base.py @@ -12,6 +12,7 @@ from grafanalib.influxdb import InfluxDBTarget from dashboards.annotations import Annotation from dashboards.influx_queries import Query +from dashboards.legends import AxisLabel, Units def get_influx_target(target_query: str, result_format: str = 'time_series', alias: str = "", **kwargs) -> InfluxDBTarget: @@ -78,11 +79,11 @@ def build_row_repeat_dashboard( dataSource: str, measurment_name: str, panel_query: Query, - unit: str, - axisLabel: str, + unit: Units, + axisLabel: AxisLabel, other_vars: List[Template] = None, annotations: Annotations = Annotations(), - alias: str = None, + alias: str = '', ) -> Dashboard: """Build a Dashboard that takes one query and repeats that with 2 variables.""" time_series_kwargs = { @@ -90,8 +91,8 @@ def build_row_repeat_dashboard( 'dataSource': dataSource, 'targets': [get_influx_target(str(panel_query), alias=alias)], 'repeat': Repeat('h', panel_repeat_var.name), - 'unit': unit, - 'axisLabel': axisLabel, + 'unit': unit.value, + 'axisLabel': axisLabel.value, 'pointSize': 9, } if other_vars is None: diff --git a/dashboards/dashboard_fe2ti.py b/dashboards/dashboard_fe2ti.py index 366e88f03a99d82e8ce25cce207a8d8bec80b9d3..2cdafaedd2a187a26e3019986da4ebe36943f22b 100644 --- a/dashboards/dashboard_fe2ti.py +++ b/dashboards/dashboard_fe2ti.py @@ -12,6 +12,8 @@ from dashboards.variables import get_dashboard_variable, Filter from dashboards.influx_queries import join_variable_and from dashboards.legends import Units +from dashboards.influx_queries import Query + description_markdown = r""" - Linestyle indicates the compiler: @@ -39,6 +41,9 @@ INTEL_LINESTYLE = "solid" GCC_LINESTYLE = "dashed" +def is_regex(name): + return name[0] == "/" and name[-1] == "/" + def dashboard_fe2ti(): data_source = "fe2ti" measurment_name = "fe2ti" diff --git a/dashboards/dashboard_pystencils.py b/dashboards/dashboard_pystencils.py index 9dd297f6b4e7479e6a4ca1d860635e522dccc74e..c2990303655cd626cd60a18245244cc686862d21 100644 --- a/dashboards/dashboard_pystencils.py +++ b/dashboards/dashboard_pystencils.py @@ -14,11 +14,15 @@ from dashboards.legends import Units import cbutil.ncu_keys as ncu_keys import cbutil.likwid_keys as likwid_keys +from dashboards.influx_queries import Query INTEL_LINESTYLE = "solid" GCC_LINESTYLE = "dashed" +def is_regex(name): + return name[0] == "/" and name[-1] == "/" + def dashboard_pystencils_cpu(): data_source = "pystencils" row_repeat = "host" diff --git a/dashboards/dashboard_walberla.py b/dashboards/dashboard_walberla.py index 433eb1033dacabd60960e58629b2f889f9a85136..15358a910eb798876b4ce245b1c84d834287b5ca 100644 --- a/dashboards/dashboard_walberla.py +++ b/dashboards/dashboard_walberla.py @@ -351,6 +351,7 @@ def dashboard_uniformgridcpu_relativeperformance(): ] + [ get_variable_condition_without_regex(filters[i].name) for i in [4] ], "AND" + , include_time_filter=True ) where0B2 = get_variable_condition_with_tag(filters[0].name) where1A = get_variable_condition_with_tag(filters[0].name) @@ -364,6 +365,7 @@ def dashboard_uniformgridcpu_relativeperformance(): ] + [ get_variable_condition_without_regex(filters[i].name) for i in [4] ], "AND" + , include_time_filter=True ) where2B2 = get_variable_condition_with_tag(filters[0].name) @@ -754,7 +756,8 @@ def dashboard_percolationgpu(): PanelInfos(r"/.*_average/ useParticles=$useParticles", Units.seconds), ] - whereVariable = join_conditions([get_variable_condition_unbounded(filters[0].name)], "AND") + whereVariable = join_conditions([get_variable_condition_unbounded(filters[0].name)], "AND", + include_time_filter=True) groupVariable = [filters[0].name] filter_vars = [ @@ -783,7 +786,8 @@ def dashboard_percolationgpu(): ] - where = join_conditions([get_variable_condition_with_tag(filters[i].name) for i in range(3)], "AND") + where = join_conditions([get_variable_condition_with_tag(filters[i].name) for i in range(3)], "AND", + include_time_filter=True) group_by_elements01 = ["GPU", "branch", "fluidCells", "host", "numParticles", "useParticles", "communicationHidingXWidth", "communicationHidingYWidth", "communicationHidingZWidth", "cores", "numXCellsPerBlock", "numYBlocks", "particleDiameter", "sendDirectlyFromGPU"] group_by01 = [get_variable_tag(i) for i in group_by_elements01] diff --git a/dashboards/influx_queries.py b/dashboards/influx_queries.py index 59d90be43cd0243dc2c066f937ef10a83e649a4c..76b054feae453285a5b5c1b39480e8acb8ec21bb 100644 --- a/dashboards/influx_queries.py +++ b/dashboards/influx_queries.py @@ -142,7 +142,7 @@ def get_variable_tag(variable_name: str, *, tag_key: str = None) -> str: return f'"{clean_lhs}"::tag' -def join_conditions(conditions: List[str], operators: Union[List[str], str], include_time_filter: bool = True): +def join_conditions(conditions: List[str], operators: Union[List[str], str], include_time_filter: bool = False): ops = operators if isinstance(operators, str): ops = repeat(operators, len(conditions) - 1) @@ -162,7 +162,7 @@ def join_conditions(conditions: List[str], operators: Union[List[str], str], inc return ret -def join_variable_and(variable_names: List[str], include_time_filter: bool = True) -> str: +def join_variable_and(variable_names: List[str], include_time_filter: bool = False) -> str: return join_conditions( [get_variable_condition(name) for name in variable_names], "AND", include_time_filter ) diff --git a/tests/test_dashboard_creation.py b/tests/test_dashboard_creation.py index 6b3f5ad5c348d8ce38b7d84779f7844e52271535..f10735a628df98a7d94613944812f86f5f3c9d29 100644 --- a/tests/test_dashboard_creation.py +++ b/tests/test_dashboard_creation.py @@ -85,6 +85,8 @@ def test_build_dashboard(): def test_dashboard_fe2ti(): + print(dashboard_fe2ti()) + print("++++++++++++++++++1++++++++++++++++++") dashboard_fe2ti() diff --git a/tests/test_dashboard_upload.py b/tests/test_dashboard_upload.py index 2caafef551e5598433832eed6e20e33bc6621ff0..bcd316b7f9e8ca3dfb983509bf07986532154498 100644 --- a/tests/test_dashboard_upload.py +++ b/tests/test_dashboard_upload.py @@ -1,22 +1,55 @@ -# Test case using pytest import pytest -from dashboards.upload import load_config_from_env from unittest.mock import patch -import os - -def test_load_config_from_env(): - # Case 1: Test if function raises exception for missing GRAFANA_API_KEY - with pytest.raises(ValueError) as e: - load_config_from_env(env_path=".env") - assert str(e.value) == "GRAFANA_API_KEY is None or not defined in the .env file" - - # Case 2: Test if function raises exception for missing GRAFANA_SERVER - with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key"}): - with pytest.raises(ValueError) as e: - load_config_from_env(env_path=".env") - assert str(e.value) == "GRAFANA_SERVER is None or not defined in the .env file" - - # Case 3: Test if function returns expected values when both variables are defined - with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key", "GRAFANA_SERVER": "server_url"}): - result = load_config_from_env(env_path=".env") - assert result == ("server_url", "api_key") \ No newline at end of file +from dashboards.upload import load_config_from_env # Replace with the correct path to your function + +# Successful test +@patch('dotenv.load_dotenv') +@patch('os.getenv') +def test_load_config_success(mock_getenv, mock_load_dotenv): + # Setup mock return values + mock_getenv.side_effect = lambda key: { + 'GRAFANA_API_KEY': 'test_api_key', + 'GRAFANA_SERVER': 'http://test.server' + }.get(key) + + # Test the function + grafana_server, grafana_api_key = load_config_from_env() + + # Assert the expected values + assert grafana_server == 'http://test.server' + assert grafana_api_key == 'test_api_key' + mock_load_dotenv.assert_called_once_with('.env') + +# Test when GRAFANA_API_KEY is missing +@patch('dotenv.load_dotenv') +@patch('os.getenv') +def test_missing_grafana_api_key(mock_getenv, mock_load_dotenv): + # Setup mock return values with missing GRAFANA_API_KEY + mock_getenv.side_effect = lambda key: { + 'GRAFANA_SERVER': 'http://test.server' + }.get(key) + + # Test that ValueError is raised for missing GRAFANA_API_KEY + with pytest.raises(ValueError, match="GRAFANA_API_KEY is None or not defined in the .env file"): + load_config_from_env() + +# Test when GRAFANA_SERVER is missing +@patch('dotenv.load_dotenv') +@patch('os.getenv') +def test_missing_grafana_server(mock_getenv, mock_load_dotenv): + # Setup mock return values with missing GRAFANA_SERVER + mock_getenv.side_effect = lambda key: { + 'GRAFANA_API_KEY': 'test_api_key' + }.get(key) + + # Test that ValueError is raised for missing GRAFANA_SERVER + with pytest.raises(ValueError, match="GRAFANA_SERVER is None or not defined in the .env file"): + load_config_from_env() + +# Test when the .env file does not exist +@patch('dotenv.load_dotenv') +def test_no_env_file(mock_load_dotenv): + # Simulate that the .env file does not exist + with patch('os.path.exists', return_value=False): + with pytest.raises(ValueError, match="GRAFANA_API_KEY is None or not defined in the .env file"): + load_config_from_env() diff --git a/tests/test_influx_queries.py b/tests/test_influx_queries.py index 7864f3eb497df0a806ea72050dc8f2f6174a621f..c29eefbfcfee38021048d4dbfb4567a6e38608d0 100644 --- a/tests/test_influx_queries.py +++ b/tests/test_influx_queries.py @@ -12,7 +12,7 @@ def test_query(): q = Query( select_="mlupsPerProcess", from_="UniformGridGPU", - where_='"host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/', + where_='"host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/ AND $timeFilter ', group_by=[ "blocks_0", "blocks_1", @@ -32,7 +32,7 @@ def test_query(): q1 = ( 'SELECT "mlupsPerProcess" ' 'FROM "UniformGridGPU" ' - 'WHERE ("host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/) AND $timeFilter ' + 'WHERE ("host" =~ /^${host:regex}$/ AND "collisionSetup" =~ /^${collisionSetup:regex}$/ AND $timeFilter ) ' 'GROUP BY "blocks_0", "blocks_1", "blocks_2", ' '"cellsPerBlock_0", "cellsPerBlock_1", "cellsPerBlock_2", ' '"gpuBlockSize_0", "gpuBlockSize_1", "gpuBlockSize_2", '