Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): K6 Cloud Update #3416

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
119 changes: 77 additions & 42 deletions docs/docs/tools-and-integrations/k6.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ image: https://res.cloudinary.com/djwdcmwdz/image/upload/v1698686403/docs/Blog_T

K6 is it's a great tool in its own right that allows you to replicate most of the production challenges you might encounter. But, as with all of the tools that only test the initial transaction between the client side and the server, you can only run validations against the immediate response from the service.

<div style={{position: "relative", paddingBottom: "62.5%", height: "0"}}>
<iframe src="https://www.loom.com/embed/5c5e1261bb0b4fefa30081294378908c" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen width="100%" style={{position: "absolute", top: "0", left: "0", width: "100%", height: "100%"}}>
</iframe>
<div style={{ position: "relative", paddingBottom: "62.5%", height: "0" }}>
<iframe
src="https://www.loom.com/embed/5c5e1261bb0b4fefa30081294378908c"
frameborder="0"
webkitallowfullscreen
mozallowfullscreen
allowfullscreen
width="100%"
style={{ position: "absolute", top: "0", left: "0", width: "100%", height: "100%" }}
></iframe>
</div>

## The K6 Tracetest Extension
Expand Down Expand Up @@ -58,7 +65,7 @@ To do so, you can follow the instructions defined in the [documentation](../gett
**XK6:** To start using the Tracetest k6 binary you need to have the xk6 builder installed on your machine.
You can follow the instructions defined in this [page](https://github.com/grafana/xk6/) to do that.

**OpenTelemetry Instrumented Service:** In order to generate traces and spans, the service under test must support the basics for [propagation](https://opentelemetry.io/docs/reference/specification/context/api-propagators/) through HTTP requests as well as store traces and spans into a Data Store Backend (Jaeger, Grafana Tempo, OpenSearch, etc).
**OpenTelemetry Instrumented Service:** In order to generate traces and spans, the service under test must support the basics for [propagation](https://opentelemetry.io/docs/reference/specification/context/api-propagators/) through HTTP requests as well as store traces and spans into a Data Store Backend (Jaeger, Grafana Tempo, OpenSearch, etc).

## Installing the K6 Tracetest Extension

Expand Down Expand Up @@ -137,7 +144,7 @@ const http = new Http({
// supported propagators tracecontext, baggage, b3, ot, jaeger & xray
propagators: ['b3'],

// tracetest configuration
// tracetest configuration
tracetest: {
// define the triggered test id
testId,
Expand Down Expand Up @@ -220,7 +227,15 @@ const metadata = {
};

// manually running a test
tracetest.runTest(response.trace_id, { testId }, metadata);
tracetest.runTest(
response.trace_id,
{
test_id: testId,
should_wait: true,
variable_name: "TRACE_ID",
},
metadata
);
```

### Using the Custom Output
Expand All @@ -229,7 +244,15 @@ The Tracetest K6 extension includes an output you can use to automatically trigg
In this case, you can avoid manually using:

```javascript
tracetest.runTest(response.trace_id, { testId }, metadata);
tracetest.runTest(
response.trace_id,
{
test_id: testId,
should_wait: true,
variable_name: "TRACE_ID",
},
metadata
);
```

And just focus on writing the HTTP triggers.
Expand Down Expand Up @@ -268,10 +291,10 @@ This will generate an output like the following:

```bash

/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io

execution: local
Expand All @@ -284,7 +307,7 @@ This will generate an output like the following:
ERRO[0017] panic: Tracetest: 5 jobs failed

Goja stack:
native
native

running (17.1s), 0/1 VUs, 6 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 6s
Expand All @@ -294,31 +317,31 @@ default ✓ [======================================] 1 VUs 6s

█ teardown

checks.........................: 100.00% ✓ 12 ✗ 0
checks.........................: 100.00% ✓ 12 ✗ 0
data_received..................: 1.1 kB 67 B/s
data_sent......................: 3.3 kB 190 B/s
http_req_blocked...............: avg=89µs min=3µs med=12.5µs max=476µs p(90)=249µs p(95)=362.49µs
http_req_connecting............: avg=37µs min=0s med=0s max=222µs p(90)=111µs p(95)=166.49µs
http_req_duration..............: avg=4.83ms min=1.86ms med=5.35ms max=7.61ms p(90)=6.77ms p(95)=7.19ms
{ expected_response:true }...: avg=4.83ms min=1.86ms med=5.35ms max=7.61ms p(90)=6.77ms p(95)=7.19ms
http_req_failed................: 0.00% ✓ 0 ✗ 6
http_req_receiving.............: avg=51µs min=32µs med=52.5µs max=74µs p(90)=68µs p(95)=71µs
http_req_sending...............: avg=47.83µs min=17µs med=47µs max=88µs p(90)=71µs p(95)=79.49µs
http_req_tls_handshaking.......: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_waiting...............: avg=4.74ms min=1.75ms med=5.23ms max=7.56ms p(90)=6.69ms p(95)=7.12ms
http_req_duration..............: avg=4.83ms min=1.86ms med=5.35ms max=7.61ms p(90)=6.77ms p(95)=7.19ms
{ expected_response:true }...: avg=4.83ms min=1.86ms med=5.35ms max=7.61ms p(90)=6.77ms p(95)=7.19ms
http_req_failed................: 0.00% ✓ 0 ✗ 6
http_req_receiving.............: avg=51µs min=32µs med=52.5µs max=74µs p(90)=68µs p(95)=71µs
http_req_sending...............: avg=47.83µs min=17µs med=47µs max=88µs p(90)=71µs p(95)=79.49µs
http_req_tls_handshaking.......: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_waiting...............: avg=4.74ms min=1.75ms med=5.23ms max=7.56ms p(90)=6.69ms p(95)=7.12ms
http_reqs......................: 6 0.350387/s
iteration_duration.............: avg=2.44s min=1s med=1s max=11.08s p(90)=5.03s p(95)=8.06s
iteration_duration.............: avg=2.44s min=1s med=1s max=11.08s p(90)=5.03s p(95)=8.06s
iterations.....................: 6 0.350387/s
vus............................: 0 min=0 max=1
vus_max........................: 1 min=1 max=1
[TotalRuns=6, SuccessfulRus=1, FailedRuns=5]
[FAILED]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc071893eaaca9de301f2147e2be372e, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/272]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718fff1aca9de30b702c3a1bfad75, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/275]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718b8daaca9de301e39889afca15b, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/276]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718a7e2aca9de30955b5203b162a7, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/273]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718edf9aca9de305916d7b1e7814c, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/274]
[SUCCESSFUL]
[TotalRuns=6, SuccessfulRus=1, FailedRuns=5]
[FAILED]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc071893eaaca9de301f2147e2be372e, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/272]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718fff1aca9de30b702c3a1bfad75, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/275]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718b8daaca9de301e39889afca15b, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/276]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718a7e2aca9de30955b5203b162a7, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/273]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718edf9aca9de305916d7b1e7814c, RunState=FINISHED FailingSpecs=true, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/274]
[SUCCESSFUL]
[Request=POST - http://localhost:8081/pokemon/import, TraceID=dc0718c9d2aca9de3044a794f7248eab, RunState=FINISHED FailingSpecs=false, TracetestURL= http://localhost:3000/test/kc_MgKoVR/run/271]
```

Expand Down Expand Up @@ -368,6 +391,18 @@ Usage:
XK6_TRACETEST_SERVER_PATH=<your-server-path> k6 run <your-script>.js -o xk6-tracetest
```

**XK6_TRACETEST_API_TOKEN:** Allows you authenticate every operation against done by the scripts against the [Tracetest Cloud](https://app.tracetest.io/).

:::note
To find more about the API Tokens visit the [concepts page](../concepts/environment-tokens).
:::

Usage:

```bash
XK6_TRACETEST_API_TOKEN=<your-api-token> k6 run <your-script>.js -o xk6-tracetest
```

Need more ways to configure it? Let us know!

## Full Script Example
Expand All @@ -382,28 +417,28 @@ import { sleep } from "k6";

export const options = {
vus: 1,
duration: "6s",
duration: "5s",
thresholds: {
http_req_duration: ["p(95)<1"], // 95% of requests should be below 200ms
},
};

const tracetest = Tracetest({
serverUrl: "http://localhost:11633",
});
const testId = "kc_MgKoVR";
let pokemonId = 6; // charizad
let pokemonId = 6; //charizard
const http = new Http();
const url = "http://localhost:8081/pokemon/import";
const testId = "kc_MgKoVR";
const tracetest = Tracetest();

export default function () {
const url = "http://localhost:8081/pokemon/import";
const payload = JSON.stringify({
id: pokemonId,
});
const params = {
tracetest: {
testId,
},
headers: {
"Content-Type": "application/json",
},
tracetest: {
testId,
},
};

const response = http.post(url, payload, params);
Expand All @@ -413,7 +448,7 @@ export default function () {
"body matches de id": (r) => JSON.parse(r.body).id === pokemonId,
});

pokemonId = pokemonId + 1;
pokemonId += 1;
sleep(1);
}

Expand All @@ -432,7 +467,7 @@ export function handleSummary(data) {
`;

return {
stdout: summary,
stderr: summary,
"tracetest.json": tracetest.json(),
};
}
Expand Down