From c9fdec9d00a6e7de2c4912a9167b7f4a7d094235 Mon Sep 17 00:00:00 2001 From: Egon Ferri Date: Wed, 24 Jul 2024 12:58:15 +0200 Subject: [PATCH] fix: rename test_parameters to experiment_parameters to avoid pytest mess --- README.md | 4 +-- test/unit/test_main.py | 4 +-- vegeta_ss/__main__.py | 40 ++++++++++++++-------------- vegeta_ss/config/config.yaml.example | 2 +- vegeta_ss/models.py | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e5e216c..c918519 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ targets: url: "https://jsonplaceholder.typicode.com/posts/1" method: "GET" -test_parameters: +experiment_parameters: # Name used to help organizing and keeping different experiments results, which will be saved in results/experiments experiment_name: experiment_i # Maximum rate of request per second that will be tried @@ -156,7 +156,7 @@ cp vegeta_ss/config/config.yaml.example vegeta_ss/config/config.yaml ``` In this way you'll have a git-ignored config file (to avoid undesired url sharing). -In this configuration, you can define multiple target endpoints, each with its own characteristics such as the URL, HTTP method, request body file, and headers. The `test_parameters` section allows you to set global parameters for the load testing experiments, including the maximum request rate to be tested, experiment duration, latency bounds, and timeout settings. +In this configuration, you can define multiple target endpoints, each with its own characteristics such as the URL, HTTP method, request body file, and headers. The `experiment_parameters` section allows you to set global parameters for the load testing experiments, including the maximum request rate to be tested, experiment duration, latency bounds, and timeout settings. By adjusting these configuration settings, you can tailor the load testing tool to your specific use case, helping you assess the performance and reliability of your web services or APIs under various conditions. diff --git a/test/unit/test_main.py b/test/unit/test_main.py index 3ddb550..1ccb9dd 100644 --- a/test/unit/test_main.py +++ b/test/unit/test_main.py @@ -7,7 +7,7 @@ import pytest from vegeta_ss.__main__ import VegetaAttacker, evaluate_trial, save_results -from vegeta_ss.models import AttackReport, HTTPMethod, Target, TestParameters +from vegeta_ss.models import AttackReport, HTTPMethod, Target, ExperimentParameters from vegeta_ss.utils import format_time test_target_get = Target( @@ -49,7 +49,7 @@ test_target_trace = Target( name="test_target_trace", method=HTTPMethod("TRACE"), url="http://localhost" ) -test_target_params = TestParameters( +test_target_params = ExperimentParameters( experiment_name="test_experiment_name", min_req_sec=1, max_req_sec=100, diff --git a/vegeta_ss/__main__.py b/vegeta_ss/__main__.py index 31f6b0c..0159336 100644 --- a/vegeta_ss/__main__.py +++ b/vegeta_ss/__main__.py @@ -9,7 +9,7 @@ import pandas as pd from omegaconf import OmegaConf -from vegeta_ss.models import AttackReport, Target, TestParameters +from vegeta_ss.models import AttackReport, Target, ExperimentParameters from vegeta_ss.utils import format_time, logger results_dir = Path("results") @@ -165,20 +165,20 @@ def save_results(data: list, result_file_path: Path, result: AttackReport) -> No result_df.to_csv(result_file_path, index=False) -def run_load_test(target: Target, test_params: TestParameters) -> None: +def run_load_test(target: Target, experiment_params: ExperimentParameters) -> None: t0 = time.time() # Set up trial parameters - max_ub = int(test_params.max_latency_upper_bound_msec * 1e6) - avg_ub = int(test_params.avg_latency_upper_bound_msec * 1e6) + max_ub = int(experiment_params.max_latency_upper_bound_msec * 1e6) + avg_ub = int(experiment_params.avg_latency_upper_bound_msec * 1e6) rate, max_found, breaking_point = ( - test_params.max_req_sec, - max(0, test_params.min_req_sec - 1), - test_params.max_req_sec, + experiment_params.max_req_sec, + max(0, experiment_params.min_req_sec - 1), + experiment_params.max_req_sec, ) # Set up save results dir - base_dir = results_dir / test_params.experiment_name / target.name + base_dir = results_dir / experiment_params.experiment_name / target.name file_name = "results.csv" base_dir.mkdir(parents=True, exist_ok=True) @@ -188,15 +188,15 @@ def run_load_test(target: Target, test_params: TestParameters) -> None: logger.info(f"Performing trial with rate {rate}") with VegetaAttacker( target, - test_params.experiment_name, - test_params.save_plots, - test_params.print_histograms, - test_params.hist_bins, + experiment_params.experiment_name, + experiment_params.save_plots, + experiment_params.print_histograms, + experiment_params.hist_bins, ) as attacker: result = attacker.run_attack( rate, - test_params.experiment_duration_sec, - test_params.vegeta_timeout_sec, + experiment_params.experiment_duration_sec, + experiment_params.vegeta_timeout_sec, ) max_found, breaking_point = evaluate_trial( rate, @@ -205,7 +205,7 @@ def run_load_test(target: Target, test_params: TestParameters) -> None: avg_ub, max_found, breaking_point, - test_params.sleep_time_between_trials_sec, + experiment_params.sleep_time_between_trials_sec, ) data.append( [rate, f"{result.success:.2%}"] @@ -220,7 +220,7 @@ def run_load_test(target: Target, test_params: TestParameters) -> None: result_file_path = base_dir / file_name save_results(data, result_file_path, result) - if max_found < test_params.min_req_sec: + if max_found < experiment_params.min_req_sec: logger.info( f"Test completed in {round(time.time() - t0)}s. Unable to find a suitable rate. Try lowering min_req_seq parameter in config. Complete results at {result_file_path}" ) @@ -233,14 +233,14 @@ def run_load_test(target: Target, test_params: TestParameters) -> None: def main(cfg_path="vegeta_ss/config/config.yaml"): cfg = OmegaConf.load(cfg_path) - test_params = TestParameters(**cfg.test_parameters) - result_dir = results_dir / test_params.experiment_name + experiment_params = ExperimentParameters(**cfg.experiment_parameters) + result_dir = results_dir / experiment_params.experiment_name try: os.makedirs(result_dir) except FileExistsError: logger.warning( - f"Experiment folder with name {test_params.experiment_name} already existing, continuing will override. Continue? [Y/n]" + f"Experiment folder with name {experiment_params.experiment_name} already existing, continuing will override. Continue? [Y/n]" ) answer = input( " --------> send n if you want to stop the experiment and exit, any other key to continue: " @@ -255,7 +255,7 @@ def main(cfg_path="vegeta_ss/config/config.yaml"): logger.info( f"Starting load test for Target {target.name}, {i + 1} of {len(cfg.targets)} targets" ) - run_load_test(target, test_params) + run_load_test(target, experiment_params) if __name__ == "__main__": diff --git a/vegeta_ss/config/config.yaml.example b/vegeta_ss/config/config.yaml.example index f267135..3ce36c8 100644 --- a/vegeta_ss/config/config.yaml.example +++ b/vegeta_ss/config/config.yaml.example @@ -17,7 +17,7 @@ targets: url: "https://jsonplaceholder.typicode.com/posts/1" method: "GET" -test_parameters: +experiment_parameters: # Name used to help organizing and keeping different experiments results, which will be saved in results/experiments experiment_name: experiment_i # Maximum rate of request per second that will be tried diff --git a/vegeta_ss/models.py b/vegeta_ss/models.py index d43f237..c547f00 100644 --- a/vegeta_ss/models.py +++ b/vegeta_ss/models.py @@ -41,7 +41,7 @@ class Target(BaseModel): body_file: Optional[str] = Field(None, description="File path for the request body") -class TestParameters(BaseModel): +class ExperimentParameters(BaseModel): experiment_name: str min_req_sec: int max_req_sec: int