1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Telemetry-layer implementation for [`ConnectionPool`].
//!
//! Snapshotting is something you *do* to a live [`ConnectionPool`]; this file
//! hosts the [`snapshot`](ConnectionPool::snapshot) method on the pool that
//! produces a read-only [`ConnectionPoolSnapshot`] of its current occupancy.
//!
//! # Contract
//!
//! - **No I/O.** Snapshotting only reads in-process counters exposed by sqlx.
//! - **No mutation.** The live pool is untouched.
//! - **No allocation beyond the returned struct.** A single heap `String` for
//! `client_name` plus a few `u32`s.
//! - **Consistent at the sqlx boundary.** Individual fields are each atomic
//! reads from the pool; the composite view is a best-effort "recent past".
//! `active_connections` is derived as `pool_size - idle_connections` with
//! `saturating_sub` to tolerate the rare case where idle advances between
//! the two reads.
//!
//! # Intended consumers
//!
//! - `/metrics` Prometheus exporter (via
//! [`ConnectionPoolSnapshot::write_prometheus`](crate::features::connection_pooler::prometheus))
//! - `client_connections` persistence (`insert_connection_snapshot`)
//! - Structured logging (`tracing::info!(?snapshot, …)`)
use Utc;
use crate;