Compare commits

...

6 Commits

Author SHA1 Message Date
Joe Adams
8c3604b85e
Bump version file
Signed-off-by: Joe Adams <github@joeadams.io>
2023-07-21 14:21:09 -04:00
Joe Adams
803e131ee4 Update changelog for release 0.13.2 ()
Signed-off-by: Joe Adams <github@joeadams.io>
2023-07-21 14:20:47 -04:00
Ben Kochie
bad8b233d8 Cleanup collectors ()
Fix up `replication` and `process_idle` Update input params to match
the rest of the collectors.

Signed-off-by: SuperQ <superq@gmail.com>
2023-07-21 14:18:57 -04:00
Tom Hughes
392d8ca16a Unpack postgres arrays for process idle times correctly ()
Signed-off-by: Ben Kochie <superq@gmail.com>
2023-07-21 14:10:59 -04:00
Tom Hughes
0850b195a0 Fix replication collector
Signed-off-by: Tom Hughes <tom@compton.nu>
2023-07-21 14:08:26 -04:00
Felix Yuan
dd87ad094a Bug Fix: Fix lingering type issues ()
* Fix postmaster type issue
* Disable postmaster collector by default

---------

Signed-off-by: Felix Yuan <felix.yuan@reddit.com>
2023-07-21 14:07:24 -04:00
6 changed files with 27 additions and 18 deletions

View File

@ -1,3 +1,9 @@
## 0.13.2 / 2023-07-21
* [BUGFIX] Fix type issues on pg_postmaster metrics #828
* [BUGFIX] Fix pg_replication collector instantiation #854
* [BUGFIX] Fix pg_process_idle metrics #855
## 0.13.1 / 2023-06-27
* [BUGFIX] Make collectors not fail on null values #823

View File

@ -1 +1 @@
0.13.1
0.13.2

View File

@ -23,7 +23,7 @@ import (
const postmasterSubsystem = "postmaster"
func init() {
registerCollector(postmasterSubsystem, defaultEnabled, NewPGPostmasterCollector)
registerCollector(postmasterSubsystem, defaultDisabled, NewPGPostmasterCollector)
}
type PGPostmasterCollector struct {
@ -44,7 +44,7 @@ var (
[]string{}, nil,
)
pgPostmasterQuery = "SELECT pg_postmaster_start_time from pg_postmaster_start_time();"
pgPostmasterQuery = "SELECT extract(epoch from pg_postmaster_start_time) from pg_postmaster_start_time();"
)
func (c *PGPostmasterCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {

View File

@ -18,6 +18,7 @@ import (
"database/sql"
"github.com/go-kit/log"
"github.com/lib/pq"
"github.com/prometheus/client_golang/prometheus"
)
@ -43,8 +44,8 @@ var pgProcessIdleSeconds = prometheus.NewDesc(
prometheus.Labels{},
)
func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch chan<- prometheus.Metric) error {
db := inst.getDB()
func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
db := instance.getDB()
row := db.QueryRowContext(ctx,
`WITH
metrics AS (
@ -82,22 +83,22 @@ func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch cha
GROUP BY 1, 2, 3;`)
var applicationName sql.NullString
var secondsSum sql.NullInt64
var secondsSum sql.NullFloat64
var secondsCount sql.NullInt64
var seconds []int64
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, inst *instance, ch cha
}
secondsSumMetric := 0.0
if secondsSum.Valid {
secondsSumMetric = float64(secondsSum.Int64)
secondsSumMetric = secondsSum.Float64
}
ch <- prometheus.MustNewConstHistogram(
pgProcessIdleSeconds,

View File

@ -15,7 +15,6 @@ package collector
import (
"context"
"database/sql"
"github.com/prometheus/client_golang/prometheus"
)
@ -30,7 +29,7 @@ type PGReplicationCollector struct {
}
func NewPGReplicationCollector(collectorConfig) (Collector, error) {
return &PGPostmasterCollector{}, nil
return &PGReplicationCollector{}, nil
}
var (
@ -64,7 +63,8 @@ var (
END as is_replica`
)
func (c *PGReplicationCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
func (c *PGReplicationCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
db := instance.getDB()
row := db.QueryRowContext(ctx,
pgReplicationQuery,
)

View File

@ -29,6 +29,8 @@ func TestPgReplicationCollector(t *testing.T) {
}
defer db.Close()
inst := &instance{db: db}
columns := []string{"lag", "is_replica"}
rows := sqlmock.NewRows(columns).
AddRow(1000, 1)
@ -39,7 +41,7 @@ func TestPgReplicationCollector(t *testing.T) {
defer close(ch)
c := PGReplicationCollector{}
if err := c.Update(context.Background(), db, ch); err != nil {
if err := c.Update(context.Background(), inst, ch); err != nil {
t.Errorf("Error calling PGReplicationCollector.Update: %s", err)
}
}()