Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip pg_stat_checkpointer collector if pg<17 #1112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions collector/pg_stat_checkpointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package collector
import (
"context"
"database/sql"
"log/slog"

"github.com/blang/semver/v4"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -29,10 +31,11 @@ func init() {
}

type PGStatCheckpointerCollector struct {
log *slog.Logger
}

func NewPGStatCheckpointerCollector(collectorConfig) (Collector, error) {
return &PGStatCheckpointerCollector{}, nil
func NewPGStatCheckpointerCollector(config collectorConfig) (Collector, error) {
return &PGStatCheckpointerCollector{log: config.logger}, nil
}

var (
Expand Down Expand Up @@ -104,8 +107,15 @@ var (
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()

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)

// num_timed = nt = bigint
Expand Down
Loading