Skip to content

Commit

Permalink
chore: add load test to example-axum-otlp to monitor memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Jan 2, 2025
1 parent b0ead85 commit 324734f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust = '1.80.0'
just = '1'
grpcurl = '1.9'
protoc = '29.2'
k6 = '0.43'
# grpc-health-probe = "*"
# sccache = "0.5"
"aqua:cargo-bins/cargo-binstall" = "1" # do not use cargo-binstall (it's a special name used by mise)
1 change: 1 addition & 0 deletions examples/axum-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ init-tracing-opentelemetry = { path = "../../init-tracing-opentelemetry", featur
"otlp",
"tracing_subscriber_ext",
] }
memory-stats = "1.1"
opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true, default-features = false, features = [
"reqwest-rustls",
Expand Down
58 changes: 58 additions & 0 deletions examples/axum-otlp/k6-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import http from "k6/http";

export const options = {
// A number specifying the number of VUs to run concurrently.
vus: 10,
// A string specifying the total duration of the test run.
duration: "200s",

// The following section contains configuration options for execution of this
// test script in Grafana Cloud.
//
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
//
// cloud: {
// // The ID of the project to which the test is assigned in the k6 Cloud UI.
// // By default tests are executed in default project.
// projectID: "",
// // The name of the test in the k6 Cloud UI.
// // Test runs with the same name will be grouped.
// name: "script.js"
// },

// Uncomment this section to enable the use of Browser API in your tests.
//
// See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more
// about using Browser API in your test scripts.
//
// scenarios: {
// // The scenario name appears in the result summary, tags, and so on.
// // You can give the scenario any name, as long as each name in the script is unique.
// ui: {
// // Executor is a mandatory parameter for browser-based tests.
// // Shared iterations in this case tells k6 to reuse VUs to execute iterations.
// //
// // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types.
// executor: 'shared-iterations',
// options: {
// browser: {
// // This is a mandatory parameter that instructs k6 to launch and
// // connect to a chromium-based browser, and use it to run UI-based
// // tests.
// type: 'chromium',
// },
// },
// },
// }
};

// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function () {
http.get("http://127.0.0.1:3003/");
sleep(0.2);
}
7 changes: 5 additions & 2 deletions examples/axum-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn app() -> Router {
// build our application with a route
Router::new()
.route(
"/proxy/:service/*path",
"/proxy/{service}/{*path}",
get(proxy_handler).post(proxy_handler),
)
.route("/", get(index)) // request processed inside span
Expand All @@ -40,7 +40,10 @@ fn app() -> Router {
}

async fn health() -> impl IntoResponse {
axum::Json(json!({ "status" : "UP" }))
let memory_stats = memory_stats::memory_stats();
axum::Json(
json!({ "status" : "UP", "physical_mem": memory_stats.map(|s| s.physical_mem), "virtual_mem": memory_stats.map(|s| s.virtual_mem) }),
)
}

#[tracing::instrument]
Expand Down
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ run_example_http_client:

run_example_load:
cd examples/load; cargo run --release 2>/dev/null

run_example_axum-otlp_load:
cd examples/axum-otlp; k6 run k6-script.js

run_example_axum-otlp_load_client:
while true; do curl -S http://127.0.0.1:3003/health; echo ""; sleep 3; done

0 comments on commit 324734f

Please sign in to comment.