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

Fix Execution context variables docs #1660

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions docs/sources/next/using-k6/execution-context-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ The module provides test-execution information via three properties:
| [scenario](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#scenario) | The current running scenario |
| [vu](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#vu) | The current VU and iteration |

> k6 v0.34.0 introduced the **k6/execution** module.
> If you are using a version k6 that does not have this module,
> refer to the [\_\_VU and \_\_ITER](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/execution-context-variables#__vu-and-__iter-discouraged) section.

## Example: log all context variables

If you want to experiment with what each context variable looks like as a test runs,
Expand Down Expand Up @@ -81,29 +77,28 @@ VU tags: ${exec.vu.tags}`);

For detailed reference, refer to the [k6/execution module](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution).

## Examples and use cases
## Additional examples

- [Getting unique data once](https://grafana.com/docs/k6/<K6_VERSION>/examples/data-parameterization#retrieving-unique-data)
- [Timing operations](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#timing-operations)
- [Executing different code blocks](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#script-naming)

{{< collapse title="_VU and _ITER (discouraged)" >}}

⚠️ **\_\_VU** and **\_\_ITER** are both global variables with execution-context information that k6 makes available to the test script.
{{< admonition type="note" >}}

### \_\_ITER
k6 v0.34.0 introduced the **k6/execution** module. If you are using a version of k6 that doesn't have this module, use `__VU` and `__ITER`.

A numeric counter with the current iteration number for a specific VU. Zero-based.
{{< /admonition >}}

### \_\_VU
`__VU` and `__ITER` are both global variables with execution-context information that k6 makes available to the test script.

Current VU number in use. k6 assigns the value incrementally for each new VU instance, starting from one.
The variable is 0 when executing the setup and teardown functions.
- `__ITER`: A numeric counter with the current iteration number for a specific VU. Zero-based.
- `__VU`: Current VU number in use. k6 assigns the value incrementally for each new VU instance, starting from one. The variable is 0 when executing the setup and teardown functions.

### Running in k6 Cloud

When you run tests in [k6 Cloud](https://grafana.com/docs/grafana-cloud/testing/k6/), the **\_\_VU** value is per server/load generator.
Read the details in the [cloud docs](https://grafana.com/docs/grafana-cloud/testing/k6/reference/cloud-ips/).
When you run tests in [Grafana Cloud k6](https://grafana.com/docs/grafana-cloud/testing/k6/), the **\_\_VU** value is per server/load generator.

### Examples

Expand Down Expand Up @@ -136,7 +131,8 @@ export default function () {

{{< /collapse >}}

## Grafana Cloud k6 environment variables
## Grafana Cloud k6 context variables

Grafana Cloud k6 injects additional context variables into a running cloud test. These variables provide information about the server (`K6_CLOUDRUN_INSTANCE_ID`), load zone (`K6_CLOUDRUN_LOAD_ZONE`),instance ID (`K6_CLOUDRUN_INSTANCE_ID`), and cloud distribution (`K6_CLOUDRUN_DISTRIBUTION`).

If you run tests in k6 Cloud, you have additional environment variables that tell you the server, load zone, and distribution of the currently running test.
[Read about cloud environment variables](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/cloud-scripting-extras/cloud-environment-variables/).
Refer to [Cloud execution context variables](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/cloud-scripting-extras/cloud-execution-context-variables/) for more details.
28 changes: 12 additions & 16 deletions docs/sources/v0.52.x/using-k6/execution-context-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ The module provides test-execution information via three properties:
| [scenario](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#scenario) | The current running scenario |
| [vu](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#vu) | The current VU and iteration |

> k6 v0.34.0 introduced the **k6/execution** module.
> If you are using a version k6 that does not have this module,
> refer to the [\_\_VU and \_\_ITER](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/execution-context-variables#__vu-and-__iter-discouraged) section.

## Example: log all context variables

If you want to experiment with what each context variable looks like as a test runs,
Expand Down Expand Up @@ -81,29 +77,28 @@ VU tags: ${exec.vu.tags}`);

For detailed reference, refer to the [k6/execution module](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution).

## Examples and use cases
## Additional examples

- [Getting unique data once](https://grafana.com/docs/k6/<K6_VERSION>/examples/data-parameterization#retrieving-unique-data)
- [Timing operations](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#timing-operations)
- [Executing different code blocks](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-execution#script-naming)

{{< collapse title="_VU and _ITER (discouraged)" >}}

⚠️ **\_\_VU** and **\_\_ITER** are both global variables with execution-context information that k6 makes available to the test script.
{{< admonition type="note" >}}

### \_\_ITER
k6 v0.34.0 introduced the **k6/execution** module. If you are using a version of k6 that doesn't have this module, use `__VU` and `__ITER`.

A numeric counter with the current iteration number for a specific VU. Zero-based.
{{< /admonition >}}

### \_\_VU
`__VU` and `__ITER` are both global variables with execution-context information that k6 makes available to the test script.

Current VU number in use. k6 assigns the value incrementally for each new VU instance, starting from one.
The variable is 0 when executing the setup and teardown functions.
- `__ITER`: A numeric counter with the current iteration number for a specific VU. Zero-based.
- `__VU`: Current VU number in use. k6 assigns the value incrementally for each new VU instance, starting from one. The variable is 0 when executing the setup and teardown functions.

### Running in k6 Cloud

When you run tests in [k6 Cloud](https://grafana.com/docs/grafana-cloud/testing/k6/), the **\_\_VU** value is per server/load generator.
Read the details in the [cloud docs](https://grafana.com/docs/grafana-cloud/testing/k6/reference/cloud-ips/).
When you run tests in [Grafana Cloud k6](https://grafana.com/docs/grafana-cloud/testing/k6/), the **\_\_VU** value is per server/load generator.

### Examples

Expand Down Expand Up @@ -136,7 +131,8 @@ export default function () {

{{< /collapse >}}

## Grafana Cloud k6 environment variables
## Grafana Cloud k6 context variables

Grafana Cloud k6 injects additional context variables into a running cloud test. These variables provide information about the server (`K6_CLOUDRUN_INSTANCE_ID`), load zone (`K6_CLOUDRUN_LOAD_ZONE`),instance ID (`K6_CLOUDRUN_INSTANCE_ID`), and cloud distribution (`K6_CLOUDRUN_DISTRIBUTION`).

If you run tests in k6 Cloud, you have additional environment variables that tell you the server, load zone, and distribution of the currently running test.
[Read about cloud environment variables](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/cloud-scripting-extras/cloud-environment-variables/).
Refer to [Cloud execution context variables](https://grafana.com/docs/grafana-cloud/testing/k6/author-run/cloud-scripting-extras/cloud-execution-context-variables/) for more details.
Loading