Skip to content

release-26.2: stmtdiagnostics: add continuous bundle collection with COUNT-based limiting#166159

Merged
dhartunian merged 3 commits intocockroachdb:release-26.2from
dhartunian:davidh/backport-release-26.2-162154
Mar 19, 2026
Merged

release-26.2: stmtdiagnostics: add continuous bundle collection with COUNT-based limiting#166159
dhartunian merged 3 commits intocockroachdb:release-26.2from
dhartunian:davidh/backport-release-26.2-162154

Conversation

@dhartunian
Copy link
Collaborator

@dhartunian dhartunian commented Mar 19, 2026

Backport 3/3 commits from #162154 on behalf of @isaactwong.


Summary

  • Adds request_id column and index to system.statement_diagnostics via schema migration (V26_2_StmtDiagnosticsRequestID), linking bundles to their originating diagnostic request.
  • Implements continuous diagnostic bundle collection for requests with sampling_probability and expires_at set. At insertion time, enforces per-request limits by counting existing bundles (SELECT COUNT(*) WHERE request_id = ?) against the sql.stmt_diagnostics.max_bundles_per_request cluster setting (default 10).
  • During mixed-version upgrades, continuous requests collect without limit enforcement until the migration completes. Pre-migration bundles have NULL request_id, so the counter resets to 0 post-migration.

Commit breakdown

  1. stmtdiagnostics: add request_id schema migration — Version gate, schema change, migration, golden file updates.
  2. stmtdiagnostics: add continuous bundle collection with COUNT-based limiting — Registry implementation, cluster setting, tests.

🤖 Generated with Claude Code


Release justification: missed the branch cut yesterday due to merge conflicts

@dhartunian dhartunian requested review from a team as code owners March 19, 2026 11:53
@blathers-crl
Copy link

blathers-crl bot commented Mar 19, 2026

⚠️ End-of-Life Version Warning

This backport targets 26.2, which is an End-of-Life (EOL) version.

Please verify that backporting to this EOL version is intentional and appropriate. EOL versions no longer receive maintenance updates according to our support policy.


Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@blathers-crl blathers-crl bot added backport Label PR's that are backports to older release branches T-observability labels Mar 19, 2026
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link

@themavik themavik left a comment

Choose a reason for hiding this comment

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

What it does: Adds continuous statement diagnostic bundle collection with COUNT-based per-request limiting, plus request_id schema migration.

Done well: Clear migration path (V26_2_StmtDiagnosticsRequestID) with version gating. The mixed-version behavior (no limit until migration completes, NULL request_id for pre-migration bundles) is sensible. Good test coverage in statement_diagnostics_test.go. Cluster setting sql.stmt_diagnostics.max_bundles_per_request gives operators control.

Suggestion: The SELECT COUNT(*) at insertion time could become a hotspot under heavy continuous collection. Consider whether a cached counter or batched cleanup would help at scale—or document that operators should tune max_bundles_per_request for high-throughput scenarios.

isaactwong and others added 3 commits March 19, 2026 09:23
Add the `request_id` column and index to `system.statement_diagnostics`
via a new cluster version gate `V26_2_StmtDiagnosticsRequestID`. The
`request_id` column links diagnostic bundles to their originating
request, enabling multiple bundles per request for continuous collection.

The migration adds:
- `request_id INT8` column to `system.statement_diagnostics`
- `request_id_idx` index for efficient lookup by request

Resolves: cockroachdb#161001

Release note: None

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…miting

Implement continuous diagnostic bundle collection for requests that have
both `sampling_probability` and `expires_at` set. At bundle insertion
time, enforce the per-request limit by counting existing bundles via
`SELECT COUNT(*) FROM system.statement_diagnostics WHERE request_id = ?`
and comparing against the `sql.stmt_diagnostics.max_bundles_per_request`
cluster setting (default 10). This replaces a previous design that used
an in-memory counter and a `collections_remaining` DB column.

The `max_bundles_per_request` setting now requires a positive integer
(minimum 1); unlimited collection is no longer supported.

During mixed-version rolling upgrades, continuous requests collect
without limit enforcement until the migration completes and `request_id`
becomes available. Pre-migration bundles have NULL `request_id`, so
the post-migration counter effectively resets to 0.

Resolves: cockroachdb#161001

Release note (ops change): Statement diagnostics requests with
sampling_probability and expires_at now collect up to 10 bundles
(configurable via sql.stmt_diagnostics.max_bundles_per_request) instead
of a single bundle. Set the cluster setting to 1 to restore single-bundle
behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address feedback from dhartunian's review:

- Update copyright year from 2025 to 2026 in new migration file
- Refactor duplicate UPDATE statement in statement_diagnostics.go
  to extract SQL execution after if/else
- Remove unused hasMatchingIndex() function and export
- Test improvements:
  - Remove unnecessary time.Sleep in test
  - Remove redundant count re-query after SucceedsSoon
  - Replace two require calls with single require.Equal
  - Extract SQL execution outside SucceedsSoon loop to prevent
    false positives from accumulated statements (lines 1610, 1887)

Informs: cockroachdb#161001

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dhartunian dhartunian force-pushed the davidh/backport-release-26.2-162154 branch from c3b0ba9 to 79de19e Compare March 19, 2026 13:23
@dhartunian dhartunian merged commit cdbf8ae into cockroachdb:release-26.2 Mar 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches T-observability target-release-26.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants