Skip to content

Commit

Permalink
fix: rename test_parameters to experiment_parameters to avoid pytest …
Browse files Browse the repository at this point in the history
…mess
  • Loading branch information
Egon Ferri committed Jul 24, 2024
1 parent 9580e4b commit c9fdec9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 20 additions & 20 deletions vegeta_ss/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand All @@ -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%}"]
Expand All @@ -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}"
)
Expand All @@ -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: "
Expand All @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion vegeta_ss/config/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vegeta_ss/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9fdec9

Please sign in to comment.