From 4b1397d61f8615add1eb42d132102c123d3bb19c Mon Sep 17 00:00:00 2001 From: Nikolai Vaganov Date: Mon, 23 Sep 2024 23:18:25 +0300 Subject: [PATCH 1/3] fix converting NULL to uint64 is unsupported in size table Signed-off-by: Nikolai Vaganov --- collector/pg_wal.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/collector/pg_wal.go b/collector/pg_wal.go index afa8fcef6..4cbb1793c 100644 --- a/collector/pg_wal.go +++ b/collector/pg_wal.go @@ -15,7 +15,7 @@ package collector import ( "context" - + "database/sql" "github.com/prometheus/client_golang/prometheus" ) @@ -66,19 +66,34 @@ func (c PGWALCollector) Update(ctx context.Context, instance *instance, ch chan< pgWALQuery, ) - var segments uint64 - var size uint64 + var segments sql.NullInt64 + var size sql.NullInt64 err := row.Scan(&segments, &size) if err != nil { return err } + + var segmentsValue float64 + if segments.Valid { + segmentsValue = float64(segments.Int64) + } else { + segmentsValue = 0 + } + + var sizeValue float64 + if size.Valid { + sizeValue = float64(size.Int64) + } else { + sizeValue = 0 + } + ch <- prometheus.MustNewConstMetric( pgWALSegments, - prometheus.GaugeValue, float64(segments), + prometheus.GaugeValue, segmentsValue, ) ch <- prometheus.MustNewConstMetric( pgWALSize, - prometheus.GaugeValue, float64(size), + prometheus.GaugeValue, sizeValue, ) return nil } From 2c5c3ecfb0221a8c5025712333be1a90200c9552 Mon Sep 17 00:00:00 2001 From: Nikolai Vaganov Date: Mon, 23 Sep 2024 23:37:57 +0300 Subject: [PATCH 2/3] lint fix Signed-off-by: Nikolai Vaganov --- collector/pg_wal.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/collector/pg_wal.go b/collector/pg_wal.go index 4cbb1793c..cfb0ee95a 100644 --- a/collector/pg_wal.go +++ b/collector/pg_wal.go @@ -15,7 +15,7 @@ package collector import ( "context" - "database/sql" + "database/sql" "github.com/prometheus/client_golang/prometheus" ) @@ -74,18 +74,18 @@ func (c PGWALCollector) Update(ctx context.Context, instance *instance, ch chan< } var segmentsValue float64 - if segments.Valid { - segmentsValue = float64(segments.Int64) - } else { - segmentsValue = 0 + if segments.Valid { + segmentsValue = float64(segments.Int64) + } else { + segmentsValue = 0 } - var sizeValue float64 - if size.Valid { - sizeValue = float64(size.Int64) - } else { - sizeValue = 0 - } + var sizeValue float64 + if size.Valid { + sizeValue = float64(size.Int64) + } else { + sizeValue = 0 + } ch <- prometheus.MustNewConstMetric( pgWALSegments, From 20e10175decd65f005d4f3941757b4385a2ce2b4 Mon Sep 17 00:00:00 2001 From: Nikolai Vaganov Date: Mon, 23 Sep 2024 23:40:22 +0300 Subject: [PATCH 3/3] lint fix Signed-off-by: Nikolai Vaganov --- collector/pg_wal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/pg_wal.go b/collector/pg_wal.go index cfb0ee95a..ab39d9145 100644 --- a/collector/pg_wal.go +++ b/collector/pg_wal.go @@ -78,7 +78,7 @@ func (c PGWALCollector) Update(ctx context.Context, instance *instance, ch chan< segmentsValue = float64(segments.Int64) } else { segmentsValue = 0 - } + } var sizeValue float64 if size.Valid {