@@ -12,27 +12,63 @@ install-dev install-prod install-ci: _check_venv_active ## install app in develo
1212 @uv pip sync requirements/$(subst install-,,$@ ) .txt
1313
1414
15- # Define the files where user input will be saved
15+ # Configuration files and default values
1616LOCUST_CONFIG_FILE := .locust.conf
17- # Authentication credentials file
1817AUTH_CREDS_FILE := .auth-credentials.env
19- # Define host IP using get_my_ip function from common.Makefile
2018HOST_IP := $(get_my_ip )
2119
22- # Function to create Locust configuration file if it doesn't exist
20+ # Default Database settings
21+ PG_HOST := 127.0.0.1
22+ PG_PORT := 5432
23+ PG_USER := postgres
24+ PG_PASSWORD := password
25+
26+ # Default Grafana settings
27+ GRAFANA_URL := http://127.0.0.1:3000/
28+
29+ # Default Locust test settings
30+ DEFAULT_PROCESSES := 4
31+ DEFAULT_USERS := 10
32+ DEFAULT_SPAWN_RATE := 1
33+ DEFAULT_RUN_TIME := 10s
34+ DEFAULT_HOST := http://localhost:8080
35+
36+ # Function to generate Locust configuration file
37+ # Usage: $(call generate_locust_config,filename_suffix,processes,users,spawn_rate,run_time,description)
38+ define generate_locust_config
39+ @printf "$(YELLOW ) Setting up $(2 ) configuration...$(NC ) \n"
40+ @echo "# Locust configuration file - $(5)" > $(LOCUST_CONFIG_FILE)$(1); \
41+ echo "[locust]" >> $(LOCUST_CONFIG_FILE)$(1); \
42+ echo "locustfile = deployment_max_rps_test.py" >> $(LOCUST_CONFIG_FILE)$(1); \
43+ echo "headless = true" >> $(LOCUST_CONFIG_FILE)$(1); \
44+ if [ -f $(LOCUST_CONFIG_FILE) ]; then \
45+ echo "host = $$(grep "host = " $(LOCUST_CONFIG_FILE) | cut -d= -f2 | xargs)" >> $(LOCUST_CONFIG_FILE)$(1); \
46+ else \
47+ echo "host = $(DEFAULT_HOST)" >> $(LOCUST_CONFIG_FILE)$(1); \
48+ fi; \
49+ echo "users = $(3)" >> $(LOCUST_CONFIG_FILE)$(1); \
50+ echo "spawn-rate = $(4)" >> $(LOCUST_CONFIG_FILE)$(1); \
51+ echo "run-time = $(5)" >> $(LOCUST_CONFIG_FILE)$(1); \
52+ echo "processes = $(2)" >> $(LOCUST_CONFIG_FILE)$(1); \
53+ echo "" >> $(LOCUST_CONFIG_FILE)$(1); \
54+ echo "[logging]" >> $(LOCUST_CONFIG_FILE)$(1); \
55+ echo "level = INFO" >> $(LOCUST_CONFIG_FILE)$(1);
56+ endef
57+
58+ # Function to create or update Locust configuration with user input
2359define create_locust_config
2460 @if [ ! -f $(LOCUST_CONFIG_FILE ) ]; then \
2561 printf "$(YELLOW ) First time setup: Creating Locust configuration file$(NC ) \n"; \
26- read -p "Number of processes [4 ]: " processes; \
27- processes=$${processes:-4 }; \
28- read -p "Number of users [10 ]: " users; \
29- users=$${users:-10 }; \
30- read -p "Spawn rate [1 ]: " spawn_rate; \
31- spawn_rate=$${spawn_rate:-1 }; \
32- read -p "Run time [10s ]: " run_time; \
33- run_time=$${run_time:-10s }; \
34- read -p "Host to load test [http://localhost:8080 ]: " host; \
35- host=$${host:-http://localhost:8080 }; \
62+ read -p "Number of processes [$( DEFAULT_PROCESSES ) ]: " processes; \
63+ processes=$${processes:-$( DEFAULT_PROCESSES ) }; \
64+ read -p "Number of users [$( DEFAULT_USERS ) ]: " users; \
65+ users=$${users:-$( DEFAULT_USERS ) }; \
66+ read -p "Spawn rate [$( DEFAULT_SPAWN_RATE ) ]: " spawn_rate; \
67+ spawn_rate=$${spawn_rate:-$( DEFAULT_SPAWN_RATE ) }; \
68+ read -p "Run time [$( DEFAULT_RUN_TIME ) ]: " run_time; \
69+ run_time=$${run_time:-$( DEFAULT_RUN_TIME ) }; \
70+ read -p "Host to load test [$( DEFAULT_HOST ) ]: " host; \
71+ host=$${host:-$( DEFAULT_HOST ) }; \
3672 echo; \
3773 echo "# Locust configuration file - Autogenerated" > $(LOCUST_CONFIG_FILE); \
3874 echo "[locust]" >> $(LOCUST_CONFIG_FILE); \
@@ -52,37 +88,6 @@ define create_locust_config
5288 fi
5389endef
5490
55- # Function to create Locust configuration file without Grafana integration
56- define create_locust_config_no_grafana
57- @if [ ! -f $(LOCUST_CONFIG_FILE ) _no_grafana ]; then \
58- printf "$(YELLOW ) First time setup: Creating Locust configuration file (no Grafana)$(NC ) \n"; \
59- read -p "Number of processes [4]: " processes; \
60- processes=$${processes:-4}; \
61- read -p "Number of users [10]: " users; \
62- users=$${users:-10}; \
63- read -p "Spawn rate [1]: " spawn_rate; \
64- spawn_rate=$${spawn_rate:-1}; \
65- read -p "Run time [10s]: " run_time; \
66- run_time=$${run_time:-10s}; \
67- read -p "Host to load test [http://localhost:8080]: " host; \
68- host=$${host:-http://localhost:8080}; \
69- echo; \
70- echo "# Locust configuration file - Autogenerated (no Grafana)" > $(LOCUST_CONFIG_FILE)_no_grafana; \
71- echo "[locust]" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
72- echo "locustfile = deployment_max_rps_test.py" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
73- echo "headless = false" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
74- echo "host = $$host" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
75- echo "users = $$users" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
76- echo "spawn-rate = $$spawn_rate" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
77- echo "run-time = $$run_time" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
78- echo "processes = $$processes" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
79- echo "" >> $(LOCUST_CONFIG_FILE)_no_grafana; \
80- printf "$(GREEN)Locust configuration file (no Grafana) created. It won't be asked again.$(NC)\n"; \
81- else \
82- printf "$(GREEN)Using existing Locust configuration file $(LOCUST_CONFIG_FILE)_no_grafana$(NC)\n"; \
83- fi
84- endef
85-
8691# Function to prompt for credentials if they don't exist
8792define prompt_for_credentials
8893 @if [ ! -f $(AUTH_CREDS_FILE ) ]; then \
@@ -107,65 +112,62 @@ test-deployment-with-grafana: _check_venv_active ## runs deployment test with Gr
107112 @printf " $( YELLOW) Starting Locust with Grafana integration...$( NC) \n"
108113 @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
109114 locust --config $(LOCUST_CONFIG_FILE ) \
110- --grafana-url http://127.0.0.1:3000/ \
111- --pghost 127.0.0.1 \
112- --pgpassword=password \
113- --pguser=postgres \
114- --pgport=5432 \
115+ --grafana-url $( GRAFANA_URL ) \
116+ --pghost $( PG_HOST ) \
117+ --pgport $( PG_PORT ) \
118+ --pguser $( PG_USER ) \
119+ --pgpassword= $( PG_PASSWORD ) \
115120 --timescale
116121
117122test-deployment-no-grafana : _check_venv_active # # runs deployment test without Grafana integration
118123 @$(call prompt_for_credentials)
119- @$(call create_locust_config_no_grafana )
124+ @$(call create_locust_config )
120125 @printf " $( YELLOW) Starting Locust without Grafana integration...$( NC) \n"
121126 @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
122- locust --config $(LOCUST_CONFIG_FILE ) _no_grafana
127+ locust --config $(LOCUST_CONFIG_FILE ) \
128+ --headless
129+
130+ test-deployment-light : _check_venv_active # # runs a light load test with 5 users, 1 spawn rate and 10s runtime (with Grafana)
131+ @$(call prompt_for_credentials)
132+ @$(call generate_locust_config,_light,2,5,1,10s,Light Test)
133+ @printf " $( YELLOW) Starting Locust with light load (with Grafana)...$( NC) \n"
134+ @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
135+ locust --config $(LOCUST_CONFIG_FILE ) _light \
136+ --grafana-url $(GRAFANA_URL ) \
137+ --pghost $(PG_HOST ) \
138+ --pgport $(PG_PORT ) \
139+ --pguser $(PG_USER ) \
140+ --pgpassword=$(PG_PASSWORD ) \
141+ --timescale
123142
124- test-deployment-light : _check_venv_active # # runs a light load test with 5 users, 1 spawn rate and 10s runtime
143+ test-deployment-light-no-grafana : _check_venv_active # # runs a light load test with 5 users, 1 spawn rate and 10s runtime (without Grafana)
125144 @$(call prompt_for_credentials)
126- @printf " $( YELLOW) Creating light test configuration...$( NC) \n"
127- @echo " # Locust configuration file - Light Test" > $(LOCUST_CONFIG_FILE ) _light; \
128- echo " [locust]" >> $(LOCUST_CONFIG_FILE ) _light; \
129- echo " locustfile = deployment_max_rps_test.py" >> $(LOCUST_CONFIG_FILE ) _light; \
130- echo " headless = true" >> $(LOCUST_CONFIG_FILE ) _light; \
131- echo " host = $$ (grep " host = " $( LOCUST_CONFIG_FILE) | cut -d= -f2 | xargs)" >> $(LOCUST_CONFIG_FILE ) _light; \
132- echo " users = 5" >> $(LOCUST_CONFIG_FILE ) _light; \
133- echo " spawn-rate = 1" >> $(LOCUST_CONFIG_FILE ) _light; \
134- echo " run-time = 10s" >> $(LOCUST_CONFIG_FILE ) _light; \
135- echo " processes = 2" >> $(LOCUST_CONFIG_FILE ) _light; \
136- echo " " >> $(LOCUST_CONFIG_FILE ) _light; \
137- echo " [logging]" >> $(LOCUST_CONFIG_FILE ) _light; \
138- echo " level = INFO" >> $(LOCUST_CONFIG_FILE ) _light;
139- @printf " $( YELLOW) Starting Locust with light load...$( NC) \n"
145+ @$(call generate_locust_config,_light,2,5,1,10s,Light Test)
146+ @printf " $( YELLOW) Starting Locust with light load (without Grafana)...$( NC) \n"
140147 @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
141148 locust --config $(LOCUST_CONFIG_FILE ) _light \
142- --grafana-url http://$(HOST_IP ) :3000/ \
143- --pghost $(HOST_IP ) \
144- --pgpassword=password \
145- --pguser=postgres
149+ --headless
146150
147- test-deployment-heavy : _check_venv_active # # runs a heavy load test with 50 users, 5 spawn rate and 60s runtime
151+ test-deployment-heavy : _check_venv_active # # runs a heavy load test with 50 users, 5 spawn rate and 60s runtime (with Grafana)
148152 @$(call prompt_for_credentials)
149- @printf " $( YELLOW) Creating heavy test configuration...$( NC) \n"
150- @echo " # Locust configuration file - Heavy Test" > $(LOCUST_CONFIG_FILE ) _heavy; \
151- echo " [locust]" >> $(LOCUST_CONFIG_FILE ) _heavy; \
152- echo " locustfile = deployment_max_rps_test.py" >> $(LOCUST_CONFIG_FILE ) _heavy; \
153- echo " headless = true" >> $(LOCUST_CONFIG_FILE ) _heavy; \
154- echo " host = $$ (grep " host = " $( LOCUST_CONFIG_FILE) | cut -d= -f2 | xargs)" >> $(LOCUST_CONFIG_FILE ) _heavy; \
155- echo " users = 50" >> $(LOCUST_CONFIG_FILE ) _heavy; \
156- echo " spawn-rate = 5" >> $(LOCUST_CONFIG_FILE ) _heavy; \
157- echo " run-time = 60s" >> $(LOCUST_CONFIG_FILE ) _heavy; \
158- echo " processes = 4" >> $(LOCUST_CONFIG_FILE ) _heavy; \
159- echo " " >> $(LOCUST_CONFIG_FILE ) _heavy; \
160- echo " [logging]" >> $(LOCUST_CONFIG_FILE ) _heavy; \
161- echo " level = INFO" >> $(LOCUST_CONFIG_FILE ) _heavy;
162- @printf " $( YELLOW) Starting Locust with heavy load...$( NC) \n"
153+ @$(call generate_locust_config,_heavy,4,50,5,60s,Heavy Test)
154+ @printf " $( YELLOW) Starting Locust with heavy load (with Grafana)...$( NC) \n"
163155 @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
164156 locust --config $(LOCUST_CONFIG_FILE ) _heavy \
165- --grafana-url http://$(HOST_IP ) :3000/ \
166- --pghost $(HOST_IP ) \
167- --pgpassword=password \
168- --pguser=postgres
157+ --grafana-url $(GRAFANA_URL ) \
158+ --pghost $(PG_HOST ) \
159+ --pgport $(PG_PORT ) \
160+ --pguser $(PG_USER ) \
161+ --pgpassword=$(PG_PASSWORD ) \
162+ --timescale
163+
164+ test-deployment-heavy-no-grafana : _check_venv_active # # runs a heavy load test with 50 users, 5 spawn rate and 60s runtime (without Grafana)
165+ @$(call prompt_for_credentials)
166+ @$(call generate_locust_config,_heavy,4,50,5,60s,Heavy Test)
167+ @printf " $( YELLOW) Starting Locust with heavy load (without Grafana)...$( NC) \n"
168+ @export $$(cat $(AUTH_CREDS_FILE ) | xargs ) && \
169+ locust --config $(LOCUST_CONFIG_FILE ) _heavy \
170+ --headless
169171
170172clear-credentials : # # Clear the cached authentication credentials
171173 @if [ -f $( AUTH_CREDS_FILE) ]; then \
@@ -186,16 +188,16 @@ update-credentials: ## Update the cached authentication credentials
186188
187189update-locust-config : # # Update the Locust configuration file
188190 @printf " $( YELLOW) Updating Locust configuration:$( NC) \n"
189- @read -p " Number of processes [4 ]: " processes; \
190- processes=$$ {processes:-4 }; \
191- read -p " Number of users [10 ]: " users; \
192- users=$$ {users:-10 }; \
193- read -p " Spawn rate [1 ]: " spawn_rate; \
194- spawn_rate=$$ {spawn_rate:-1 }; \
195- read -p " Run time [10s ]: " run_time; \
196- run_time=$$ {run_time:-10s }; \
197- read -p " Host to load test [http://localhost:8080 ]: " host; \
198- host=$$ {host:-http://localhost:8080 }; \
191+ @read -p " Number of processes [$( DEFAULT_PROCESSES ) ]: " processes; \
192+ processes=$$ {processes:-$( DEFAULT_PROCESSES ) }; \
193+ read -p " Number of users [$( DEFAULT_USERS ) ]: " users; \
194+ users=$$ {users:-$( DEFAULT_USERS ) }; \
195+ read -p " Spawn rate [$( DEFAULT_SPAWN_RATE ) ]: " spawn_rate; \
196+ spawn_rate=$$ {spawn_rate:-$( DEFAULT_SPAWN_RATE ) }; \
197+ read -p " Run time [$( DEFAULT_RUN_TIME ) ]: " run_time; \
198+ run_time=$$ {run_time:-$( DEFAULT_RUN_TIME ) }; \
199+ read -p " Host to load test [$( DEFAULT_HOST ) ]: " host; \
200+ host=$$ {host:-$( DEFAULT_HOST ) }; \
199201 echo ; \
200202 echo " # Locust configuration file - Autogenerated" > $(LOCUST_CONFIG_FILE ) ; \
201203 echo " [locust]" >> $(LOCUST_CONFIG_FILE ) ; \
@@ -207,56 +209,17 @@ update-locust-config: ## Update the Locust configuration file
207209 echo " run-time = $$ run_time" >> $(LOCUST_CONFIG_FILE ) ; \
208210 echo " processes = $$ processes" >> $(LOCUST_CONFIG_FILE ) ; \
209211 echo " " >> $(LOCUST_CONFIG_FILE ) ; \
210- echo " [logging]" >> $(LOCUST_CONFIG_FILE ) ; \
211- echo " level = INFO" >> $(LOCUST_CONFIG_FILE ) ; \
212212 printf " $( GREEN) Locust configuration updated successfully.$( NC) \n"
213213
214- update-locust-config-no-grafana : # # Update the Locust configuration file (no Grafana)
215- @printf " $( YELLOW) Updating Locust configuration (no Grafana):$( NC) \n"
216- @read -p " Number of processes [4]: " processes; \
217- processes=$$ {processes:-4}; \
218- read -p " Number of users [10]: " users; \
219- users=$$ {users:-10}; \
220- read -p " Spawn rate [1]: " spawn_rate; \
221- spawn_rate=$$ {spawn_rate:-1}; \
222- read -p " Run time [10s]: " run_time; \
223- run_time=$$ {run_time:-10s}; \
224- read -p " Host to load test [http://localhost:8080]: " host; \
225- host=$$ {host:-http://localhost:8080}; \
226- echo ; \
227- echo " # Locust configuration file - Autogenerated (no Grafana)" > $(LOCUST_CONFIG_FILE ) _no_grafana; \
228- echo " [locust]" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
229- echo " locustfile = deployment_max_rps_test.py" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
230- echo " headless = true" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
231- echo " host = $$ host" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
232- echo " users = $$ users" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
233- echo " spawn-rate = $$ spawn_rate" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
234- echo " run-time = $$ run_time" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
235- echo " processes = $$ processes" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
236- echo " " >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
237- echo " [logging]" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
238- echo " level = INFO" >> $(LOCUST_CONFIG_FILE ) _no_grafana; \
239- printf " $( GREEN) Locust configuration (no Grafana) updated successfully.$( NC) \n"
240-
241- clear-locust-config : # # Clear the Locust configuration file
242- @if [ -f $( LOCUST_CONFIG_FILE) ]; then \
243- rm $(LOCUST_CONFIG_FILE ) ; \
244- printf " $( GREEN) Locust configuration file cleared.$( NC) \n" ; \
245- else \
246- printf " $( YELLOW) No Locust configuration file found.$( NC) \n" ; \
247- fi
248-
249- clear-locust-config-no-grafana : # # Clear the Locust configuration file (no Grafana)
250- @if [ -f $( LOCUST_CONFIG_FILE) _no_grafana ]; then \
251- rm $(LOCUST_CONFIG_FILE ) _no_grafana; \
252- printf " $( GREEN) Locust configuration file (no Grafana) cleared.$( NC) \n" ; \
253- else \
254- printf " $( YELLOW) No Locust configuration file (no Grafana) found.$( NC) \n" ; \
255- fi
256-
257- printf "$(GREEN)Grafana and PostgreSQL settings cleared.$(NC)\n"; \
258- else \
259- printf "$(YELLOW)No Grafana and PostgreSQL settings file found.$(NC)\n"; \
214+ clear-locust-config : # # Clear all Locust configuration files
215+ @for config_file in $(LOCUST_CONFIG_FILE ) $(LOCUST_CONFIG_FILE ) _light $(LOCUST_CONFIG_FILE ) _heavy; do \
216+ if [ -f $$ config_file ]; then \
217+ rm $$ config_file; \
218+ printf " $( GREEN) $$ config_file cleared.$( NC) \n" ; \
219+ fi ; \
220+ done
221+ @if [ ! -f $( LOCUST_CONFIG_FILE) ] && [ ! -f $( LOCUST_CONFIG_FILE) _light ] && [ ! -f $( LOCUST_CONFIG_FILE) _heavy ]; then \
222+ printf " $( YELLOW) No Locust configuration files found.$( NC) \n" ; \
260223 fi
261224
262225up :
0 commit comments