Skip to content

Commit cd450cd

Browse files
Merge pull request #12 from form3tech-oss/alessio-remove-incompatible-columns
fix: remove columns in versions older than v14 of Postgres.
2 parents c68de8e + 19955f1 commit cd450cd

File tree

4 files changed

+10
-68
lines changed

4 files changed

+10
-68
lines changed

collector/pg_replication_slot.go

+1-19
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ var (
6363
"whether the replication slot is active or not",
6464
[]string{"slot_name", "slot_type"}, nil,
6565
)
66-
pgReplicationSlotSafeWal = prometheus.NewDesc(
67-
prometheus.BuildFQName(
68-
namespace,
69-
replicationSlotSubsystem,
70-
"safe_wal_size_bytes",
71-
),
72-
"number of bytes that can be written to WAL such that this slot is not in danger of getting in state lost",
73-
[]string{"slot_name", "slot_type"}, nil,
74-
)
7566
pgReplicationSlotWalStatus = prometheus.NewDesc(
7667
prometheus.BuildFQName(
7768
namespace,
@@ -92,7 +83,6 @@ var (
9283
END AS current_wal_lsn,
9384
COALESCE(confirmed_flush_lsn, '0/0') - '0/0' AS confirmed_flush_lsn,
9485
active,
95-
safe_wal_size,
9686
wal_status
9787
FROM pg_replication_slots;`
9888
)
@@ -112,9 +102,8 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
112102
var walLSN sql.NullFloat64
113103
var flushLSN sql.NullFloat64
114104
var isActive sql.NullBool
115-
var safeWalSize sql.NullInt64
116105
var walStatus sql.NullString
117-
if err := rows.Scan(&slotName, &slotType, &walLSN, &flushLSN, &isActive, &safeWalSize, &walStatus); err != nil {
106+
if err := rows.Scan(&slotName, &slotType, &walLSN, &flushLSN, &isActive, &walStatus); err != nil {
118107
return err
119108
}
120109

@@ -154,13 +143,6 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, instance *instance
154143
prometheus.GaugeValue, isActiveValue, slotNameLabel, slotTypeLabel,
155144
)
156145

157-
if safeWalSize.Valid {
158-
ch <- prometheus.MustNewConstMetric(
159-
pgReplicationSlotSafeWal,
160-
prometheus.GaugeValue, float64(safeWalSize.Int64), slotNameLabel, slotTypeLabel,
161-
)
162-
}
163-
164146
if walStatus.Valid {
165147
ch <- prometheus.MustNewConstMetric(
166148
pgReplicationSlotWalStatus,

collector/pg_replication_slot_test.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func TestPgReplicationSlotCollectorActive(t *testing.T) {
3131

3232
inst := &instance{db: db}
3333

34-
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "safe_wal_size", "wal_status"}
34+
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "wal_status"}
3535
rows := sqlmock.NewRows(columns).
36-
AddRow("test_slot", "physical", 5, 3, true, 323906992, "reserved")
36+
AddRow("test_slot", "physical", 5, 3, true, "reserved")
3737
mock.ExpectQuery(sanitizeQuery(pgReplicationSlotQuery)).WillReturnRows(rows)
3838

3939
ch := make(chan prometheus.Metric)
@@ -50,7 +50,6 @@ func TestPgReplicationSlotCollectorActive(t *testing.T) {
5050
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 5, metricType: dto.MetricType_GAUGE},
5151
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 3, metricType: dto.MetricType_GAUGE},
5252
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 1, metricType: dto.MetricType_GAUGE},
53-
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 323906992, metricType: dto.MetricType_GAUGE},
5453
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical", "wal_status": "reserved"}, value: 1, metricType: dto.MetricType_GAUGE},
5554
}
5655

@@ -74,9 +73,9 @@ func TestPgReplicationSlotCollectorInActive(t *testing.T) {
7473

7574
inst := &instance{db: db}
7675

77-
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "safe_wal_size", "wal_status"}
76+
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "wal_status"}
7877
rows := sqlmock.NewRows(columns).
79-
AddRow("test_slot", "physical", 6, 12, false, -4000, "extended")
78+
AddRow("test_slot", "physical", 6, 12, false, "extended")
8079
mock.ExpectQuery(sanitizeQuery(pgReplicationSlotQuery)).WillReturnRows(rows)
8180

8281
ch := make(chan prometheus.Metric)
@@ -92,7 +91,6 @@ func TestPgReplicationSlotCollectorInActive(t *testing.T) {
9291
expected := []MetricResult{
9392
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 6, metricType: dto.MetricType_GAUGE},
9493
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: 0, metricType: dto.MetricType_GAUGE},
95-
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical"}, value: -4000, metricType: dto.MetricType_GAUGE},
9694
{labels: labelMap{"slot_name": "test_slot", "slot_type": "physical", "wal_status": "extended"}, value: 1, metricType: dto.MetricType_GAUGE},
9795
}
9896

@@ -117,9 +115,9 @@ func TestPgReplicationSlotCollectorActiveNil(t *testing.T) {
117115

118116
inst := &instance{db: db}
119117

120-
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "safe_wal_size", "wal_status"}
118+
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "wal_status"}
121119
rows := sqlmock.NewRows(columns).
122-
AddRow("test_slot", "physical", 6, 12, nil, nil, "lost")
120+
AddRow("test_slot", "physical", 6, 12, nil, "lost")
123121
mock.ExpectQuery(sanitizeQuery(pgReplicationSlotQuery)).WillReturnRows(rows)
124122

125123
ch := make(chan prometheus.Metric)
@@ -158,9 +156,9 @@ func TestPgReplicationSlotCollectorTestNilValues(t *testing.T) {
158156

159157
inst := &instance{db: db}
160158

161-
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "safe_wal_size", "wal_status"}
159+
columns := []string{"slot_name", "slot_type", "current_wal_lsn", "confirmed_flush_lsn", "active", "wal_status"}
162160
rows := sqlmock.NewRows(columns).
163-
AddRow(nil, nil, nil, nil, true, nil, nil)
161+
AddRow(nil, nil, nil, nil, true, nil)
164162
mock.ExpectQuery(sanitizeQuery(pgReplicationSlotQuery)).WillReturnRows(rows)
165163

166164
ch := make(chan prometheus.Metric)

collector/pg_stat_database.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,6 @@ var (
206206
[]string{"datid", "datname"},
207207
prometheus.Labels{},
208208
)
209-
statDatabaseActiveTime = prometheus.NewDesc(prometheus.BuildFQName(
210-
namespace,
211-
statDatabaseSubsystem,
212-
"active_time_seconds_total",
213-
),
214-
"Time spent executing SQL statements in this database, in seconds",
215-
[]string{"datid", "datname"},
216-
prometheus.Labels{},
217-
)
218209

219210
statDatabaseQuery = `
220211
SELECT
@@ -236,7 +227,6 @@ var (
236227
,deadlocks
237228
,blk_read_time
238229
,blk_write_time
239-
,active_time
240230
,stats_reset
241231
FROM pg_stat_database;
242232
`
@@ -254,7 +244,7 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance
254244

255245
for rows.Next() {
256246
var datid, datname sql.NullString
257-
var numBackends, xactCommit, xactRollback, blksRead, blksHit, tupReturned, tupFetched, tupInserted, tupUpdated, tupDeleted, conflicts, tempFiles, tempBytes, deadlocks, blkReadTime, blkWriteTime, activeTime sql.NullFloat64
247+
var numBackends, xactCommit, xactRollback, blksRead, blksHit, tupReturned, tupFetched, tupInserted, tupUpdated, tupDeleted, conflicts, tempFiles, tempBytes, deadlocks, blkReadTime, blkWriteTime sql.NullFloat64
258248
var statsReset sql.NullTime
259249

260250
err := rows.Scan(
@@ -276,7 +266,6 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance
276266
&deadlocks,
277267
&blkReadTime,
278268
&blkWriteTime,
279-
&activeTime,
280269
&statsReset,
281270
)
282271
if err != nil {
@@ -355,10 +344,6 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance
355344
level.Debug(c.log).Log("msg", "Skipping collecting metric because it has no blk_write_time")
356345
continue
357346
}
358-
if !activeTime.Valid {
359-
level.Debug(c.log).Log("msg", "Skipping collecting metric because it has no active_time")
360-
continue
361-
}
362347

363348
statsResetMetric := 0.0
364349
if !statsReset.Valid {
@@ -482,13 +467,6 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance
482467
labels...,
483468
)
484469

485-
ch <- prometheus.MustNewConstMetric(
486-
statDatabaseActiveTime,
487-
prometheus.CounterValue,
488-
activeTime.Float64/1000.0,
489-
labels...,
490-
)
491-
492470
ch <- prometheus.MustNewConstMetric(
493471
statDatabaseStatsReset,
494472
prometheus.CounterValue,

collector/pg_stat_database_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestPGStatDatabaseCollector(t *testing.T) {
5252
"deadlocks",
5353
"blk_read_time",
5454
"blk_write_time",
55-
"active_time",
5655
"stats_reset",
5756
}
5857

@@ -81,7 +80,6 @@ func TestPGStatDatabaseCollector(t *testing.T) {
8180
925,
8281
16,
8382
823,
84-
33,
8583
srT)
8684

8785
mock.ExpectQuery(sanitizeQuery(statDatabaseQuery)).WillReturnRows(rows)
@@ -115,7 +113,6 @@ func TestPGStatDatabaseCollector(t *testing.T) {
115113
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 925},
116114
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 16},
117115
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 823},
118-
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0.033},
119116
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 1685059842},
120117
}
121118

@@ -162,7 +159,6 @@ func TestPGStatDatabaseCollectorNullValues(t *testing.T) {
162159
"deadlocks",
163160
"blk_read_time",
164161
"blk_write_time",
165-
"active_time",
166162
"stats_reset",
167163
}
168164

@@ -186,7 +182,6 @@ func TestPGStatDatabaseCollectorNullValues(t *testing.T) {
186182
925,
187183
16,
188184
823,
189-
32,
190185
srT).
191186
AddRow(
192187
"pid",
@@ -207,7 +202,6 @@ func TestPGStatDatabaseCollectorNullValues(t *testing.T) {
207202
925,
208203
16,
209204
823,
210-
32,
211205
srT)
212206
mock.ExpectQuery(sanitizeQuery(statDatabaseQuery)).WillReturnRows(rows)
213207

@@ -240,7 +234,6 @@ func TestPGStatDatabaseCollectorNullValues(t *testing.T) {
240234
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 925},
241235
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 16},
242236
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 823},
243-
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0.032},
244237
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 1685059842},
245238
}
246239

@@ -282,7 +275,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
282275
"deadlocks",
283276
"blk_read_time",
284277
"blk_write_time",
285-
"active_time",
286278
"stats_reset",
287279
}
288280

@@ -311,7 +303,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
311303
925,
312304
16,
313305
823,
314-
14,
315306
srT).
316307
AddRow(
317308
nil,
@@ -333,7 +324,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
333324
nil,
334325
nil,
335326
nil,
336-
nil,
337327
).
338328
AddRow(
339329
"pid",
@@ -354,7 +344,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
354344
926,
355345
17,
356346
824,
357-
15,
358347
srT)
359348
mock.ExpectQuery(sanitizeQuery(statDatabaseQuery)).WillReturnRows(rows)
360349

@@ -387,7 +376,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
387376
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 925},
388377
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 16},
389378
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 823},
390-
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0.014},
391379
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 1685059842},
392380

393381
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_GAUGE, value: 355},
@@ -406,7 +394,6 @@ func TestPGStatDatabaseCollectorRowLeakTest(t *testing.T) {
406394
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 926},
407395
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 17},
408396
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 824},
409-
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0.015},
410397
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 1685059842},
411398
}
412399

@@ -449,7 +436,6 @@ func TestPGStatDatabaseCollectorTestNilStatReset(t *testing.T) {
449436
"deadlocks",
450437
"blk_read_time",
451438
"blk_write_time",
452-
"active_time",
453439
"stats_reset",
454440
}
455441

@@ -473,7 +459,6 @@ func TestPGStatDatabaseCollectorTestNilStatReset(t *testing.T) {
473459
925,
474460
16,
475461
823,
476-
7,
477462
nil)
478463

479464
mock.ExpectQuery(sanitizeQuery(statDatabaseQuery)).WillReturnRows(rows)
@@ -507,7 +492,6 @@ func TestPGStatDatabaseCollectorTestNilStatReset(t *testing.T) {
507492
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 925},
508493
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 16},
509494
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 823},
510-
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0.007},
511495
{labels: labelMap{"datid": "pid", "datname": "postgres"}, metricType: dto.MetricType_COUNTER, value: 0},
512496
}
513497

0 commit comments

Comments
 (0)