Registry Mirror
Skip to content

Conversation

@ridhoq

@ridhoq Ridwan Hoq (ridhoq) commented Oct 8, 2026 •

Copy link
Copy Markdown

Expose PostgreSQL pool telemetry through ateapi's existing OpenTelemetry pipeline so database scale tests can distinguish connection acquisition delays from subsequent database work.

Fixes #2288. First slice of #2287.

The four instruments are db.client.connection.count (used and idle connections), db.client.connection.max (capacity), db.client.connection.wait_time (acquisition duration and outcomes), and db.client.connection.pending_requests (acquisitions in progress). Pool names are bounded to main, watch, owner, and probe. Existing query tracing is preserved, and metrics do not depend on trace sampling.

Acquisition duration and pending requests include connection creation and validation, not just queueing. They exclude SQL execution and time holding a connection. The histogram records successful and unsuccessful attempts, with outcomes success, cancelled, timeout, and error. Only error carries error.type: pool_closed, connect_error, or _OTHER. A pgconn connection deadline remains connect_error, even when it wraps a context deadline. Connection-hook failures remain _OTHER.

Occupancy and capacity callbacks unregister on shutdown and failed initialization preserves pool ownership. The change includes registry entries, operator guidance, and collector E2E expectations. Pending requests extends the original issue scope to expose acquisition backlogs before attempts complete. No dependency versions change.

Validation

Rebased onto 11afdf64. On 7a289f36:

  • Race-enabled store integration tests and affected helper tests passed with Docker required. Fifty focused repeats passed, followed by a single-CPU shuffled run.
  • All repository verifiers passed. The linter needed a serial-runner retry with a longer timeout because another linter was running.
  • The deployed TestPlatformMetricsEmitted passed in 32.51 seconds in a disposable Kind cluster with gVisor, Envoy, and the bundled credential provider. A live collector scrape confirmed all four metric families for all four pools. The disposable cluster was removed.
  • The full go test -race ./... run had one failure in unchanged internal/benchmarking/glutton.TestUseCPUBurnsCPUTime: it measured 129.25ms of user CPU against a 150ms minimum while builds and other tests were running. Twenty isolated repeats passed. The full run was not green.

The full deployed E2E suite and microVM lane have not been run locally. CI still needs to run on the updated head.

Prepared with GitHub Copilot CLI for implementation, review, rebasing, and local validation.

@ridhoq Ridwan Hoq (ridhoq) changed the title Expose PostgreSQL pool saturation and connection acquisition metrics ateapi: expose PostgreSQL pool saturation and connection acquisition metrics Oct 8, 2026
@ridhoq
Ridwan Hoq (ridhoq) marked this pull request as ready for review October 8, 2026 21:22
@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) PTAL when you get a chance, thanks!

@maxsmythe Max Smythe (maxsmythe) added area/observability kind/feature An enhancement / feature request or implementation labels Oct 9, 2026

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.

Thanks, added some comments!

Comment thread go.mod Resolved
Comment thread docs/metrics/registry/metrics.yaml Resolved
Comment thread internal/ateattr/ateattr.go Resolved
@ridhoq

Ridwan Hoq (ridhoq) commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) Thanks for all of the reviews! While reviewing the timeout handling, I found another distinction worth fixing. Pgconn's own connection timeout can return a ConnectError wrapping context.DeadlineExceeded while the caller's context is still active. My previous ordering classified that as a caller timeout rather than error with error.type=connect_error.

The classifier now recognizes pool and connection errors before checking wrapped context errors. I added tests using a controlled dial function to exercise an internal connection timeout and caller cancellation during connection creation. The internal timeout test uses 1 ms and passed 150 consecutive runs with race detection.

I also ran TestPlatformMetricsEmitted locally against commit 1bae1630 in a disposable Kind cluster with gVisor and Envoy. It passed, and the collector scrape included all four PostgreSQL metric families for main, watch, and owner.

Could you please queue the required CI checks, including run-tests and e2e-test, for the current PR head if you have permission? The local run covered the focused metrics suite, not the full E2E suite or microVM lane.

@krisztianfekete

Copy link
Copy Markdown
Collaborator

