Skip to content

Commit 26fd4ab

Browse files
authored
Merge pull request #5 from Healy-Hyperspatial/custom-config
Add custom config
2 parents db9336a + 41c3b9c commit 26fd4ab

File tree

5 files changed

+96
-35
lines changed

5 files changed

+96
-35
lines changed

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
### Fixed
1616

1717

18+
19+
## [v0.2.0]
20+
21+
### Added
22+
23+
- Taurus config options in cli. [#5](https://github.com/Healy-Hyperspatial/stac-api-load-balancing/pull/5)
24+
25+
### Changed
26+
27+
### Fixed
28+
29+
1830
## [v0.1.1]
1931

2032
### Added
@@ -35,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3547
- First release
3648

3749

38-
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.1...main>
50+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.2.0...main>
51+
[v0.2.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.1...v0.2.0>
3952
[v0.1.1]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.0...v0.1.1>
4053
[v0.1.0]: <https://github.com/stac-utils/stac-fastapi-elasticsearch/tree/v0.1.0>

README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@ Usage: stac-api-load-balancing [OPTIONS]
2222
This tool facilitates data ingestion, Locust load testing, and Taurus
2323
performance testing against a specified STAC API endpoint.
2424
25-
Args:
26-
ingest (bool): If true, ingests sample data into the specified STAC API.
27-
locust (bool): If true, conducts Locust load testing against the STAC API.
28-
taurus (bool): If true, performs Taurus performance testing against the STAC API.
29-
api_address (str): The URL of the STAC API for testing.
25+
Args:
26+
ingest (bool): If True, ingest sample data into the specified STAC API.
27+
locust (bool): If True, execute Locust load tests against the
28+
specified STAC API.
29+
taurus (bool): If True, perform Taurus performance
30+
testing with custom settings against the specified STAC API.
31+
concurrency (int): Specifies the number of concurrent users for Taurus testing. Default is 10.
32+
ramp_up (str): Specifies the ramp-up period for Taurus testing, in Taurus notation (e.g., '1m' for 1 minute). Default is '1m'.
33+
iterations (int): Specifies the number of iterations each virtual user will
34+
execute in Taurus testing. Default is 100.
35+
api_address (str): The base URL of the STAC API to be tested.
3036
3137
Options:
32-
--version Show the version and exit.
33-
-a, --api-address TEXT Specify the STAC API URL to test against.
34-
-t, --taurus Run the Taurus wrapper for performance testing
35-
against the STAC API.
36-
-l, --locust Run Locust load tests against the STAC API.
37-
-i, --ingest Ingest sample data into the STAC API.
38-
--help Show this message and exit.
38+
-i, --ingest Ingest sample data into the STAC API.
39+
-l, --locust Run Locust load tests against the STAC API.
40+
-t, --taurus Run the Taurus wrapper for performance testing
41+
against the STAC API.
42+
-c, --concurrency INTEGER Number of concurrent users for Taurus option.
43+
-r, --ramp-up TEXT Ramp-up time for Taurus option.
44+
-n, --iterations INTEGER Number of iterations for Taurus option.
45+
-a, --api-address TEXT Specify the STAC API URL to test against.
46+
--version Show the version and exit.
47+
--help Show this message and exit.
3948
```
4049

4150
## Ingest test data - http://localhost:8084 is just an example url

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ services:
3838
ports:
3939
- "8083:8082"
4040
volumes:
41-
- ./stac_fastapi:/app/stac_fastapi
4241
- ./scripts:/app/scripts
4342
depends_on:
4443
- pgstac

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""stac-api-load-balancing setup.py."""
22
from setuptools import setup
33

4-
__version__ = "0.1.1"
4+
__version__ = "0.2.0"
55

66
with open("README.md", "r") as fh:
77
long_description = fh.read()
@@ -20,7 +20,6 @@
2020
"bzt",
2121
],
2222
packages=["stac_api_load_balancing"],
23-
# package_data={"stac_api_load_balancing": ["config_files/*", "data_loader/*", "data_loader/setup_data/*"]},
2423
entry_points={
2524
"console_scripts": ["stac-api-load-balancing=stac_api_load_balancing.cli:main"]
2625
},

stac_api_load_balancing/cli.py

+60-19
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@
1010
from .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

101142
if __name__ == "__main__":

0 commit comments

Comments
 (0)