From e82943ea83ea31e8463839379885afa92b5ea1c1 Mon Sep 17 00:00:00 2001 From: David Butenhof Date: Wed, 12 Jul 2023 14:44:57 -0400 Subject: [PATCH] Identify benchmark type (#3495) PBENCH-1210 Right now we only support visualizing and comparing `uperf` benchmark data with Quisby. However as we expand that support within the server, the UI code will need to be able to identify the schema of the output data, which depends on the benchmark. As a simple solution, add a `"benchmark"` field to the response data which the client can read. --- lib/pbench/server/api/resources/datasets_compare.py | 9 +++++---- lib/pbench/server/api/resources/datasets_visualize.py | 9 +++++---- lib/pbench/test/functional/server/test_datasets.py | 2 ++ lib/pbench/test/unit/server/test_datasets_compare.py | 1 + lib/pbench/test/unit/server/test_datasets_visualize.py | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/pbench/server/api/resources/datasets_compare.py b/lib/pbench/server/api/resources/datasets_compare.py index dcb17cbafb..4261eabf57 100644 --- a/lib/pbench/server/api/resources/datasets_compare.py +++ b/lib/pbench/server/api/resources/datasets_compare.py @@ -109,11 +109,12 @@ def _get( ) from e stream_file[dataset.name] = file - get_quisby_data = QuisbyProcessing().compare_csv_to_json( + quisby_response = QuisbyProcessing().compare_csv_to_json( benchmark_type, InputType.STREAM, stream_file ) - if get_quisby_data["status"] != "success": + if quisby_response["status"] != "success": raise APIInternalError( - f"Quisby processing failure. Exception: {get_quisby_data['exception']}" + f"Quisby processing failure. Exception: {quisby_response['exception']}" ) - return jsonify(get_quisby_data) + quisby_response["benchmark"] = benchmark.lower() + return jsonify(quisby_response) diff --git a/lib/pbench/server/api/resources/datasets_visualize.py b/lib/pbench/server/api/resources/datasets_visualize.py index e7e505a55d..53f2b6be7f 100644 --- a/lib/pbench/server/api/resources/datasets_visualize.py +++ b/lib/pbench/server/api/resources/datasets_visualize.py @@ -76,12 +76,13 @@ def _get( except Exception as e: raise APIInternalError(str(e)) from e - get_quisby_data = QuisbyProcessing().extract_data( + quisby_response = QuisbyProcessing().extract_data( benchmark_type, dataset.name, InputType.STREAM, file ) - if get_quisby_data["status"] != "success": + if quisby_response["status"] != "success": raise APIInternalError( - f"Quisby processing failure. Exception: {get_quisby_data['exception']}" + f"Quisby processing failure. Exception: {quisby_response['exception']}" ) - return jsonify(get_quisby_data) + quisby_response["benchmark"] = benchmark.lower() + return jsonify(quisby_response) diff --git a/lib/pbench/test/functional/server/test_datasets.py b/lib/pbench/test/functional/server/test_datasets.py index b113fbf159..76344e797b 100644 --- a/lib/pbench/test/functional/server/test_datasets.py +++ b/lib/pbench/test/functional/server/test_datasets.py @@ -610,6 +610,7 @@ def test_visualize(self, server_client: PbenchServerClient, login_user): ), f"VISUALIZE {dataset.name} failed {response.status_code}:{response.json()['message']}" json = response.json() assert json["status"] == "success" + assert json["benchmark"] == "uperf" assert "csv_data" in json assert json["json_data"]["dataset_name"] == dataset.name assert isinstance(json["json_data"]["data"], list) @@ -643,6 +644,7 @@ def test_compare(self, server_client: PbenchServerClient, login_user): response.ok ), f"COMPARE {candidates[:2]} failed {response.status_code}:{json['message']}" assert json["status"] == "success" + assert json["benchmark"] == "uperf" assert isinstance(json["json_data"]["data"], list) @pytest.mark.dependency(name="inventory", depends=["upload"], scope="session") diff --git a/lib/pbench/test/unit/server/test_datasets_compare.py b/lib/pbench/test/unit/server/test_datasets_compare.py index fb6cda9458..6475aed113 100644 --- a/lib/pbench/test/unit/server/test_datasets_compare.py +++ b/lib/pbench/test/unit/server/test_datasets_compare.py @@ -143,6 +143,7 @@ def mock_get_inventory(_self, _dataset: str, _path: str) -> dict[str, Any]: response = query_get_as(datasets, user, exp_status) if exp_status == HTTPStatus.OK: assert response.json["status"] == "success" + assert response.json["benchmark"] == "uperf" assert response.json["json_data"] == "quisby_data" else: assert response.json["message"] == exp_message diff --git a/lib/pbench/test/unit/server/test_datasets_visualize.py b/lib/pbench/test/unit/server/test_datasets_visualize.py index 4e5554d647..d39837f8a3 100644 --- a/lib/pbench/test/unit/server/test_datasets_visualize.py +++ b/lib/pbench/test/unit/server/test_datasets_visualize.py @@ -96,6 +96,7 @@ def mock_extract_data(self, test_name, dataset_name, input_type, data) -> JSON: response = query_get_as("uperf_1", "test", HTTPStatus.OK) assert response.json["status"] == "success" + assert response.json["benchmark"] == "uperf" assert response.json["json_data"] == "quisby_data" def test_unsuccessful_get_with_incorrect_data(self, query_get_as, monkeypatch):