Expand description
Minimal runtime control API — k6 REST /v1/status parity.
Binds 127.0.0.1:<port> and serves:
GET /v1/status→ k6 JSON:API shape{"data":{"type":"status","id":"default","attributes":{...}}}(vus / vus-max / paused / running / stopped / tainted)PATCH /v1/status→ k6 envelope{"data":{"attributes":{...}}}or a flat{"vus":N,"max":M,"vus-max":N,"paused":bool}— adjusts the externally-controlled scheduler’s VU pool / pause state at runtime.maxis clamped to the configuredmax_vusceiling, so a client can never grow the pool past the run’s cap. Bothmax(legacy) andvus-max(k6’s JSON:API field name) are accepted, and the status doc emits BOTH so old and new clients work.POST /v1/stop→ stop the run (k6 extension — also achievable viaPATCH /v1/status {"stopped":true})PATCH /v1/stop→ k6 envelope{"data":{"attributes":{"stopped":true}}}— same as the PATCH /v1/status path, but on the/v1/stoproute.GET /v1/metrics→ k6 JSON:API envelope of current metric valuesGET /v1/groups→ k6 JSON:API envelope of the group hierarchyGET /v1/setup→ the current setup data (or null)PUT /v1/setup→ set the setup data from the request bodyPOST /v1/setup→ run the script’s setup() and return the resultPOST /v1/teardown→ run the script’s teardown()
Everything else returns 404. This is intentionally dependency-free: a hand-rolled HTTP/1.1 reader keeps the control surface small and avoids pulling a web framework into the engine for one endpoint.
§SUPERSET (k6 v2 divergence)
k6 v2 turns the REST API off by default (GlobalFlags.Address → "").
Tropel serves it whenever a --control-port is configured (for any executor,
not just externally-controlled) — a deliberate SUPERSET so integrators
(knockport, scripts, or platform operators) can always inspect a live run
without reconfiguring the executor type. The HEADER_LINE_LEN / BODY_SIZE
caps are the bounds that keep this safe (TR-604).
Structs§
- Control
ApiState - Shared state for the control API: the scheduler (mutable run state) and read-only handles used by the read-only routes.
Functions§
- serve_
control_ api - Handle the control server task. Runs until the listener errors or the task is aborted by the scenario finishing.