1010from .data_loader import data_loader
1111
1212
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+ """
1526 template_path = pkg_resources .resource_filename (
1627 __name__ , "config_files/taurus_locust.yml"
1728 )
18- print ("template path: " , template_path )
1929 locustfile_path = pkg_resources .resource_filename (
2030 __name__ , "config_files/locustfile.py"
2131 )
@@ -28,6 +38,9 @@ def generate_taurus_config(api_url):
2838 config = yaml .safe_load (file )
2939
3040 # 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
3144 config ["scenarios" ]["default" ]["script" ] = locustfile_path
3245 config ["scenarios" ]["default" ]["default-address" ] = api_url
3346
@@ -40,6 +53,7 @@ def generate_taurus_config(api_url):
4053 return None
4154
4255
56+ @click .command ()
4357@click .option (
4458 "-i" , "--ingest" , is_flag = True , help = "Ingest sample data into the STAC API."
4559)
@@ -52,50 +66,77 @@ def generate_taurus_config(api_url):
5266 is_flag = True ,
5367 help = "Run the Taurus wrapper for performance testing against the STAC API." ,
5468)
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
5584@click .option (
5685 "-a" ,
5786 "--api-address" ,
5887 default = "http://localhost:8080" ,
5988 help = "Specify the STAC API URL to test against." ,
6089)
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+ ):
64100 """
65101 Entry point for the stac-api-load-balancing CLI tool.
66102
67103 This tool facilitates data ingestion, Locust load testing, and Taurus performance testing
68104 against a specified STAC API endpoint.
69105
70106 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.
75114 """
76115 os .environ ["LOCUST_HOST" ] = api_address
77116
78117 if ingest :
118+ # Load data into the STAC API
79119 data_loader .load_items (stac_api_base_url = api_address )
80120 elif locust :
121+ # Execute Locust load tests
122+ locust_file_path = pkg_resources .resource_filename (
123+ __name__ , "config_files/locustfile.py"
124+ )
81125 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 ],
89127 check = True ,
90128 )
91129 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+ )
93134 if config_file_path :
94135 try :
95136 subprocess .run (["bzt" , config_file_path ], check = True )
96137 finally :
97138 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
99140
100141
101142if __name__ == "__main__" :
0 commit comments