10
10
from .data_loader import data_loader
11
11
12
12
13
- def generate_taurus_config (api_url ):
14
- """Generate a Taurus configuration file with the specified API URL."""
13
+ def generate_taurus_config (api_url : str , concurrency : int , ramp_up , iterations ) -> str :
14
+ """
15
+ Generate a custom Taurus configuration file based on the specified settings.
16
+
17
+ Args:
18
+ api_url (str): The base URL for the STAC API to be tested.
19
+ concurrency (int): The number of concurrent users to simulate.
20
+ ramp_up (str): The duration over which to ramp up the load test.
21
+ iterations (int): The total number of iterations to perform.
22
+
23
+ Returns:
24
+ str: The path to the generated Taurus configuration file.
25
+ """
15
26
template_path = pkg_resources .resource_filename (
16
27
__name__ , "config_files/taurus_locust.yml"
17
28
)
18
- print ("template path: " , template_path )
19
29
locustfile_path = pkg_resources .resource_filename (
20
30
__name__ , "config_files/locustfile.py"
21
31
)
@@ -28,6 +38,9 @@ def generate_taurus_config(api_url):
28
38
config = yaml .safe_load (file )
29
39
30
40
# Setting the script path directly to where `locustfile.py` is expected to be within the package
41
+ config ["execution" ][0 ]["concurrency" ] = concurrency
42
+ config ["execution" ][0 ]["ramp-up" ] = ramp_up
43
+ config ["execution" ][0 ]["iterations" ] = iterations
31
44
config ["scenarios" ]["default" ]["script" ] = locustfile_path
32
45
config ["scenarios" ]["default" ]["default-address" ] = api_url
33
46
@@ -40,6 +53,7 @@ def generate_taurus_config(api_url):
40
53
return None
41
54
42
55
56
+ @click .command ()
43
57
@click .option (
44
58
"-i" , "--ingest" , is_flag = True , help = "Ingest sample data into the STAC API."
45
59
)
@@ -52,50 +66,77 @@ def generate_taurus_config(api_url):
52
66
is_flag = True ,
53
67
help = "Run the Taurus wrapper for performance testing against the STAC API." ,
54
68
)
69
+ @click .option (
70
+ "-c" ,
71
+ "--concurrency" ,
72
+ default = 10 ,
73
+ help = "Number of concurrent users for Taurus option." ,
74
+ type = int ,
75
+ )
76
+ @click .option ("-r" , "--ramp-up" , default = "1m" , help = "Ramp-up time for Taurus option." )
77
+ @click .option (
78
+ "-n" ,
79
+ "--iterations" ,
80
+ default = 100 ,
81
+ help = "Number of iterations for Taurus option." ,
82
+ type = int ,
83
+ ) # Changed the flag to -n to avoid conflict
55
84
@click .option (
56
85
"-a" ,
57
86
"--api-address" ,
58
87
default = "http://localhost:8080" ,
59
88
help = "Specify the STAC API URL to test against." ,
60
89
)
61
- @click .command ()
62
- @click .version_option (version = "0.1.0" )
63
- def main (ingest , locust , taurus , api_address ):
90
+ @click .version_option (version = "0.2.0" )
91
+ def main (
92
+ ingest : bool ,
93
+ locust : bool ,
94
+ taurus : bool ,
95
+ api_address : str ,
96
+ concurrency : int ,
97
+ ramp_up : str ,
98
+ iterations : int ,
99
+ ):
64
100
"""
65
101
Entry point for the stac-api-load-balancing CLI tool.
66
102
67
103
This tool facilitates data ingestion, Locust load testing, and Taurus performance testing
68
104
against a specified STAC API endpoint.
69
105
70
106
Args:
71
- ingest (bool): If true, ingests sample data into the specified STAC API.
72
- locust (bool): If true, conducts Locust load testing against the STAC API.
73
- taurus (bool): If true, performs Taurus performance testing against the STAC API.
74
- api_address (str): The URL of the STAC API for testing.
107
+ ingest (bool): If True, ingest sample data into the specified STAC API.
108
+ locust (bool): If True, execute Locust load tests against the specified STAC API.
109
+ taurus (bool): If True, perform Taurus performance testing with custom settings against the specified STAC API.
110
+ concurrency (int): Specifies the number of concurrent users for Taurus testing. Default is 10.
111
+ ramp_up (str): Specifies the ramp-up period for Taurus testing, in Taurus notation (e.g., '1m' for 1 minute). Default is '1m'.
112
+ iterations (int): Specifies the number of iterations each virtual user will execute in Taurus testing. Default is 100.
113
+ api_address (str): The base URL of the STAC API to be tested.
75
114
"""
76
115
os .environ ["LOCUST_HOST" ] = api_address
77
116
78
117
if ingest :
118
+ # Load data into the STAC API
79
119
data_loader .load_items (stac_api_base_url = api_address )
80
120
elif locust :
121
+ # Execute Locust load tests
122
+ locust_file_path = pkg_resources .resource_filename (
123
+ __name__ , "config_files/locustfile.py"
124
+ )
81
125
subprocess .run (
82
- [
83
- "locust" ,
84
- "--locustfile" ,
85
- pkg_resources .resource_filename (__name__ , "config_files/locustfile.py" ),
86
- "--host" ,
87
- api_address ,
88
- ],
126
+ ["locust" , "--locustfile" , locust_file_path , "--host" , api_address ],
89
127
check = True ,
90
128
)
91
129
elif taurus :
92
- config_file_path = generate_taurus_config (api_address )
130
+ # Generate and run a custom Taurus configuration for performance testing
131
+ config_file_path = generate_taurus_config (
132
+ api_address , concurrency , ramp_up , iterations
133
+ )
93
134
if config_file_path :
94
135
try :
95
136
subprocess .run (["bzt" , config_file_path ], check = True )
96
137
finally :
97
138
if os .path .exists (config_file_path ):
98
- os .remove (config_file_path ) # Cleanup the temporary config file
139
+ os .remove (config_file_path ) # Cleanup after running
99
140
100
141
101
142
if __name__ == "__main__" :
0 commit comments