Skip to content

Wrap collector query errors with %w so CMR timeouts are counted - #193

Draft
Areson wants to merge 1 commit into
Areson/collection-fault-countersfrom
Areson/collector-wrap-w
Draft

Areson wants to merge 1 commit into
Areson/collection-fault-countersfrom
Areson/collector-wrap-w

Conversation

@Areson

@Areson Areson commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #187: review against Areson/collection-fault-counters.

#187 counts collector-timeouts with errors.Is(err, context.DeadlineExceeded), but some built-in collectors wrap query errors with %s or %v. That flattens the error chain, so when those collectors hit their CMR deadline the timeout isn't counted. This PR changes those wraps to %w. The message text stays the same.

Wraps changed in Collect paths:

  • metrics/trx/trx.go: oldest-trx query error (%s → %w)
  • metrics/stmt.current/current.go: query error and row scan error (%s → %w, two places)
  • metrics/wait.io.table/table.go: rows.Columns() error (%v → %w)
  • metrics/repl.lag/pfs.go: replica check query error and lag query error (%s with err.Error() → %w, two places)

The trx and stmt.current changes were flagged in review on #187. I found the wait.io.table and repl.lag ones by grepping metrics/ for %s and %v wraps. Every other match is in Prepare or option parsing, where CMR doesn't apply, so I left those alone.

With this change, the "trx and stmt.current don't yet" caveat comes out of docs/content/api/status.md.

Tests:

  • Added mock.ErrorDB (test/mock/db.go). It returns a *sql.DB whose connections always fail with a given error, so tests can check how a collector wraps errors without MySQL.
  • Added tests for trx, stmt.current and both repl.lag PFS queries. In each, the query fails with an error wrapping context.DeadlineExceeded, and the test asserts errors.Is still matches after Collect wraps it. With the old wraps, all three fail.
  • The wait.io.table Columns() wrap has no unit test. That error only comes from rows that a context cancel closes after the query succeeds, and database/sql closes them in a goroutine, so a test would be racy.
  • The stmt.current scan-error wrap has no test either, for the same reason.

Not changed: collectPFS in repl.lag runs its lag query with context.Background() rather than ctx, so CMR doesn't bound that query today. Fixing that changes behavior, so it should be its own change.

🤖 Generated with Claude Code

collector-timeouts uses errors.Is(err, context.DeadlineExceeded), which
only matches when collectors keep the error chain. trx, stmt.current,
wait.io.table and the repl.lag PFS path wrapped query errors with %s or
%v, so their CMR timeouts weren't counted. Wrap with %w, keeping the
message text, and drop the docs caveat for trx and stmt.current.

Add mock.ErrorDB, a *sql.DB whose connections always fail with a given
error, plus tests that each changed collector keeps the
context.DeadlineExceeded chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant