From 9040dce9e8ac132de0ead97bc138db09ebc139ce Mon Sep 17 00:00:00 2001 From: Heitor Tashiro Sergent Date: Wed, 6 Dec 2023 14:44:25 -0500 Subject: [PATCH] chore: fix broken links and bring changes from #1393 (#1448) * chore: bring in changes from #1393 to next * chore: backport to v0.48 * chore: remove test services * chore: backport to v0.48 * chore: backport to v0.47 --- .../next/examples/oauth-authentication.md | 210 +++++++++++++++++- docs/sources/next/get-started/resources.md | 2 - .../xk6-disruptor/faults/_index.md | 11 +- .../xk6-disruptor/faults/pod-termination.md | 33 +++ .../xk6-disruptor/get-started/_index.md | 1 - .../xk6-disruptor/poddisruptor/_index.md | 15 +- .../xk6-disruptor/poddisruptor/constructor.md | 2 +- .../poddisruptor/injectgrpcfaults.md | 10 +- .../poddisruptor/injecthttpfaults.md | 12 +- .../poddisruptor/terminate-pods.md | 24 ++ .../xk6-disruptor/servicedisruptor/_index.md | 14 +- .../servicedisruptor/constructor.md | 2 +- .../servicedisruptor/injectgrpcfaults.md | 10 +- .../servicedisruptor/injecthttpfaults.md | 12 +- .../servicedisruptor/terminate-pods.md | 24 ++ .../end-of-test/custom-summary.md | 2 +- .../scenarios/executors/shared-iterations.md | 4 +- docs/sources/v0.47.x/get-started/resources.md | 2 - .../v0.48.x/examples/oauth-authentication.md | 210 +++++++++++++++++- docs/sources/v0.48.x/get-started/resources.md | 2 - .../xk6-disruptor/faults/_index.md | 11 +- .../xk6-disruptor/faults/pod-termination.md | 33 +++ .../xk6-disruptor/get-started/_index.md | 1 - .../xk6-disruptor/poddisruptor/_index.md | 15 +- .../xk6-disruptor/poddisruptor/constructor.md | 2 +- .../poddisruptor/injectgrpcfaults.md | 10 +- .../poddisruptor/injecthttpfaults.md | 12 +- .../poddisruptor/terminate-pods.md | 24 ++ .../xk6-disruptor/servicedisruptor/_index.md | 14 +- .../servicedisruptor/constructor.md | 2 +- .../servicedisruptor/injectgrpcfaults.md | 10 +- .../servicedisruptor/injecthttpfaults.md | 12 +- .../servicedisruptor/terminate-pods.md | 24 ++ .../end-of-test/custom-summary.md | 2 +- .../scenarios/executors/shared-iterations.md | 4 +- .../en/01 Get started/05 resources.md | 3 - 36 files changed, 678 insertions(+), 103 deletions(-) create mode 100644 docs/sources/next/javascript-api/xk6-disruptor/faults/pod-termination.md create mode 100644 docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md create mode 100644 docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md create mode 100644 docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/pod-termination.md create mode 100644 docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md create mode 100644 docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md diff --git a/docs/sources/next/examples/oauth-authentication.md b/docs/sources/next/examples/oauth-authentication.md index e2f4154bdf..604e402a57 100644 --- a/docs/sources/next/examples/oauth-authentication.md +++ b/docs/sources/next/examples/oauth-authentication.md @@ -61,6 +61,207 @@ export function authenticateUsingAzure(tenantId, clientId, clientSecret, scope, {{< /code >}} +### Azure B2C + +The following example shows how you can authenticate with Azure B2C using the [Client Credentials Flow](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-oauth-code#client-credentials-flow). + +This example is based on a JMeter example found at the [azure-ad-b2c/load-tests](https://github.com/azure-ad-b2c/load-tests) repository. + +To use this script, you need to: + +1. [Set up your own Azure B2C tenant](https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant) + - Copy the tenant name, it will be used in your test script. +1. [Register a web application](https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-register-applications?tabs=app-reg-ga) + - Register a single page application with the redirect URL of: https://jwt.ms. That's needed for the flow to receive a token. + - After the creation, you can get the Application (client) ID, and the Directory (tenant) ID. Copy both of them, they'll be used in your test script. +1. [Create a user flow so that you can sign up and create a user](https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-user-flows) + - Create a new user, and copy the username and password. They'll be used in the test script. + +You can find the settings in the B2C settings in the Azure portal if you need to refer to them later on. Make sure to fill out all the variables for the `B2CGraphSettings` object, as well as replace `USERNAME` and `PASSWORD` in `export default function`. + +{{< code >}} + +```javascript +import http from 'k6/http'; +import crypto from 'k6/crypto'; +import { randomString } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; + +const B2CGraphSettings = { + B2C: { + client_id: '', // Application ID in Azure + user_flow_name: '', + tenant_id: '', // Directory ID in Azure + tenant_name: '', + scope: 'openid', + redirect_url: 'https://jwt.ms', + }, +}; + +/** + * Authenticate using OAuth against Azure B2C + * @function + * @param {string} username - Username of the user to authenticate + * @param {string} password + * @return {string} id_token + */ +export function GetB2cIdToken(username, password) { + const state = GetState(); + SelfAsserted(state, username, password); + const code = CombinedSigninAndSignup(state); + return GetToken(code, state.codeVerifier); +} + +/** + * @typedef {object} b2cStateProperties + * @property {string} csrfToken + * @property {string} stateProperty + * @property {string} codeVerifier + * + */ + +/** + * Get the id token from Azure B2C + * @function + * @param {string} code + * @returns {string} id_token + */ +const GetToken = (code, codeVerifier) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_id}` + + `/oauth2/v2.0/token` + + `?p=${B2CGraphSettings.B2C.user_flow_name}` + + `&client_id=${B2CGraphSettings.B2C.client_id}` + + `&grant_type=authorization_code` + + `&scope=${B2CGraphSettings.B2C.scope}` + + `&code=${code}` + + `&redirect_uri=${B2CGraphSettings.B2C.redirect_url}` + + `&code_verifier=${codeVerifier}`; + + const response = http.post(url, '', { + tags: { + b2c_login: 'GetToken', + }, + }); + + return JSON.parse(response.body).id_token; +}; + +/** + * Signs in the user using the CombinedSigninAndSignup policy + * extraqct B2C code from response + * @function + * @param {b2cStateProperties} state + * @returns {string} code + */ +const CombinedSigninAndSignup = (state) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_name}.onmicrosoft.com` + + `/${B2CGraphSettings.B2C.user_flow_name}/api/CombinedSigninAndSignup/confirmed` + + `?csrf_token=${state.csrfToken}` + + `&rememberMe=false` + + `&tx=StateProperties=${state.stateProperty}` + + `&p=${B2CGraphSettings.B2C.user_flow_name}`; + + const response = http.get(url, '', { + tags: { + b2c_login: 'CombinedSigninAndSignup', + }, + }); + const codeRegex = '.*code=([^"]*)'; + return response.url.match(codeRegex)[1]; +}; + +/** + * Signs in the user using the SelfAsserted policy + * @function + * @param {b2cStateProperties} state + * @param {string} username + * @param {string} password + */ +const SelfAsserted = (state, username, password) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_id}` + + `/${B2CGraphSettings.B2C.user_flow_name}/SelfAsserted` + + `?tx=StateProperties=${state.stateProperty}` + + `&p=${B2CGraphSettings.B2C.user_flow_name}` + + `&request_type=RESPONSE` + + `&email=${username}` + + `&password=${password}`; + + const params = { + headers: { + 'X-CSRF-TOKEN': `${state.csrfToken}`, + }, + tags: { + b2c_login: 'SelfAsserted', + }, + }; + http.post(url, '', params); +}; + +/** + * Calls the B2C login page to get the state property + * @function + * @returns {b2cStateProperties} b2cState + */ +const GetState = () => { + const nonce = randomString(50); + const challenge = crypto.sha256(nonce.toString(), 'base64rawurl'); + + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com` + + `/${B2CGraphSettings.B2C.tenant_id}/oauth2/v2.0/authorize?` + + `p=${B2CGraphSettings.B2C.user_flow_name}` + + `&client_id=${B2CGraphSettings.B2C.client_id}` + + `&nonce=${nonce}` + + `&redirect_uri=${B2CGraphSettings.B2C.redirect_url}` + + `&scope=${B2CGraphSettings.B2C.scope}` + + `&response_type=code` + + `&prompt=login` + + `&code_challenge_method=S256` + + `&code_challenge=${challenge}` + + `&response_mode=fragment`; + + const response = http.get(url, '', { + tags: { + b2c_login: 'GetCookyAndState', + }, + }); + + const vuJar = http.cookieJar(); + const responseCookies = vuJar.cookiesForURL(response.url); + + const b2cState = {}; + b2cState.codeVerifier = nonce; + b2cState.csrfToken = responseCookies['x-ms-cpim-csrf'][0]; + b2cState.stateProperty = response.body.match('.*StateProperties=([^"]*)')[1]; + return b2cState; +}; + +/** + * Helper function to get the authorization header for a user + * @param {user} user + * @returns {object} httpsOptions + */ +export const GetAuthorizationHeaderForUser = (user) => { + const token = GetB2cIdToken(user.username, user.password); + + return { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + token, + }, + }; +}; + +export default function () { + const token = GetB2cIdToken('USERNAME', 'PASSWORD'); + console.log(token); +} +``` + +{{< /code >}} + ### Okta {{< code >}} @@ -79,7 +280,14 @@ import encoding from 'k6/encoding'; * @param {string} scope - Space-separated list of scopes * @param {string|object} resource - Either a resource ID (as string) or an object containing username and password */ -export function authenticateUsingOkta(oktaDomain, authServerId, clientId, clientSecret, scope, resource) { +export function authenticateUsingOkta( + oktaDomain, + authServerId, + clientId, + clientSecret, + scope, + resource +) { if (authServerId === 'undefined' || authServerId == '') { authServerId = 'default'; } diff --git a/docs/sources/next/get-started/resources.md b/docs/sources/next/get-started/resources.md index f4d3c4ea8b..2a60e811a5 100644 --- a/docs/sources/next/get-started/resources.md +++ b/docs/sources/next/get-started/resources.md @@ -32,8 +32,6 @@ If you need a place to learn k6 and test your scripts, you can use these playgro - [pizza.grafana.fun](https://pizza.grafana.fun/). A simple demo webapp. [grafana/quickpizza](https://github.com/grafana/quickpizza) - [k6-http.grafana.fun](https://k6-http.grafana.fun). A simple HTTP Request & Response Service. [grafana/httpbin](https://github.com/grafana/httpbin) -- [k6-php.grafana.fun](https://k6-php.grafana.fun). A simple PHP website. [grafana/test.k6.io](https://github.com/grafana/test.k6.io) -- [test-api.k6.io](https://test-api.k6.io). A demo HTTP REST API with some WebSocket support. [grafana/test-api.k6.io](https://github.com/grafana/test-api.k6.io) - [grpcbin.test.k6.io](https://grpcbin.test.k6.io/). A simple gRPC Request & Response Service. [grafana/k6-grpcbin](https://github.com/grafana/k6-grpcbin) Note that these are shared testing environments - please avoid high-load tests. Alternatively, you can deploy and host them on your infrastructure and run the examples in the repository. diff --git a/docs/sources/next/javascript-api/xk6-disruptor/faults/_index.md b/docs/sources/next/javascript-api/xk6-disruptor/faults/_index.md index 0dd1d0a6f0..aa8d461eb7 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/faults/_index.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/faults/_index.md @@ -1,14 +1,15 @@ --- title: 'Faults' excerpt: 'xk6-disruptor: Fault Description' -weight: 01 +weight: 100 --- # Faults A fault is as an abnormal condition that affects a system component and which may lead to a failure. -| Fault type | Description | -| ------------------------------------------------------------------------------------ | ------------------------------------------- | -| [gRPC Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) | Fault affecting gRPC requests from a target | -| [HTTP Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) | Fault affecting HTTP requests from a target | +| Fault type | Description | +| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | +| [gRPC Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) | Fault affecting gRPC requests from a target | +| [HTTP Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) | Fault affecting HTTP requests from a target | +| [Pod Termination Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | Fault terminating a number of target Pods | diff --git a/docs/sources/next/javascript-api/xk6-disruptor/faults/pod-termination.md b/docs/sources/next/javascript-api/xk6-disruptor/faults/pod-termination.md new file mode 100644 index 0000000000..30902aafff --- /dev/null +++ b/docs/sources/next/javascript-api/xk6-disruptor/faults/pod-termination.md @@ -0,0 +1,33 @@ +--- +title: 'Pod Termination' +description: 'xk6-disruptor: Pod Termination Fault attributes' +weight: 03 +--- + +# Pod Termination + +A Pod Termination Fault allows terminating either a fixed number or a percentage of the pods that matching a selector or back a service. + +A Pod Termination fault is defined by the following attributes: + +| Attribute | Type | Description | +| --------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| count | integer or percentage | the number of pods to be terminated. It can be specified as a integer number or as a percentage, for example `30%`, that defines the fraction of target pods to be terminated | + +{{% admonition type="note" %}} + +If the count is a percentage and there are no enough elements in the target pod list, the number is rounded up. +For example '25%' of a list of 2 target pods will terminate one pod. +If the list of target pods is not empty, at least one pod is always terminated. + +{{% /admonition %}} + +## Example + +This example defines a PorTermination fault that will terminate `30%` of target pods + +```javascript +const fault = { + count: '30%', +}; +``` diff --git a/docs/sources/next/javascript-api/xk6-disruptor/get-started/_index.md b/docs/sources/next/javascript-api/xk6-disruptor/get-started/_index.md index f1ce26ed41..c2203dd5df 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/get-started/_index.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/get-started/_index.md @@ -2,7 +2,6 @@ title: 'Get started' excerpt: 'xk6-disruptor is an extension that adds fault injection capabilities to k6. Start here to learn the basics and how to use the disruptor' weight: 01 -weight: 01 --- # Get started diff --git a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/_index.md b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/_index.md index 9230046217..cb537e8b75 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/_index.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/_index.md @@ -1,7 +1,7 @@ --- title: 'PodDisruptor' excerpt: 'xk6-disruptor: PodDisruptor class' -weight: 02 +weight: 200 --- # PodDisruptor @@ -12,11 +12,12 @@ To construct a `PodDisruptor`, use the [PodDisruptor() constructor](https://graf ## Methods -| Method | Description | -| --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | -| [PodDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | -| [PodDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults) | Inject [HTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | -| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor | +| Method | Description | +| -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| [PodDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | +| [PodDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults) | Inject [HTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor | +| [PodDisruptor.terminatePods()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/terminate-pods) | executes a [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) in the target Pods | ## Example @@ -59,4 +60,4 @@ $ kubectl run nginx --image=nginx You can also use the [xk6-kubernetes](https://github.com/grafana/xk6-kubernetes) extension for creating these resources from your test script. - {{% /admonition %}} +{{% /admonition %}} diff --git a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/constructor.md b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/constructor.md index b72d2e9bde..65965c0741 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/constructor.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/constructor.md @@ -1,7 +1,7 @@ --- title: 'Constructor' excerpt: 'xk6-disruptor: PodDisruptor constructor' -weight: 01 +weight: 100 --- # Constructor diff --git a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md index ddf2b64060..d28d4daced 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md @@ -1,18 +1,18 @@ --- title: 'injectGrpcFaults()' excerpt: 'xk6-disruptor: PodDisruptor.injectGrpcFaults method' -weight: 02 +weight: 200 --- # injectGrpcFaults() injectGrpcFaults injects gRPC faults in the requests served by a target Pod. -| Parameter | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameter | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## options diff --git a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md index 318f451ba7..0a61d0ea1c 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md @@ -1,18 +1,18 @@ --- title: 'injectHTTPFaults()' excerpt: 'xk6-disruptor: PodDisruptor.injectHTTPFaults method' -weight: 03 +weight: 300 --- # injectHTTPFaults() injectHTTPFaults injects HTTP faults in the requests served by a target Pod. -| Parameter | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameter | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [http faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## options @@ -30,7 +30,7 @@ WARN\[0035\] Request Failed error="read tcp 172.18.0.1:43564->172.18.255.200:80: This is normal and means that one request was "in transit" at the time the faults were injected, causing the request to fail from a network connection reset. - {{% /admonition %}} +{{% /admonition %}} ## Example diff --git a/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md new file mode 100644 index 0000000000..aea02db3f3 --- /dev/null +++ b/docs/sources/next/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md @@ -0,0 +1,24 @@ +--- +title: 'terminatePods()' +description: 'xk6-disruptor: PodDisruptor.terminatePods method' +weight: 400 +--- + +# terminatePods() + +`terminatePods` terminates a number of the pods matching the selector configured in the PodDisruptor. + +| Parameter | Type | Description | +| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- | +| fault | object | description of the [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | + +## Example + + + +```javascript +const fault = { + count: 2, +}; +disruptor.terminatePods(fault); +``` diff --git a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/_index.md b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/_index.md index fbc0f82ddd..952543ec88 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/_index.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/_index.md @@ -1,7 +1,7 @@ --- title: 'ServiceDisruptor' excerpt: 'xk6-disruptor: ServiceDisruptor class' -weight: 03 +weight: 300 --- # ServiceDisruptor @@ -12,10 +12,12 @@ To construct a `ServiceDisruptor`, use the [ServiceDisruptor() constructor](http ## Methods -| Method | Description | -| ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | -| [ServiceDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | -| [ServiceDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults) | Inject [HTTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| Method | Description | +| ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| [ServiceDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | +| [ServiceDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults) | Inject [HTTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| ServiceDisruptor.targets() | Returns the list of target Pods of the ServiceDisruptor | +| [ServiceDisruptor.terminatePods()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/terminate-pods) | executes a [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) in the target Pods | ## Example @@ -50,4 +52,4 @@ You can test this script by creating first a pod running nginx and exposing it a You can also use the [xk6-kubernetes](https://github.com/grafana/xk6-kubernetes) extension for creating these resources from your test script. - {{% /admonition %}} +{{% /admonition %}} diff --git a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/constructor.md b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/constructor.md index 3f9b87030e..ac36f8daaf 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/constructor.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/constructor.md @@ -1,7 +1,7 @@ --- title: 'Constructor' excerpt: 'xk6-disruptor: ServiceDisruptor constructor' -weight: 01 +weight: 100 --- # Constructor diff --git a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md index 5892038280..3e917ed2fd 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md @@ -1,18 +1,18 @@ --- title: 'injectGrpcFaults' excerpt: 'xk6-disruptor: ServiceDisruptor.injectGrpcFaults method' -weight: 02 +weight: 200 --- # injectGrpcFaults injectGrpcFaults injects gRPC faults in the requests served by a target Service. -| Parameters | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameters | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## Options diff --git a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md index 01372275cb..6201c5c279 100644 --- a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md +++ b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md @@ -1,18 +1,18 @@ --- title: 'injectHTTPFaults' excerpt: 'xk6-disruptor: ServiceDisruptor.injectHTTPFaults method' -weight: 03 +weight: 300 --- # injectHTTPFaults injectHTTPFaults injects HTTP faults in the requests served by a target Service. -| Parameters | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameters | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [http faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## Options @@ -30,7 +30,7 @@ WARN\[0035\] Request Failed error="read tcp 172.18.0.1:43564->172.18.255.200:80: This is normal and means that one request was "in transit" at the time the faults were injected causing the request to fail due to a network connection reset. - {{% /admonition %}} +{{% /admonition %}} ## Example diff --git a/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md new file mode 100644 index 0000000000..44ebf76430 --- /dev/null +++ b/docs/sources/next/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md @@ -0,0 +1,24 @@ +--- +title: 'terminatePods()' +description: 'xk6-disruptor: ServiceDisruptor.terminatePods method' +weight: 400 +--- + +# terminatePods() + +`terminatePods` terminates a number of pods that belong to the service specified in the ServiceDisruptor. + +| Parameter | Type | Description | +| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- | +| fault | object | description of the [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | + +## Example + + + +```javascript +const fault = { + count: 2, +}; +disruptor.terminatePods(fault); +``` diff --git a/docs/sources/next/results-output/end-of-test/custom-summary.md b/docs/sources/next/results-output/end-of-test/custom-summary.md index 098e4d35ec..6fd2c13bc3 100644 --- a/docs/sources/next/results-output/end-of-test/custom-summary.md +++ b/docs/sources/next/results-output/end-of-test/custom-summary.md @@ -72,7 +72,7 @@ They determine where k6 displays or saves the content: The value of a key can have a type of either `string` or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). -You can return mutiple summary outputs in a script. +You can return multiple summary outputs in a script. As an example, this `return` statement sends a report to standard output and writes the `data` object to a JSON file. {{< code >}} diff --git a/docs/sources/next/using-k6/scenarios/executors/shared-iterations.md b/docs/sources/next/using-k6/scenarios/executors/shared-iterations.md index 9ee6a3687d..ad5486ddbd 100644 --- a/docs/sources/next/using-k6/scenarios/executors/shared-iterations.md +++ b/docs/sources/next/using-k6/scenarios/executors/shared-iterations.md @@ -9,7 +9,7 @@ weight: 01 The `shared-iterations` executor shares iterations between the number of VUs. The test ends once k6 executes all iterations. -For a shortcut to this executor, use the [vus](https://grafana.com/docs/k6//using-k6/k6-options/reference#vus) and [iterations](https://grafana.com/docs/k6//using-k6/k6-options/reference#iterations) options. +For a shortcut to this executor, use the [`vus`](https://grafana.com/docs/k6//using-k6/k6-options/reference#vus) and [`iterations`](https://grafana.com/docs/k6//using-k6/k6-options/reference#iterations) options. {{% admonition type="note" %}} @@ -18,7 +18,7 @@ VU that executes faster will complete more iterations than slower VUs. To guarantee that every VU completes a specific, fixed number of iterations, [use the per-VU iterations executor](https://grafana.com/docs/k6//using-k6/scenarios/executors/per-vu-iterations). - {{% /admonition %}} +{{% /admonition %}} ## Options diff --git a/docs/sources/v0.47.x/get-started/resources.md b/docs/sources/v0.47.x/get-started/resources.md index f4d3c4ea8b..2a60e811a5 100644 --- a/docs/sources/v0.47.x/get-started/resources.md +++ b/docs/sources/v0.47.x/get-started/resources.md @@ -32,8 +32,6 @@ If you need a place to learn k6 and test your scripts, you can use these playgro - [pizza.grafana.fun](https://pizza.grafana.fun/). A simple demo webapp. [grafana/quickpizza](https://github.com/grafana/quickpizza) - [k6-http.grafana.fun](https://k6-http.grafana.fun). A simple HTTP Request & Response Service. [grafana/httpbin](https://github.com/grafana/httpbin) -- [k6-php.grafana.fun](https://k6-php.grafana.fun). A simple PHP website. [grafana/test.k6.io](https://github.com/grafana/test.k6.io) -- [test-api.k6.io](https://test-api.k6.io). A demo HTTP REST API with some WebSocket support. [grafana/test-api.k6.io](https://github.com/grafana/test-api.k6.io) - [grpcbin.test.k6.io](https://grpcbin.test.k6.io/). A simple gRPC Request & Response Service. [grafana/k6-grpcbin](https://github.com/grafana/k6-grpcbin) Note that these are shared testing environments - please avoid high-load tests. Alternatively, you can deploy and host them on your infrastructure and run the examples in the repository. diff --git a/docs/sources/v0.48.x/examples/oauth-authentication.md b/docs/sources/v0.48.x/examples/oauth-authentication.md index e2f4154bdf..604e402a57 100644 --- a/docs/sources/v0.48.x/examples/oauth-authentication.md +++ b/docs/sources/v0.48.x/examples/oauth-authentication.md @@ -61,6 +61,207 @@ export function authenticateUsingAzure(tenantId, clientId, clientSecret, scope, {{< /code >}} +### Azure B2C + +The following example shows how you can authenticate with Azure B2C using the [Client Credentials Flow](https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-oauth-code#client-credentials-flow). + +This example is based on a JMeter example found at the [azure-ad-b2c/load-tests](https://github.com/azure-ad-b2c/load-tests) repository. + +To use this script, you need to: + +1. [Set up your own Azure B2C tenant](https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant) + - Copy the tenant name, it will be used in your test script. +1. [Register a web application](https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-register-applications?tabs=app-reg-ga) + - Register a single page application with the redirect URL of: https://jwt.ms. That's needed for the flow to receive a token. + - After the creation, you can get the Application (client) ID, and the Directory (tenant) ID. Copy both of them, they'll be used in your test script. +1. [Create a user flow so that you can sign up and create a user](https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-user-flows) + - Create a new user, and copy the username and password. They'll be used in the test script. + +You can find the settings in the B2C settings in the Azure portal if you need to refer to them later on. Make sure to fill out all the variables for the `B2CGraphSettings` object, as well as replace `USERNAME` and `PASSWORD` in `export default function`. + +{{< code >}} + +```javascript +import http from 'k6/http'; +import crypto from 'k6/crypto'; +import { randomString } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; + +const B2CGraphSettings = { + B2C: { + client_id: '', // Application ID in Azure + user_flow_name: '', + tenant_id: '', // Directory ID in Azure + tenant_name: '', + scope: 'openid', + redirect_url: 'https://jwt.ms', + }, +}; + +/** + * Authenticate using OAuth against Azure B2C + * @function + * @param {string} username - Username of the user to authenticate + * @param {string} password + * @return {string} id_token + */ +export function GetB2cIdToken(username, password) { + const state = GetState(); + SelfAsserted(state, username, password); + const code = CombinedSigninAndSignup(state); + return GetToken(code, state.codeVerifier); +} + +/** + * @typedef {object} b2cStateProperties + * @property {string} csrfToken + * @property {string} stateProperty + * @property {string} codeVerifier + * + */ + +/** + * Get the id token from Azure B2C + * @function + * @param {string} code + * @returns {string} id_token + */ +const GetToken = (code, codeVerifier) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_id}` + + `/oauth2/v2.0/token` + + `?p=${B2CGraphSettings.B2C.user_flow_name}` + + `&client_id=${B2CGraphSettings.B2C.client_id}` + + `&grant_type=authorization_code` + + `&scope=${B2CGraphSettings.B2C.scope}` + + `&code=${code}` + + `&redirect_uri=${B2CGraphSettings.B2C.redirect_url}` + + `&code_verifier=${codeVerifier}`; + + const response = http.post(url, '', { + tags: { + b2c_login: 'GetToken', + }, + }); + + return JSON.parse(response.body).id_token; +}; + +/** + * Signs in the user using the CombinedSigninAndSignup policy + * extraqct B2C code from response + * @function + * @param {b2cStateProperties} state + * @returns {string} code + */ +const CombinedSigninAndSignup = (state) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_name}.onmicrosoft.com` + + `/${B2CGraphSettings.B2C.user_flow_name}/api/CombinedSigninAndSignup/confirmed` + + `?csrf_token=${state.csrfToken}` + + `&rememberMe=false` + + `&tx=StateProperties=${state.stateProperty}` + + `&p=${B2CGraphSettings.B2C.user_flow_name}`; + + const response = http.get(url, '', { + tags: { + b2c_login: 'CombinedSigninAndSignup', + }, + }); + const codeRegex = '.*code=([^"]*)'; + return response.url.match(codeRegex)[1]; +}; + +/** + * Signs in the user using the SelfAsserted policy + * @function + * @param {b2cStateProperties} state + * @param {string} username + * @param {string} password + */ +const SelfAsserted = (state, username, password) => { + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com/${B2CGraphSettings.B2C.tenant_id}` + + `/${B2CGraphSettings.B2C.user_flow_name}/SelfAsserted` + + `?tx=StateProperties=${state.stateProperty}` + + `&p=${B2CGraphSettings.B2C.user_flow_name}` + + `&request_type=RESPONSE` + + `&email=${username}` + + `&password=${password}`; + + const params = { + headers: { + 'X-CSRF-TOKEN': `${state.csrfToken}`, + }, + tags: { + b2c_login: 'SelfAsserted', + }, + }; + http.post(url, '', params); +}; + +/** + * Calls the B2C login page to get the state property + * @function + * @returns {b2cStateProperties} b2cState + */ +const GetState = () => { + const nonce = randomString(50); + const challenge = crypto.sha256(nonce.toString(), 'base64rawurl'); + + const url = + `https://${B2CGraphSettings.B2C.tenant_name}.b2clogin.com` + + `/${B2CGraphSettings.B2C.tenant_id}/oauth2/v2.0/authorize?` + + `p=${B2CGraphSettings.B2C.user_flow_name}` + + `&client_id=${B2CGraphSettings.B2C.client_id}` + + `&nonce=${nonce}` + + `&redirect_uri=${B2CGraphSettings.B2C.redirect_url}` + + `&scope=${B2CGraphSettings.B2C.scope}` + + `&response_type=code` + + `&prompt=login` + + `&code_challenge_method=S256` + + `&code_challenge=${challenge}` + + `&response_mode=fragment`; + + const response = http.get(url, '', { + tags: { + b2c_login: 'GetCookyAndState', + }, + }); + + const vuJar = http.cookieJar(); + const responseCookies = vuJar.cookiesForURL(response.url); + + const b2cState = {}; + b2cState.codeVerifier = nonce; + b2cState.csrfToken = responseCookies['x-ms-cpim-csrf'][0]; + b2cState.stateProperty = response.body.match('.*StateProperties=([^"]*)')[1]; + return b2cState; +}; + +/** + * Helper function to get the authorization header for a user + * @param {user} user + * @returns {object} httpsOptions + */ +export const GetAuthorizationHeaderForUser = (user) => { + const token = GetB2cIdToken(user.username, user.password); + + return { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + token, + }, + }; +}; + +export default function () { + const token = GetB2cIdToken('USERNAME', 'PASSWORD'); + console.log(token); +} +``` + +{{< /code >}} + ### Okta {{< code >}} @@ -79,7 +280,14 @@ import encoding from 'k6/encoding'; * @param {string} scope - Space-separated list of scopes * @param {string|object} resource - Either a resource ID (as string) or an object containing username and password */ -export function authenticateUsingOkta(oktaDomain, authServerId, clientId, clientSecret, scope, resource) { +export function authenticateUsingOkta( + oktaDomain, + authServerId, + clientId, + clientSecret, + scope, + resource +) { if (authServerId === 'undefined' || authServerId == '') { authServerId = 'default'; } diff --git a/docs/sources/v0.48.x/get-started/resources.md b/docs/sources/v0.48.x/get-started/resources.md index f4d3c4ea8b..2a60e811a5 100644 --- a/docs/sources/v0.48.x/get-started/resources.md +++ b/docs/sources/v0.48.x/get-started/resources.md @@ -32,8 +32,6 @@ If you need a place to learn k6 and test your scripts, you can use these playgro - [pizza.grafana.fun](https://pizza.grafana.fun/). A simple demo webapp. [grafana/quickpizza](https://github.com/grafana/quickpizza) - [k6-http.grafana.fun](https://k6-http.grafana.fun). A simple HTTP Request & Response Service. [grafana/httpbin](https://github.com/grafana/httpbin) -- [k6-php.grafana.fun](https://k6-php.grafana.fun). A simple PHP website. [grafana/test.k6.io](https://github.com/grafana/test.k6.io) -- [test-api.k6.io](https://test-api.k6.io). A demo HTTP REST API with some WebSocket support. [grafana/test-api.k6.io](https://github.com/grafana/test-api.k6.io) - [grpcbin.test.k6.io](https://grpcbin.test.k6.io/). A simple gRPC Request & Response Service. [grafana/k6-grpcbin](https://github.com/grafana/k6-grpcbin) Note that these are shared testing environments - please avoid high-load tests. Alternatively, you can deploy and host them on your infrastructure and run the examples in the repository. diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/_index.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/_index.md index 0dd1d0a6f0..aa8d461eb7 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/_index.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/_index.md @@ -1,14 +1,15 @@ --- title: 'Faults' excerpt: 'xk6-disruptor: Fault Description' -weight: 01 +weight: 100 --- # Faults A fault is as an abnormal condition that affects a system component and which may lead to a failure. -| Fault type | Description | -| ------------------------------------------------------------------------------------ | ------------------------------------------- | -| [gRPC Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) | Fault affecting gRPC requests from a target | -| [HTTP Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) | Fault affecting HTTP requests from a target | +| Fault type | Description | +| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | +| [gRPC Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) | Fault affecting gRPC requests from a target | +| [HTTP Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) | Fault affecting HTTP requests from a target | +| [Pod Termination Fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | Fault terminating a number of target Pods | diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/pod-termination.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/pod-termination.md new file mode 100644 index 0000000000..30902aafff --- /dev/null +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/faults/pod-termination.md @@ -0,0 +1,33 @@ +--- +title: 'Pod Termination' +description: 'xk6-disruptor: Pod Termination Fault attributes' +weight: 03 +--- + +# Pod Termination + +A Pod Termination Fault allows terminating either a fixed number or a percentage of the pods that matching a selector or back a service. + +A Pod Termination fault is defined by the following attributes: + +| Attribute | Type | Description | +| --------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| count | integer or percentage | the number of pods to be terminated. It can be specified as a integer number or as a percentage, for example `30%`, that defines the fraction of target pods to be terminated | + +{{% admonition type="note" %}} + +If the count is a percentage and there are no enough elements in the target pod list, the number is rounded up. +For example '25%' of a list of 2 target pods will terminate one pod. +If the list of target pods is not empty, at least one pod is always terminated. + +{{% /admonition %}} + +## Example + +This example defines a PorTermination fault that will terminate `30%` of target pods + +```javascript +const fault = { + count: '30%', +}; +``` diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/get-started/_index.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/get-started/_index.md index f1ce26ed41..c2203dd5df 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/get-started/_index.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/get-started/_index.md @@ -2,7 +2,6 @@ title: 'Get started' excerpt: 'xk6-disruptor is an extension that adds fault injection capabilities to k6. Start here to learn the basics and how to use the disruptor' weight: 01 -weight: 01 --- # Get started diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/_index.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/_index.md index 9230046217..cb537e8b75 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/_index.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/_index.md @@ -1,7 +1,7 @@ --- title: 'PodDisruptor' excerpt: 'xk6-disruptor: PodDisruptor class' -weight: 02 +weight: 200 --- # PodDisruptor @@ -12,11 +12,12 @@ To construct a `PodDisruptor`, use the [PodDisruptor() constructor](https://graf ## Methods -| Method | Description | -| --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | -| [PodDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | -| [PodDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults) | Inject [HTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | -| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor | +| Method | Description | +| -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| [PodDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | +| [PodDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults) | Inject [HTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor | +| [PodDisruptor.terminatePods()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/poddisruptor/terminate-pods) | executes a [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) in the target Pods | ## Example @@ -59,4 +60,4 @@ $ kubectl run nginx --image=nginx You can also use the [xk6-kubernetes](https://github.com/grafana/xk6-kubernetes) extension for creating these resources from your test script. - {{% /admonition %}} +{{% /admonition %}} diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/constructor.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/constructor.md index b72d2e9bde..65965c0741 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/constructor.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/constructor.md @@ -1,7 +1,7 @@ --- title: 'Constructor' excerpt: 'xk6-disruptor: PodDisruptor constructor' -weight: 01 +weight: 100 --- # Constructor diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md index ddf2b64060..d28d4daced 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injectgrpcfaults.md @@ -1,18 +1,18 @@ --- title: 'injectGrpcFaults()' excerpt: 'xk6-disruptor: PodDisruptor.injectGrpcFaults method' -weight: 02 +weight: 200 --- # injectGrpcFaults() injectGrpcFaults injects gRPC faults in the requests served by a target Pod. -| Parameter | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameter | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## options diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md index 318f451ba7..0a61d0ea1c 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/injecthttpfaults.md @@ -1,18 +1,18 @@ --- title: 'injectHTTPFaults()' excerpt: 'xk6-disruptor: PodDisruptor.injectHTTPFaults method' -weight: 03 +weight: 300 --- # injectHTTPFaults() injectHTTPFaults injects HTTP faults in the requests served by a target Pod. -| Parameter | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameter | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [http faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## options @@ -30,7 +30,7 @@ WARN\[0035\] Request Failed error="read tcp 172.18.0.1:43564->172.18.255.200:80: This is normal and means that one request was "in transit" at the time the faults were injected, causing the request to fail from a network connection reset. - {{% /admonition %}} +{{% /admonition %}} ## Example diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md new file mode 100644 index 0000000000..aea02db3f3 --- /dev/null +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/poddisruptor/terminate-pods.md @@ -0,0 +1,24 @@ +--- +title: 'terminatePods()' +description: 'xk6-disruptor: PodDisruptor.terminatePods method' +weight: 400 +--- + +# terminatePods() + +`terminatePods` terminates a number of the pods matching the selector configured in the PodDisruptor. + +| Parameter | Type | Description | +| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- | +| fault | object | description of the [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | + +## Example + + + +```javascript +const fault = { + count: 2, +}; +disruptor.terminatePods(fault); +``` diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/_index.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/_index.md index fbc0f82ddd..952543ec88 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/_index.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/_index.md @@ -1,7 +1,7 @@ --- title: 'ServiceDisruptor' excerpt: 'xk6-disruptor: ServiceDisruptor class' -weight: 03 +weight: 300 --- # ServiceDisruptor @@ -12,10 +12,12 @@ To construct a `ServiceDisruptor`, use the [ServiceDisruptor() constructor](http ## Methods -| Method | Description | -| ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | -| [ServiceDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | -| [ServiceDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults) | Inject [HTTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| Method | Description | +| ---------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| [ServiceDisruptor.injectGrpcFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults) | Inject [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) in the target Pods | +| [ServiceDisruptor.injectHTTPFaults()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults) | Inject [HTTTP faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) in the target Pods | +| ServiceDisruptor.targets() | Returns the list of target Pods of the ServiceDisruptor | +| [ServiceDisruptor.terminatePods()](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/servicedisruptor/terminate-pods) | executes a [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) in the target Pods | ## Example @@ -50,4 +52,4 @@ You can test this script by creating first a pod running nginx and exposing it a You can also use the [xk6-kubernetes](https://github.com/grafana/xk6-kubernetes) extension for creating these resources from your test script. - {{% /admonition %}} +{{% /admonition %}} diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/constructor.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/constructor.md index 3f9b87030e..ac36f8daaf 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/constructor.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/constructor.md @@ -1,7 +1,7 @@ --- title: 'Constructor' excerpt: 'xk6-disruptor: ServiceDisruptor constructor' -weight: 01 +weight: 100 --- # Constructor diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md index 5892038280..3e917ed2fd 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injectgrpcfaults.md @@ -1,18 +1,18 @@ --- title: 'injectGrpcFaults' excerpt: 'xk6-disruptor: ServiceDisruptor.injectGrpcFaults method' -weight: 02 +weight: 200 --- # injectGrpcFaults injectGrpcFaults injects gRPC faults in the requests served by a target Service. -| Parameters | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameters | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [gRPC faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/grpc) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## Options diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md index 01372275cb..6201c5c279 100644 --- a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/injecthttpfaults.md @@ -1,18 +1,18 @@ --- title: 'injectHTTPFaults' excerpt: 'xk6-disruptor: ServiceDisruptor.injectHTTPFaults method' -weight: 03 +weight: 300 --- # injectHTTPFaults injectHTTPFaults injects HTTP faults in the requests served by a target Service. -| Parameters | Type | Description | -| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | +| Parameters | Type | Description | +| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- | | fault | object | description of the [http faults](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/http) to be injected | -| duration | string | duration of the disruption | -| options (optional) | object | [options](#options) that control the injection of the fault | +| duration | string | duration of the disruption | +| options (optional) | object | [options](#options) that control the injection of the fault | ## Options @@ -30,7 +30,7 @@ WARN\[0035\] Request Failed error="read tcp 172.18.0.1:43564->172.18.255.200:80: This is normal and means that one request was "in transit" at the time the faults were injected causing the request to fail due to a network connection reset. - {{% /admonition %}} +{{% /admonition %}} ## Example diff --git a/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md new file mode 100644 index 0000000000..44ebf76430 --- /dev/null +++ b/docs/sources/v0.48.x/javascript-api/xk6-disruptor/servicedisruptor/terminate-pods.md @@ -0,0 +1,24 @@ +--- +title: 'terminatePods()' +description: 'xk6-disruptor: ServiceDisruptor.terminatePods method' +weight: 400 +--- + +# terminatePods() + +`terminatePods` terminates a number of pods that belong to the service specified in the ServiceDisruptor. + +| Parameter | Type | Description | +| --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- | +| fault | object | description of the [Pod Termination fault](https://grafana.com/docs/k6//javascript-api/xk6-disruptor/faults/pod-termination) | + +## Example + + + +```javascript +const fault = { + count: 2, +}; +disruptor.terminatePods(fault); +``` diff --git a/docs/sources/v0.48.x/results-output/end-of-test/custom-summary.md b/docs/sources/v0.48.x/results-output/end-of-test/custom-summary.md index 098e4d35ec..6fd2c13bc3 100644 --- a/docs/sources/v0.48.x/results-output/end-of-test/custom-summary.md +++ b/docs/sources/v0.48.x/results-output/end-of-test/custom-summary.md @@ -72,7 +72,7 @@ They determine where k6 displays or saves the content: The value of a key can have a type of either `string` or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). -You can return mutiple summary outputs in a script. +You can return multiple summary outputs in a script. As an example, this `return` statement sends a report to standard output and writes the `data` object to a JSON file. {{< code >}} diff --git a/docs/sources/v0.48.x/using-k6/scenarios/executors/shared-iterations.md b/docs/sources/v0.48.x/using-k6/scenarios/executors/shared-iterations.md index 9ee6a3687d..ad5486ddbd 100644 --- a/docs/sources/v0.48.x/using-k6/scenarios/executors/shared-iterations.md +++ b/docs/sources/v0.48.x/using-k6/scenarios/executors/shared-iterations.md @@ -9,7 +9,7 @@ weight: 01 The `shared-iterations` executor shares iterations between the number of VUs. The test ends once k6 executes all iterations. -For a shortcut to this executor, use the [vus](https://grafana.com/docs/k6//using-k6/k6-options/reference#vus) and [iterations](https://grafana.com/docs/k6//using-k6/k6-options/reference#iterations) options. +For a shortcut to this executor, use the [`vus`](https://grafana.com/docs/k6//using-k6/k6-options/reference#vus) and [`iterations`](https://grafana.com/docs/k6//using-k6/k6-options/reference#iterations) options. {{% admonition type="note" %}} @@ -18,7 +18,7 @@ VU that executes faster will complete more iterations than slower VUs. To guarantee that every VU completes a specific, fixed number of iterations, [use the per-VU iterations executor](https://grafana.com/docs/k6//using-k6/scenarios/executors/per-vu-iterations). - {{% /admonition %}} +{{% /admonition %}} ## Options diff --git a/src/data/markdown/translated-guides/en/01 Get started/05 resources.md b/src/data/markdown/translated-guides/en/01 Get started/05 resources.md index 14a6e00c20..33b41eae34 100644 --- a/src/data/markdown/translated-guides/en/01 Get started/05 resources.md +++ b/src/data/markdown/translated-guides/en/01 Get started/05 resources.md @@ -30,8 +30,6 @@ If you need a place to learn k6 and test your scripts, you can use these playgro - [pizza.grafana.fun](https://pizza.grafana.fun/). A simple demo webapp. [grafana/quickpizza](https://github.com/grafana/quickpizza) - [k6-http.grafana.fun](https://k6-http.grafana.fun). A simple HTTP Request & Response Service. [grafana/httpbin](https://github.com/grafana/httpbin) -- [k6-php.grafana.fun](https://k6-php.grafana.fun). A simple PHP website. [grafana/test.k6.io](https://github.com/grafana/test.k6.io) -- [test-api.k6.io](https://test-api.k6.io). A demo HTTP REST API with some WebSocket support. [grafana/test-api.k6.io](https://github.com/grafana/test-api.k6.io) - [grpcbin.test.k6.io](https://grpcbin.test.k6.io/). A simple gRPC Request & Response Service. [grafana/k6-grpcbin](https://github.com/grafana/k6-grpcbin) Note that these are shared testing environments - please avoid high-load tests. Alternatively, you can deploy and host them on your infrastructure and run the examples in the repository. @@ -43,4 +41,3 @@ Note that these are shared testing environments - please avoid high-load tests. - [The browser recorder](/test-authoring/create-tests-from-recordings/using-the-browser-recorder/). Make test scripts from browser sessions. - [k6 TypeScript template](https://github.com/grafana/k6-template-typescript) - [Integrations](/integrations/) -