Skip to content

Commit 1df1d23

Browse files
committed
Load testing
1 parent 2bfb7d6 commit 1df1d23

File tree

7 files changed

+62
-244
lines changed

7 files changed

+62
-244
lines changed

apps/load-test-service/scripts/continuous.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,18 @@ function testPassImageApi(passApiUrl, imageApiUrl) {
121121

122122
function testPassSummaryApi(baseUrl) {
123123
// Either use normal or slow endpoint
124-
if (Math.random() < 0.9) {
125-
// 90% of the time, use normal endpoint
124+
const endpointSelector = Math.random();
125+
126+
if (endpointSelector < 0.8) {
127+
// 80% of the time, use normal endpoint
126128
const summaryRes = http.get(`${baseUrl}/pass-summary`, {
127129
tags: { endpoint: 'get_pass_summary', mode: 'continuous' }
128130
});
129131

130132
check(summaryRes, {
131133
'status is 200': (r) => r.status === 200
132134
});
133-
} else {
135+
} else if (endpointSelector < 0.9) {
134136
// 10% of the time, use slow endpoint
135137
const slowRes = http.get(`${baseUrl}/pass-summary/slow`, {
136138
tags: { endpoint: 'get_pass_summary_slow', mode: 'continuous' }
@@ -139,6 +141,15 @@ function testPassSummaryApi(baseUrl) {
139141
check(slowRes, {
140142
'slow endpoint status is 200': (r) => r.status === 200
141143
});
144+
} else {
145+
// 10% of the time, use breaky endpoint
146+
const breakyRes = http.get(`${baseUrl}/pass-summary/breaky`, {
147+
tags: { endpoint: 'get_pass_summary_breaky', mode: 'continuous' }
148+
});
149+
150+
check(breakyRes, {
151+
'breaky endpoint status is 200': (r) => r.status === 200
152+
});
142153
}
143154
}
144155

apps/load-test-service/scripts/main.js

Lines changed: 0 additions & 209 deletions
This file was deleted.

apps/load-test-service/scripts/start.sh

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
#!/bin/bash
22
# Load test service start script
3-
# Provides easy switching between different test modes
43

54
# Set defaults
6-
SCRIPT_TYPE=${SCRIPT_TYPE:-main}
75
DURATION=${DURATION:-30s}
86

97
# Parse arguments
108
while [[ $# -gt 0 ]]; do
119
case $1 in
12-
--type)
13-
SCRIPT_TYPE="$2"
14-
shift 2
15-
;;
1610
--duration)
1711
DURATION="$2"
1812
shift 2
@@ -24,28 +18,9 @@ while [[ $# -gt 0 ]]; do
2418
esac
2519
done
2620

27-
# Map script type to actual k6 script
28-
case $SCRIPT_TYPE in
29-
main|default)
30-
K6_SCRIPT="/app/scripts/main.js"
31-
echo "Running standard test sequence (main.js)"
32-
;;
33-
continuous|background)
34-
K6_SCRIPT="/app/scripts/continuous.js"
35-
echo "Running continuous background load test (continuous.js)"
36-
;;
37-
*)
38-
# If a direct path is provided, use that
39-
if [[ -f "$SCRIPT_TYPE" ]]; then
40-
K6_SCRIPT="$SCRIPT_TYPE"
41-
echo "Running custom script: $SCRIPT_TYPE"
42-
else
43-
echo "Invalid script type: $SCRIPT_TYPE"
44-
echo "Valid options: main, continuous, or a path to a custom script"
45-
exit 1
46-
fi
47-
;;
48-
esac
21+
# Set the script path
22+
K6_SCRIPT="/app/scripts/continuous.js"
23+
echo "Running continuous background load test (continuous.js)"
4924

5025
# Override the duration if specified
5126
if [[ "$DURATION" != "30s" ]]; then

apps/pass-summary-api/run-with-agent.sh

100644100755
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
4+
export DD_TRACE_AGENT_PORT=8136
5+
quarkus build -DskipTests
6+
java -javaagent:/Users/scott.gerring/dd-java-agent.jar \
7+
-Ddd.profiling.enabled=true \
8+
-XX:FlightRecorderOptions=stackdepth=256 \
9+
-Ddd.logs.injection=true \
10+
-Ddd.service=my-app \
11+
-Ddd.env=staging \
12+
-Ddd.version=1.0 \
13+
-Ddd.trace.integration.vertx.enabled=false \
14+
-Ddd.trace.executors=org.jboss.threads.EnhancedQueueExecutor \
15+
-jar target/quarkus-app/quarkus-run.jar

apps/pass-summary-api/src/main/java/org/sdlcdemo/PassSummaryResource.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import jakarta.ws.rs.Path;
1010
import jakarta.ws.rs.Produces;
1111
import jakarta.ws.rs.core.MediaType;
12+
import jakarta.ws.rs.core.Response;
1213
import org.eclipse.microprofile.rest.client.inject.RestClient;
1314
import org.sdlcdemo.passapi.client.Pass;
1415
import org.sdlcdemo.passapi.client.PassApiService;
1516

1617
import java.util.HashMap;
1718
import java.util.Map;
19+
import java.util.Random;
1820
import java.util.Set;
1921

2022
/**
@@ -68,4 +70,30 @@ public Map<String, Object> passSummarySlow() {
6870

6971
return response;
7072
}
73+
74+
/**
75+
* This endpoint periodically fails with a 500 to simulate unreliable services.
76+
* When it succeeds, it returns pass summary data like the main /pass-summary endpoint.
77+
*/
78+
@GET
79+
@Path("/breaky")
80+
@Produces(MediaType.APPLICATION_JSON)
81+
public Response breakyEndpoint() {
82+
Random r = new Random();
83+
if (r.nextInt(3) == 0) { // ~33% chance of failure
84+
throw new RuntimeException("Something has gone terribly amiss");
85+
}
86+
87+
Set<Pass> allPasses = passApiService.all();
88+
int totalAscent = allPasses.stream()
89+
.mapToInt(Pass::ascent)
90+
.sum();
91+
92+
Map<String, Object> response = new HashMap<>();
93+
response.put("pass_count", allPasses.size());
94+
response.put("total_ascent", totalAscent);
95+
response.put("status", "ok");
96+
97+
return Response.ok(response).build();
98+
}
7199
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
quarkus.rest-client.pass-api-client.url=http://localhost:8081/
2-
1+
quarkus.rest-client.pass-api-client.url=http://pass-api:8080/
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
quarkus.rest-client.pass-api-client.url=http://pass-api:8080/
2-
1+
quarkus.rest-client.pass-api-client.url=http://pass-api:8080/

0 commit comments

Comments
 (0)