Skip to content

sink: optional verdict and result joins, pending hold, column bounds and a run summary - #11

Merged
pattu777 merged 3 commits into
mainfrom
sink-join-hold-summary
Nov 27, 2026
Merged

pattu777 merged 3 commits into
mainfrom
sink-join-hold-summary

Conversation

@MihirR-BS

Copy link
Copy Markdown
Collaborator

Adds optional sink features so a caller can join per-request results and verdicts into request rows, hold a row until its result arrives, bound string and numeric columns, and get a one-line run summary at stop. Every new key is optional: with none configured, rows are byte-for-byte what they were (covered by golden-row tests in bounds_test.go).

New config keys (documented in the README sink section)

  • correlation.verdictMetric + computed:failedVerdict (1 failed / 0 ok / -1 none or WebSocket row)
  • correlation.joinMetrics: a result sample's metadata is merged into its request row through the request-id index; results with no row are counted as unjoined
  • hold: a request row marked pending waits for its result, or until max (never above staleAfter), then onExpireMeta applies
  • Column bounds: type: "uint" with min/max, maxRunes, distinct (per-process value budget with an overflow value, optional bounded partitions), when, joinDefault
  • cardinality.exemptMetrics
  • summary: a k=v;… file written at stop, cleared at start, written even when the final flush fails, created with O_EXCL (never through a symlink)
  • Check rows dropped on buffer overflow, requeue cut or still undelivered at stop are counted

Tests: new verdict_test.go, join_test.go, hold_test.go, bounds_test.go, summary_test.go, plus config-validation cases (every new section rejects unknown keys).

Not run locally: no Go toolchain on the authoring machine, so this PR's CI (gofmt, go vet, go test -race) is the first compile. Follow-up commits fix whatever it reports.

The caller-side config that uses these keys ships separately and only after this is on main, because the config parser rejects unknown keys.

🤖 Generated with Claude Code

…and a run summary

All new keys are optional; with none of them configured the rows are
byte-for-byte unchanged.

- correlation.verdictMetric + computed:failedVerdict (1 / 0 / -1)
- correlation.joinMetrics: merge a result sample's metadata into its
  request row through the request-id index; unmatched results counted
- hold: keep a pending request row until its result arrives or the
  hold expires, then apply onExpireMeta
- column bounds: type uint with min/max, maxRunes, distinct-value
  budgets with an overflow value, when conditions, joinDefault
- cardinality.exemptMetrics
- summary: one-line k=v file written at stop (also when the final
  flush fails), never through a symlink
- check rows dropped on overflow / requeue / undelivered are counted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MihirR-BS
MihirR-BS requested a review from a team as a code owner November 26, 2026 11:17
@MihirR-BS
MihirR-BS requested a review from Ritik-soh November 26, 2026 11:17
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: a6b77b5c-5c98-4233-8f3d-ced983bc732f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

MihirR-BS and others added 2 commits November 26, 2026 16:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MihirR-BS

Copy link
Copy Markdown
Collaborator Author

Claude review — head e6b3c4d

No blockers. CI is green (test, CodeQL, Semgrep). Standalone review of the production diffs; the new test files were not read line by line.

Medium — summary.keys.seen can silently disable other features

internal/sink/sink.go (AddMetricSamples) intercepts a seen metric and continues before the script-data and iteration-marker handling. validateSummary (internal/sink/config.go) only rejects a seen metric that is already a row metric, so iterations and the data counters are not covered. seen: {x: "iterations"} would stop the iteration marker from ever firing, with no validation error.
Fix: add iterations, data_sent and data_received (whatever isDataMetric covers) to the reserved roles in validateSummary.

Low — unjoined can be off in two edge cases (addJoin, internal/sink/buffer.go)

  • A late join for a row that was shed on overflow or dropped as stale is not counted as expected (suppressed or counted depending on the pending marker).
  • A join that arrives before its request row is counted as unjoined; if that row is then held and expires, it is counted again.

Late-join suppression also depends on the caller's join sample carrying the pending marker. The README says so but nothing validates it. Fine to leave as documented.

Nits

  • A uint column takes only the first non-empty source: an invalid value there writes 0 instead of falling back to the next source. Matches "first non-empty wins", but worth a README line.
  • The PR description says CI is "the first compile"; CI has already passed on this head, so update it before merge.

Looks solid

O_EXCL summary file after remove (no symlink follow); hold expiry capped at staleAfter and released at stop; bounded distinct budgets fixed in arrival order; Duration rejects non-positive values; golden-row tests cover unchanged output without the new keys.

