Skip to content

Commit 1c66044

Browse files
michael-todorovicn-rodriguez
authored andcommitted
fix: skip collector if pg<17
Signed-off-by: Michael Todorovic <[email protected]>
1 parent 4c170ed commit 1c66044

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

collector/pg_stat_checkpointer.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ package collector
1616
import (
1717
"context"
1818
"database/sql"
19+
"log/slog"
1920

21+
"github.com/blang/semver/v4"
2022
"github.com/prometheus/client_golang/prometheus"
2123
)
2224

@@ -29,10 +31,11 @@ func init() {
2931
}
3032

3133
type PGStatCheckpointerCollector struct {
34+
log *slog.Logger
3235
}
3336

34-
func NewPGStatCheckpointerCollector(collectorConfig) (Collector, error) {
35-
return &PGStatCheckpointerCollector{}, nil
37+
func NewPGStatCheckpointerCollector(config collectorConfig) (Collector, error) {
38+
return &PGStatCheckpointerCollector{log: config.logger}, nil
3639
}
3740

3841
var (
@@ -104,8 +107,15 @@ var (
104107
FROM pg_stat_checkpointer;`
105108
)
106109

107-
func (PGStatCheckpointerCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
110+
func (c PGStatCheckpointerCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
108111
db := instance.getDB()
112+
113+
before17 := instance.version.Compare(semver.MustParse("17.0.0"))
114+
if before17 < 0 {
115+
c.log.Warn("pg_stat_checkpointer collector is not available on PostgreSQL < 17.0.0, skipping")
116+
return nil
117+
}
118+
109119
row := db.QueryRowContext(ctx, statCheckpointerQuery)
110120

111121
// num_timed = nt = bigint

0 commit comments

Comments
 (0)