Skip to content

Commit 10b1ffb

Browse files
authored
fix(collector): restore reserve_pool metric on PgBouncer >= 1.24 (#271)
PgBouncer 1.24.0 renamed the `reserve_pool` column in `SHOW DATABASES` to `reserve_pool_size` (pgbouncer/pgbouncer#1232). The exporter only mapped the old column name, so the `pgbouncer_databases_reserve_pool` metric silently stopped being emitted on PgBouncer 1.24+. Add a mapping for `reserve_pool_size` next to the existing `reserve_pool` entry, both pointing at the same metric name. The exporter iterates over the actual columns returned by pgbouncer, and the two names are mutually exclusive across versions, so the metric continues to be emitted exactly once per database row regardless of pgbouncer version. Add tests covering both column names. Refs: #220 Signed-off-by: Dmitrij Shishkin <greeddj@gmail.com>
1 parent 863a6e6 commit 10b1ffb

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

collector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
"force_user": {LABEL, "N/A", 1, "N/A"},
3939
"pool_size": {GAUGE, "pool_size", 1, "Maximum number of server connections"},
4040
"reserve_pool": {GAUGE, "reserve_pool", 1, "Maximum number of additional connections for this database"},
41+
"reserve_pool_size": {GAUGE, "reserve_pool", 1, "Maximum number of additional connections for this database"},
4142
"pool_mode": {LABEL, "N/A", 1, "N/A"},
4243
"max_connections": {GAUGE, "max_connections", 1, "Maximum number of allowed connections for this database"},
4344
"current_connections": {GAUGE, "current_connections", 1, "Current number of connections for this database"},

collector_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ func TestQueryShowDatabases(t *testing.T) {
235235
testQueryNamespaceMapping(t, "databases", rows, expected)
236236
}
237237

238+
func TestQueryShowDatabasesReservePool(t *testing.T) {
239+
// PgBouncer < 1.24 exposes the column as reserve_pool
240+
rows := sqlmock.NewRows([]string{"name", "host", "port", "database", "reserve_pool"}).
241+
AddRow("pg0_db", "10.10.10.1", "5432", "pg0", 5)
242+
243+
expected := []MetricResult{
244+
{labels: labelMap{"name": "pg0_db", "host": "10.10.10.1", "port": "5432", "database": "pg0", "force_user": "", "pool_mode": ""}, metricType: dto.MetricType_GAUGE, value: 5},
245+
}
246+
247+
testQueryNamespaceMapping(t, "databases", rows, expected)
248+
}
249+
250+
func TestQueryShowDatabasesReservePoolSize(t *testing.T) {
251+
// PgBouncer >= 1.24 renamed the column to reserve_pool_size
252+
rows := sqlmock.NewRows([]string{"name", "host", "port", "database", "reserve_pool_size"}).
253+
AddRow("pg0_db", "10.10.10.1", "5432", "pg0", 5)
254+
255+
expected := []MetricResult{
256+
{labels: labelMap{"name": "pg0_db", "host": "10.10.10.1", "port": "5432", "database": "pg0", "force_user": "", "pool_mode": ""}, metricType: dto.MetricType_GAUGE, value: 5},
257+
}
258+
259+
testQueryNamespaceMapping(t, "databases", rows, expected)
260+
}
261+
238262
func TestQueryShowStats(t *testing.T) {
239263
// columns are listed in the order PgBouncers exposes them, a value of -1 means pgbouncer_exporter does not expose this value as a metric
240264
rows := sqlmock.NewRows([]string{"database",

0 commit comments

Comments
 (0)