Skip to content

Commit 324734f

Browse files
committed
chore: add load test to example-axum-otlp to monitor memory leak
1 parent b0ead85 commit 324734f

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

.mise.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rust = '1.80.0'
1212
just = '1'
1313
grpcurl = '1.9'
1414
protoc = '29.2'
15+
k6 = '0.43'
1516
# grpc-health-probe = "*"
1617
# sccache = "0.5"
1718
"aqua:cargo-bins/cargo-binstall" = "1" # do not use cargo-binstall (it's a special name used by mise)

examples/axum-otlp/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ init-tracing-opentelemetry = { path = "../../init-tracing-opentelemetry", featur
1414
"otlp",
1515
"tracing_subscriber_ext",
1616
] }
17+
memory-stats = "1.1"
1718
opentelemetry = { workspace = true }
1819
opentelemetry-otlp = { workspace = true, default-features = false, features = [
1920
"reqwest-rustls",

examples/axum-otlp/k6-script.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import http from "k6/http";
2+
3+
export const options = {
4+
// A number specifying the number of VUs to run concurrently.
5+
vus: 10,
6+
// A string specifying the total duration of the test run.
7+
duration: "200s",
8+
9+
// The following section contains configuration options for execution of this
10+
// test script in Grafana Cloud.
11+
//
12+
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
13+
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
14+
//
15+
// cloud: {
16+
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
17+
// // By default tests are executed in default project.
18+
// projectID: "",
19+
// // The name of the test in the k6 Cloud UI.
20+
// // Test runs with the same name will be grouped.
21+
// name: "script.js"
22+
// },
23+
24+
// Uncomment this section to enable the use of Browser API in your tests.
25+
//
26+
// See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more
27+
// about using Browser API in your test scripts.
28+
//
29+
// scenarios: {
30+
// // The scenario name appears in the result summary, tags, and so on.
31+
// // You can give the scenario any name, as long as each name in the script is unique.
32+
// ui: {
33+
// // Executor is a mandatory parameter for browser-based tests.
34+
// // Shared iterations in this case tells k6 to reuse VUs to execute iterations.
35+
// //
36+
// // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types.
37+
// executor: 'shared-iterations',
38+
// options: {
39+
// browser: {
40+
// // This is a mandatory parameter that instructs k6 to launch and
41+
// // connect to a chromium-based browser, and use it to run UI-based
42+
// // tests.
43+
// type: 'chromium',
44+
// },
45+
// },
46+
// },
47+
// }
48+
};
49+
50+
// The function that defines VU logic.
51+
//
52+
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
53+
// about authoring k6 scripts.
54+
//
55+
export default function () {
56+
http.get("http://127.0.0.1:3003/");
57+
sleep(0.2);
58+
}

examples/axum-otlp/src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn app() -> Router {
2828
// build our application with a route
2929
Router::new()
3030
.route(
31-
"/proxy/:service/*path",
31+
"/proxy/{service}/{*path}",
3232
get(proxy_handler).post(proxy_handler),
3333
)
3434
.route("/", get(index)) // request processed inside span
@@ -40,7 +40,10 @@ fn app() -> Router {
4040
}
4141

4242
async fn health() -> impl IntoResponse {
43-
axum::Json(json!({ "status" : "UP" }))
43+
let memory_stats = memory_stats::memory_stats();
44+
axum::Json(
45+
json!({ "status" : "UP", "physical_mem": memory_stats.map(|s| s.physical_mem), "virtual_mem": memory_stats.map(|s| s.virtual_mem) }),
46+
)
4447
}
4548

4649
#[tracing::instrument]

justfile

+6
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ run_example_http_client:
126126

127127
run_example_load:
128128
cd examples/load; cargo run --release 2>/dev/null
129+
130+
run_example_axum-otlp_load:
131+
cd examples/axum-otlp; k6 run k6-script.js
132+
133+
run_example_axum-otlp_load_client:
134+
while true; do curl -S http://127.0.0.1:3003/health; echo ""; sleep 3; done

0 commit comments

Comments
 (0)