🤖 Generated with Claude Code

@MohitSinghBS MohitSinghBS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at e6b3c4db

Nothing here blocks merging: every new key is optional, and nothing sets them until the caller config ships. The first finding needs a fix before that config turns on joinMetrics.

Checked locally: gofmt and go vet are clean, the sink and config tests pass with -race, and sink coverage is 91.8%. With no new keys set, a plain column renders exactly as before.

Against the GraphQL implementation (#3788)

This is the config-driven version of what #3788 adds to plu-clickhouse (buffer.go / client.go) and k6-req-capturer.js. I compared each part:

#3788 (plu-clickhouse) This PR Matches?
http_req_failed → reqFailed (1 / 0 / -1) verdictMetric + computed:failedVerdict yes
lts_gql_result merged into its row by ltsReqId joinMetrics + bytesIdMetaKey yes, except finding 1
hold on ltsGqlPending=1, gqlHold capped at stale-after, expiry → state 3 + unattributed hold + onExpireMeta, max capped at staleAfter yes
a late result carrying the pending marker is not counted twice same yes
state outside 1–3 → 3; code and code source only when state = 2 uint 1–3 + joinDefault "3"; when state == "2" yes
500 operation names / 200 runes; 100 codes / 80 runes; message-derived codes get their own budget distinct + maxRunes, partitionBy code source with partitions ["2"] yes
op type / shape / batch size only when there is an operation; batch size only when shape = 2 when on the operation (+ shape = 2) yes
lts_gql_calls / lts_gql_result left out of the series budget, exact names only cardinality.exemptMetrics yes
signal line requestNameLimitHit;assertionsDropped;graphqlCalls;graphqlUnattributed;graphqlSampleN summary; the key order gives the same line yes
results from http.batch (no id) counted by value, 1 to 1e6 unjoined adds the sample value yes

Findings

1. Medium: a result sample can overwrite its row's URL with another request's URL. This differs from #3788.

  • addJoin (buffer.go:358-376) merges every kept metadata key from the result sample into the row, and urlMetaKey is always kept. addGraphqlResult in #3788 only sets state, code and code source.
  • The capturer does not clear urlFull after a sync request, and the result of an asyncRequest is emitted in .then. Take this script:
    1. p = http.asyncRequest(<graphql>). The capturer clears urlFull, so this row has no urlFull.
    2. http.get(otherUrl) sets urlFull to otherUrl.
    3. await p. The result is emitted while urlFull is still otherUrl.
  • The GraphQL row then reads url = "POST <otherUrl>". I reproduced this with a throwaway test against withOpJoin: the row came out as "url":"POST https://other.example.com/health" with requestName POST https://api.example.com/graphql.
  • Suggested fix: limit what a join sample can set, for example a correlation.joinMetaKeys allowlist (state, code, code source), or never take urlMetaKey from a join sample. A capturer-side workaround also works: clear urlFull around emitAsyncGraphqlResult.

2. Low: redirect hops share ltsReqId. #3788 behaves the same way.

  • The id index keeps only the last hop, so with the hold set, the first hop of a redirected asyncRequest waits 30s and is written as state 3 (not checked), and counted unattributed.
  • removeEntry (buffer.go:396-401) also deletes the id when it already points at a later hop.
  • Suggested fix: delete the index only when it still points at this entry, and release the earlier hop's hold when a later hop takes the id over. I confirmed both with a throwaway test.

3. Nit: the summary file's folder is never created. writeSummary opens the path with O_EXCL, but marker files go through writeFile, which runs MkdirAll first. In a folder nothing else creates, the summary is never written and only a log line says why.

4. Note: exempt metrics match by exact name. This is the same in #3788. A script that records its own lts_gql_result adds series the limit never counts.

For the caller config PR

  • Overflow values must be exactly ~lts.otherOperations and ~lts.otherCodes, since the BE readers label those strings (config/constants.js).
  • summary.path needs a per-process path, like <PLU_CLICKHOUSE_SIGNALS_FILE>_<K6_POD_INSTANCE_ID>, so the primary and the RTLI secondaries don't overwrite each other.
  • Set the GraphQL summary keys, failedVerdict and the joins only on graphql_reporting pods. Set graphqlSampleN only while the response check is on.

@pattu777
pattu777 merged commit 532269e into main Nov 27, 2026
7 checks passed
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.

3 participants