From 6b56e2f057e43b93a56d1f1ba781605973e4688a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 6 Jul 2023 08:33:54 +0100 Subject: [PATCH] Unpack postgres arrays for process idle times correctly (#855) Signed-off-by: Ben Kochie --- collector/pg_process_idle.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/collector/pg_process_idle.go b/collector/pg_process_idle.go index 57df723a..8d995ab5 100644 --- a/collector/pg_process_idle.go +++ b/collector/pg_process_idle.go @@ -18,6 +18,7 @@ import ( "database/sql" "github.com/go-kit/log" + "github.com/lib/pq" "github.com/prometheus/client_golang/prometheus" ) @@ -82,22 +83,22 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch GROUP BY 1, 2, 3;`) var applicationName sql.NullString - var secondsSum sql.NullInt64 + var secondsSum sql.NullFloat64 var secondsCount sql.NullInt64 - var seconds []uint64 - var secondsBucket []uint64 + var seconds []float64 + var secondsBucket []int64 - err := row.Scan(&applicationName, &secondsSum, &secondsCount, &seconds, &secondsBucket) + err := row.Scan(&applicationName, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket)) + if err != nil { + return err + } var buckets = make(map[float64]uint64, len(seconds)) for i, second := range seconds { if i >= len(secondsBucket) { break } - buckets[float64(second)] = secondsBucket[i] - } - if err != nil { - return err + buckets[second] = uint64(secondsBucket[i]) } applicationNameLabel := "unknown" @@ -111,7 +112,7 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch } secondsSumMetric := 0.0 if secondsSum.Valid { - secondsSumMetric = float64(secondsSum.Int64) + secondsSumMetric = secondsSum.Float64 } ch <- prometheus.MustNewConstHistogram( pgProcessIdleSeconds,