diff --git a/.mise.toml b/.mise.toml index e5e5c87..5c0cb9f 100644 --- a/.mise.toml +++ b/.mise.toml @@ -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) diff --git a/examples/axum-otlp/Cargo.toml b/examples/axum-otlp/Cargo.toml index 9b5160e..f1857de 100644 --- a/examples/axum-otlp/Cargo.toml +++ b/examples/axum-otlp/Cargo.toml @@ -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", diff --git a/examples/axum-otlp/k6-script.js b/examples/axum-otlp/k6-script.js new file mode 100644 index 0000000..dd82832 --- /dev/null +++ b/examples/axum-otlp/k6-script.js @@ -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); +} diff --git a/examples/axum-otlp/src/main.rs b/examples/axum-otlp/src/main.rs index 136e9f3..c04f5dd 100644 --- a/examples/axum-otlp/src/main.rs +++ b/examples/axum-otlp/src/main.rs @@ -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 @@ -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] diff --git a/justfile b/justfile index 89bb424..31d1f4b 100644 --- a/justfile +++ b/justfile @@ -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