You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-08-09 15:42:47 +03:00
Skip pg_stat_checkpointer collector if pg<17 (#1112)
* fix: skip collector if pg<17 Signed-off-by: Michael Todorovic <michael.todorovic@outlook.com> * fix: better condition Signed-off-by: Michael Todorovic <michael.todorovic@outlook.com> * fix: fix PGStatCheckpointerCollector tests Signed-off-by: Nicolas Rodriguez <nico@nicoladmin.fr> --------- Signed-off-by: Michael Todorovic <michael.todorovic@outlook.com> Signed-off-by: Nicolas Rodriguez <nico@nicoladmin.fr> Co-authored-by: Michael Todorovic <michael.todorovic@outlook.com>
This commit is contained in:
committed by
GitHub
parent
4c170ed564
commit
8bb1a41abf
@@ -16,7 +16,9 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/blang/semver/v4"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,10 +31,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PGStatCheckpointerCollector struct {
|
type PGStatCheckpointerCollector struct {
|
||||||
|
log *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPGStatCheckpointerCollector(collectorConfig) (Collector, error) {
|
func NewPGStatCheckpointerCollector(config collectorConfig) (Collector, error) {
|
||||||
return &PGStatCheckpointerCollector{}, nil
|
return &PGStatCheckpointerCollector{log: config.logger}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -104,8 +107,15 @@ var (
|
|||||||
FROM pg_stat_checkpointer;`
|
FROM pg_stat_checkpointer;`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (PGStatCheckpointerCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
|
func (c PGStatCheckpointerCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
|
||||||
db := instance.getDB()
|
db := instance.getDB()
|
||||||
|
|
||||||
|
before17 := instance.version.LT(semver.MustParse("17.0.0"))
|
||||||
|
if before17 {
|
||||||
|
c.log.Warn("pg_stat_checkpointer collector is not available on PostgreSQL < 17.0.0, skipping")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
row := db.QueryRowContext(ctx, statCheckpointerQuery)
|
row := db.QueryRowContext(ctx, statCheckpointerQuery)
|
||||||
|
|
||||||
// num_timed = nt = bigint
|
// num_timed = nt = bigint
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/DATA-DOG/go-sqlmock"
|
"github.com/DATA-DOG/go-sqlmock"
|
||||||
|
"github.com/blang/semver/v4"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/smartystreets/goconvey/convey"
|
"github.com/smartystreets/goconvey/convey"
|
||||||
@@ -30,7 +31,7 @@ func TestPGStatCheckpointerCollector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
inst := &instance{db: db}
|
inst := &instance{db: db, version: semver.MustParse("17.0.0")}
|
||||||
|
|
||||||
columns := []string{
|
columns := []string{
|
||||||
"num_timed",
|
"num_timed",
|
||||||
@@ -92,7 +93,7 @@ func TestPGStatCheckpointerCollectorNullValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
inst := &instance{db: db}
|
inst := &instance{db: db, version: semver.MustParse("17.0.0")}
|
||||||
|
|
||||||
columns := []string{
|
columns := []string{
|
||||||
"num_timed",
|
"num_timed",
|
||||||
|
Reference in New Issue
Block a user