Skip to content

fix(soak): classify k6 failures by HTTP status, and attribute the residual (#887) - #915

Merged
bpalermo merged 2 commits into
mainfrom
fix/887-k6-failure-attribution
Sep 23, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/887-k6-failure-attribution

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Fixes #887.

This reframes the issue

#887 asks for detail on an opaque other bucket. The residual was not opaque because detail was missing — it was misfiled.

classify() tested the HTTP status only inside an error_code === 0 branch. k6 sets a non-zero error_code for an HTTP error response, so those status tests were unreachable for every response they were written for:

what arrived old error_code old class correct class
404 1404 proto (caught by the 1400–1499 range) http_4xx
503 / 504 1503 / 1504 other (fell off the end) http_5xx

http_4xx and http_5xx could never be incremented at all. Both counters were dead code from #846 onward, which is why every soak reported http_4xx: 0, http_5xx: 0 — a zero that looked like evidence and was not (cf. aether#853, and the new gotcha 10 in the README).

The rev234 run's 33 other failures were reconciled against the source proxies' access logs in VictoriaLogs: 33 of 33 were plain 504/UT responses, 31 on main-worker-01 and 2 on main-worker-03, matching the two runners that reported 31 and 2 exactly.

k6 error-code semantics — verified, not assumed

I did not take 1000 + status on trust. Measured directly on k6 v2.3.0 against fixed-status local targets:

PROBE 200            status=200 error_code=0    error=""
PROBE 302-noredirect status=302 error_code=0    error=""
PROBE 404            status=404 error_code=1404 error=""
PROBE 503            status=503 error_code=1503 error=""
PROBE 504            status=504 error_code=1504 error=""
PROBE conn-refused   status=0   error_code=1212 error="dial: connection refused"
PROBE dns-nxdomain   status=0   error_code=1101 error="lookup: no such host"
PROBE timeout        status=0   error_code=1050 error="request timeout"

Two consequences beyond the reported bug:

  • 1400–1499 is genuinely ambiguous in k6 — it means both "HTTP/2 protocol error" and "1000 + a 4xx status". Testing status first resolves it: a real HTTP/2 error leaves status at 0, so only it can now reach the proto test.
  • A timeout is 1050, which no range in the function would catch. It is saved only by the res.error string test, which is why that test runs first. The existing comment claimed this without a number; it now has one.

Which mechanism exposes the tag breakdown — verified

The task asked me to find out whether k6 exposes per-tag submetrics in handleSummary rather than guess. Three probes on k6 v2.3.0:

  1. data.metrics carries no per-tag submetrics. A counter incremented with {endpoint, code, status} appears as exactly one entry, aggregated across every tag value:
    PROBE_METRIC_KEYS=["probe_fail"]
    PROBE_FAIL_SHAPE={"type":"counter","contains":"default","values":{"rate":93.2,"count":12}}
    
  2. Named counters cannot be created per observed combination either. new Counter() in a VU throws:
    DYNAMIC_COUNTER_IN_VU_CONTEXT=THREW: GoError: metrics must be declared in the init context
    
    So the suggested "separate named counters" fallback has the same constraint as tags: the key space must be enumerated at init.
  3. A submetric does appear once declared as a threshold — including multi-tag ones, and including with count: 0 when never hit:
    PROBE_METRIC_KEYS=["probe_fail{status:999}","probe_fail{status:503}","probe_fail{status:302}","probe_fail{code:0,status:302}","probe_fail"]
      probe_fail{status:999}        -> {"count":0,"rate":0}
      probe_fail{status:503}        -> {"count":6,...}
      probe_fail{code:0,status:302} -> {"count":6,...}
    

So (3) is the mechanism — but it is not free, and I measured before committing to it. ~1,950 declared submetrics cost +28–33MiB RSS and +0.5–2% of a core continuously. Both land on the wrong thing: that CPU is the same order as the fleet-core deltas the profiling passes exist to detect (#673 was closed on −0.070 fleet cores), and the memory eats a container this repo has already OOM-killed mid-soak (see the resources comment in k6-runner.yaml).

Hence a small declared key space (281 submetrics) for exact totals — measured at +5MiB RSS and +0.9s CPU over a 180s/60rps run, mostly one-off startup (the same delta over 60s was +0.65s), so the steady-state share is well under 1% of a core — plus a bounded verbatim AETHER_FAIL sample for the combinations it cannot enumerate. The sample costs nothing in the healthy case, because the healthy case is zero failures, and its timestamps are what line a burst up against a proxy roll.

Red-state evidence

k6 is installed locally (v2.3.0), so this is a real run, not a synthesised data object. The unmodified production file was driven against local fixed-status targets using k6's hosts option via --config, so nothing in the script was edited for the test.

Targets: svc-1→504, svc-2→404, svc-3→302, svc-4→refused, echo→200, mixed-svc→unresolvable.

Before (origin/main, same targets, same k6):

  dns       200
  conn      199
  tls       0
  timeout   0
  proto     224      <-- the 404s, misfiled
  http_4xx  0        <-- unreachable
  http_5xx  0        <-- unreachable
  other     423      <-- the 504s + the 302s
  TOTAL     1046

After:

  dns       210
  conn      208
  tls       0
  timeout   0
  proto     0
  http_4xx  202
  http_5xx  216
  other     208      <-- only the genuine 302s remain
  TOTAL     1044

classified=1044 of http_req_failed≈836

--- by target (#887) ---
       216  http_5xx http://svc-1.aether-test.aether.internal:18081/
       210  dns http://mixed-svc.aether-test.aether.internal:18081/
       208  conn http://svc-4.aether-test.aether.internal:18081/
       208  other http://svc-3.aether-test.aether.internal:18081/
       202  http_4xx http://svc-2.aether-test.aether.internal:18081/

--- by reason: k6 error_code / HTTP status (#887) ---
       216  code=1504 status=504
       210  code=1101 status=0
       208  code=0 status=302
       208  code=1212 status=0
       202  code=1404 status=404

attributed=1044 of classified=1044

code=1504 status=504 is the rev234 residual's exact fingerprint, now named by the instrument instead of requiring an access-log reconciliation.

The per-event lines carry the full tuple:

AETHER_FAIL {"t":"2026-09-23T10:04:30.104Z","class":"http_5xx","endpoint":"http://svc-1...:18081/","code":1504,"status":504,"error":"","vu":2,"n":10,"truncated":true}
AETHER_FAIL {"t":"2026-09-23T10:04:30.535Z","class":"conn","endpoint":"http://svc-4...:18081/","code":1212,"status":0,"error":"dial: connection refused","vu":1,"n":9,"truncated":false}

And the AETHER_METRIC marker is still one parseable line, with the existing keys untouched:

AETHER_METRIC k6_failure_classes={"counts":{...},"total":1044,"reqs":3339,"failRate":0.2503...,"byEndpoint":{...},"byReason":{"code=0 status=302":208,"code=1404 status=404":202,"code=1504 status=504":216,...},"attributed":1044}

The timeout path, separately exercised

I restructured the branch the timeout test lives in, so I drove it rather than reasoning about it. The only change to the copy under test was adding timeout: '400ms' to the request (there is no global k6 option for it); svc-1 pointed at a server that always answers 3s late.

  timeout   81
  TOTAL     81
--- by reason ---
        81  code=1050 status=0
attributed=81 of classified=81

That is the code no numeric range would have caught, classified correctly by the error string.

The new reconciliation is falsifiable

This change is an instrument, so its own gate must be shown capable of failing. attributed=A of classified=N under-reports when a code/status pair is not in the declared key space. Driving svc-1 to return 599 (not an IANA-registered status, so deliberately undeclared):

  http_5xx  595
  TOTAL     595

--- by reason: k6 error_code / HTTP status (#887) ---
                                  <-- empty: the pair is undeclared

attributed=0 of classified=595
  GAP: an undeclared code/status pair reached a class -- grep AETHER_FAIL to name it

and the sample line names it verbatim: {"class":"http_5xx","code":1599,"status":599,...}. The gate fires, and the escape hatch works.

Green-state control

All six targets healthy, 30,000 iterations — the instrument does not fabricate:

  TOTAL     0
classified=0 of http_req_failed≈0
--- by target (#887) ---
  (none)
--- by reason: k6 error_code / HTTP status (#887) ---
  (none)
attributed=0 of classified=0

No GAP: line, no AETHER_FAIL lines.

Not covered

tls and proto were not driven end-to-end — forcing a genuine TLS handshake failure or an HTTP/2 protocol error against a loopback stub was not worth the fixture. Their range tests are unchanged from #846 apart from now being reachable only when status == 0, which is the intended narrowing.

classified=N can now exceed http_req_failed≈M when 3xx responses are involved, because k6 counts only status >= 400 as failed while classify() treats a 3xx as a failure. That is pre-existing (the before-run shows 1046 vs 839) and is an artefact of the synthetic 302 target, not a regression.

Constraints

  • Single-line AETHER_METRIC marker kept and extended, existing keys intact.
  • stdout only; no files written.
  • No remote imports; the status registry and code list are hand-rolled.
  • Cross-VU aggregation is done entirely through metric names/declared submetrics; the only per-VU state is the sample cap, which is per-event output rather than an aggregate.
  • No shell touched, but bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //e2e/soak:soak_shell passes.

README updated: the collection recipe, both reconciliation lines, and a new gotcha 10 on why a zero in a class is only evidence once the class is shown to be reachable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…idual (#887)

The k6 soak's failure classifier could not increment `http_4xx` or
`http_5xx` at all. Its status tests sat inside an `error_code === 0`
branch, and k6 sets a NON-ZERO error_code for an HTTP error response --
verified on k6 v2.3.0, a 404 arrives as 1404, a 503 as 1503, a 504 as
1504, i.e. 1000 + status. Every 4xx therefore fell through to the
1400-1499 range test and was filed as `proto`; every 5xx fell off the
end into `other`.

That is where the last two soaks' unattributable residual came from.
The rev234 run's 33 `other` failures reconcile 33-of-33 against the
source proxies' access logs in VictoriaLogs as plain 504/UT responses,
31 on main-worker-01 and 2 on main-worker-03, matching the two runners
that reported 31 and 2. They were never mysterious; they were misfiled.

classify() now tests status first: a response carrying an HTTP status
was received, and whatever error_code k6 derived from it restates the
status rather than adding information. That also resolves a real
ambiguity in k6's numbering, where 1400-1499 means both "HTTP/2
protocol error" and "1000 + a 4xx status" -- a genuine HTTP/2 error
leaves status at 0, so only it can now reach the `proto` test. The
1500-1599 range is handled explicitly instead of falling to `other`,
and `other` keeps its meaning of "genuinely unrecognised".

The summary now also breaks every non-zero class down by target and by
reason (the exact error_code/status pair), and logs each failure
verbatim as AETHER_FAIL with a timestamp -- the field that lines a
burst up against a specific proxy roll, which is the only way to see
#823 given the external prober rides one keep-alive connection (#846).

How the breakdown is produced, verified rather than assumed:
handleSummary's `data.metrics` carries NO per-tag submetrics, and
metrics cannot be created outside the init context, so neither the
existing tags nor a counter-per-combination can be read back. A
submetric does appear once declared as a threshold, so a small key
space (281 submetrics, +5MiB RSS and well under 1% of a core) is
declared up front for exact totals, with the bounded verbatim sample
covering combinations it cannot enumerate. A second reconciliation
line, `attributed=A of classified=N`, reports that case rather than
losing it.

The AETHER_METRIC marker stays a single machine-parseable line with its
existing keys intact; byEndpoint, byReason and attributed are added.
No files are written and no remote imports are added.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo enabled auto-merge (squash) September 23, 2026 10:23
@bpalermo
bpalermo merged commit 76c2dca into main Sep 23, 2026
22 checks passed
@bpalermo
bpalermo deleted the fix/887-k6-failure-attribution branch September 23, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

soak: the k6 'other' failure class carries no detail, so the residual it catches is unattributable

1 participant