Three small, self-contained k6 scripts for common load-testing
needs that are solved by scripting rather than configuration. Each runs against
https://test.k6.io by default; override the target with TARGET_URL.
Generates a request path from a regex-like pattern on each iteration, so a single VU exercises many distinct URLs.
URL_PATTERN='/api/v(1|2)/items/[a-f0-9]{8}' k6 run regex-urls.jsSupports character classes ([a-z0-9]), \d/\w, quantifiers ({n},
{n,m}, ?, +, *), and simple alternation ((a|b)). It is a small
expander, not a full regex engine — nested groups/classes and unescaped .
(treated as a literal) are out of scope. For full fidelity, bundle
randexp.js with the k6 bundler.
Fires a fixed-size burst of parallel requests, measures the batch duration, then pauses before the next burst.
BURST_SIZE=50 BURST_DELAY=2 BURSTS=30 k6 run burst.jsEach iteration sends BURST_SIZE requests via http.batch() and records a
custom burst_batch_duration trend and burst_requests counter.
Maps a hostname to a specific IP via k6's native hosts option — useful for
hitting one backend behind a CDN/load balancer or testing a node before it is
in rotation.
OVERRIDE_HOST=test.k6.io OVERRIDE_IP=203.0.113.10 k6 run dns-override.jsThe IP is supplied via env var so the script never ships a stale hardcoded
address. With no OVERRIDE_IP, hosts is empty and k6 resolves normally.
URLs / bodies from a file (round-robin):
import http from 'k6/http';
import { SharedArray } from 'k6/data';
import exec from 'k6/execution';
const urls = new SharedArray('urls', () =>
open('./urls.txt').split('\n').filter(Boolean)
);
export default function () {
http.get(urls[exec.scenario.iterationInTest % urls.length]);
}Prometheus remote write (a flag, not a script):
K6_PROMETHEUS_RW_SERVER_URL=http://localhost:9090/api/v1/write \
k6 run --out experimental-prometheus-rw script.js