feat(dbmanager): report pool max size and total connections opened

Add MaxOpenConnections to provider and connection stats, exposed as the
max state of dbmanager_connection_pool_size. Count physical dials through a
counting driver connector and export dbmanager_connections_opened_total;
existing_db pools derive an approximate count from sql.DBStats.
This commit is contained in:
Hein
2026-09-30 15:46:41 +02:00
parent d3a99550d9
commit 178d40587d
11 changed files with 191 additions and 51 deletions
+14
View File
@@ -5,6 +5,8 @@ import (
"strings"
"testing"
"time"
dto "github.com/prometheus/client_model/go"
)
func TestPostgresDSNEscapesCredentials(t *testing.T) {
@@ -83,6 +85,18 @@ func TestSQLiteMemoryPoolPinned(t *testing.T) {
if got := db.Stats().MaxOpenConnections; got != 1 {
t.Fatalf("MaxOpenConnections = %d, want 1 for :memory:", got)
}
if got := conn.Stats().MaxOpenConnections; got != 1 {
t.Fatalf("ConnectionStats.MaxOpenConnections = %d, want 1", got)
}
mgr.(*connectionManager).PublishMetrics()
name := conn.Name()
var m dto.Metric
if err := connectionPoolSize.WithLabelValues(name, string(conn.Stats().Type), "max").Write(&m); err != nil {
t.Fatal(err)
}
if got := m.GetGauge().GetValue(); got != 1 {
t.Fatalf("pool_size{state=max} = %v, want 1", got)
}
if _, err := db.Exec("CREATE TABLE t(a int)"); err != nil {
t.Fatal(err)
}