Thanks Ridwan Hoq (@ridhoq), they should be running soon!

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) There was an E2E test failure which was fixed upstream, so I rebased onto latest main to pick it up. Could you rerun CI for the updated branch, please?

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) ran into an unrelated flakey test documented in #1076. E2E tests passed so hopefully another run should show up green.

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) ah, looks like #2356 just merged and caused a conflict here. One more run and it should be good to merge if you don't have any other feedback. Thanks!

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) just got this rebased and updated if you have a chance to take a look. Thanks!

@ridhoq
Ridwan Hoq (ridhoq) force-pushed the postgres-pool-metrics branch 2 times, most recently from 750fadf to 902bde9 Compare October 26, 2026 23:27

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.

Thanks, added one comment, other than that it just needs tests passing and a rebase!

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) looks like checks are passing if you're able to take one more look! Thanks!

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.

Thanks!

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) this is ready for another review and CI run. Now that 1.0 is released, I think it’s okay to merge this. Could you reapprove and queue CI when you get a chance? Thanks!

@krisztianfekete

Copy link
Copy Markdown
Collaborator

Krisztian F (@krisztianfekete) this is ready for another review and CI run. Now that 1.0 is released, I think it’s okay to merge this. Could you reapprove and queue CI when you get a chance? Thanks!

Thanks Ridwan Hoq (@ridhoq), this looks good and the content is unchanged from what I approved on 10/30. Per the post-1.0 plan on ate-dev (see mailing list for more details), main only takes urgent stability, correctness and security fixes until 11/17, and many maintainers are at KubeCon this week. This change seems to be fine for v1.1. Once the repo reopens on 11/18, please rebase if needed and I'll re-approve and run CI then. It will land on main for v1.1.x and won't be cherry-picked to release-1.0, since it's a feature.

@ridhoq

Copy link
Copy Markdown
Author

Krisztian F (@krisztianfekete) now that the repo is open again, is there anything else needed before this can merge? I've addressed your review comments and checked that it still merges cleanly with latest main. Could you take another look and queue CI when you get a chance? Thanks!

Ridwan Hoq (ridhoq) and others added 12 commits November 30, 2026 20:07
Report pool occupancy, effective capacity, and acquisition duration and outcomes for the main, watch, and owner pools. Pool hooks capture implicit acquisitions independently of trace sampling, separating connection acquisition delays from subsequent database work.

Preserve query tracers and pool ownership, unregister observations on shutdown, and cover SDK collection and real OTLP collector export with PostgreSQL integration tests.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Expose the standard pending_requests instrument so growing acquisition backlogs are visible before attempts complete. Count each acquisition from start to return, including connection creation and validation, and decrement on success, cancellation, timeout, and error.

Verify concurrent outstanding requests and zero recovery in SDK tests and positive pending counts through the real OTLP collector export path.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
The PostgreSQL collector integration test imports Docker API and Prometheus model and parser packages directly. Update their existing dependency classifications so module regeneration stays clean without changing versions.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Distinguish closed pools and connection establishment failures with bounded error types instead of reporting every failure as _OTHER. Preserve cancellation and timeout outcomes and classify the returned error chain rather than the current context state.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Precompute pool and outcome attributes on acquisition tracers and reuse upstream OpenTelemetry constructors and descriptions. Keep upstream attributes in the external registry without narrowing their types.

Remove redundant library tests and the global-provider collector test, retain production pool and lifecycle coverage, and benchmark acquisition instrumentation. Restore exporter-only dependencies to indirect without changing versions.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Replace the mixed outcome and error-class lookup map with named options. Keep label construction at pool configuration time and make the optional error type explicit in the helper.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Verify the real closed-pool error and its metric classification, describe connect_error as a pgconn connect failure, and remove the unreachable nil-tracer guard.

Balance pending requests even when another tracer replaces the acquisition context. Report the missing start time and skip its duration sample instead of panicking, with tests for missing and invalid values and subsequent recording.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Compare acquisition duration with the enclosing elapsed call rather than assuming the acquisition and caller deadlines start together. Warn once per tracer when acquisition context is lost and exercise repeated invalid contexts.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Classify pgconn connection errors before wrapped context errors so internal connection deadlines remain connect_error. Add controlled-dial regressions for internal timeout and caller cancellation, and clarify the documented outcomes.

Keep repeated missing-context coverage without inspecting sync.Once internals or introducing a logger dependency solely for warning assertions.

Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.com>
Signed-off-by: Ridwan Hoq <943533+ridhoq@users.noreply.github.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

area/observability kind/feature An enhancement / feature request or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ateapi: add PostgreSQL connection pool metrics

3 participants