Skip to content

Commit 030a2a9

Browse files
authored
Cleanup collectors (#826)
Fix up `replication` and `process_idle` Update input params to match the rest of the collectors. Signed-off-by: SuperQ <[email protected]>
1 parent 1a4e899 commit 030a2a9

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

collector/pg_process_idle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ var pgProcessIdleSeconds = prometheus.NewDesc(
4343
prometheus.Labels{},
4444
)
4545

46-
func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch chan<- prometheus.Metric) error {
47-
db := inst.getDB()
46+
func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
47+
db := instance.getDB()
4848
row := db.QueryRowContext(ctx,
4949
`WITH
5050
metrics AS (

collector/pg_replication.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package collector
1515

1616
import (
1717
"context"
18-
"database/sql"
1918

2019
"github.com./prometheus/client_golang/prometheus"
2120
)
@@ -64,7 +63,8 @@ var (
6463
END as is_replica`
6564
)
6665

67-
func (c *PGReplicationCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
66+
func (c *PGReplicationCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
67+
db := instance.getDB()
6868
row := db.QueryRowContext(ctx,
6969
pgReplicationQuery,
7070
)

collector/pg_replication_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func TestPgReplicationCollector(t *testing.T) {
2929
}
3030
defer db.Close()
3131

32+
inst := &instance{db: db}
33+
3234
columns := []string{"lag", "is_replica"}
3335
rows := sqlmock.NewRows(columns).
3436
AddRow(1000, 1)
@@ -39,7 +41,7 @@ func TestPgReplicationCollector(t *testing.T) {
3941
defer close(ch)
4042
c := PGReplicationCollector{}
4143

42-
if err := c.Update(context.Background(), db, ch); err != nil {
44+
if err := c.Update(context.Background(), inst, ch); err != nil {
4345
t.Errorf("Error calling PGReplicationCollector.Update: %s", err)
4446
}
4547
}()

0 commit comments

Comments
 (0)