Cleanup collectors (#826)

Fix up `replication` and `process_idle` Update input params to match
the rest of the collectors.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
Ben Kochie 2023-06-27 16:40:12 +02:00 committed by GitHub
parent 1a4e8993f6
commit 030a2a9bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -43,8 +43,8 @@ var pgProcessIdleSeconds = prometheus.NewDesc(
prometheus.Labels{},
)
func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch chan<- prometheus.Metric) error {
db := inst.getDB()
func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
db := instance.getDB()
row := db.QueryRowContext(ctx,
`WITH
metrics AS (

View File

@ -15,7 +15,6 @@ package collector
import (
"context"
"database/sql"
"github.com/prometheus/client_golang/prometheus"
)
@ -64,7 +63,8 @@ var (
END as is_replica`
)
func (c *PGReplicationCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
func (c *PGReplicationCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
db := instance.getDB()
row := db.QueryRowContext(ctx,
pgReplicationQuery,
)

View File

@ -29,6 +29,8 @@ func TestPgReplicationCollector(t *testing.T) {
}
defer db.Close()
inst := &instance{db: db}
columns := []string{"lag", "is_replica"}
rows := sqlmock.NewRows(columns).
AddRow(1000, 1)
@ -39,7 +41,7 @@ func TestPgReplicationCollector(t *testing.T) {
defer close(ch)
c := PGReplicationCollector{}
if err := c.Update(context.Background(), db, ch); err != nil {
if err := c.Update(context.Background(), inst, ch); err != nil {
t.Errorf("Error calling PGReplicationCollector.Update: %s", err)
}
}()