Skip to content

Commit

Permalink
Add gauges for transaction and relationship count removed by GC
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Schorr <josephschorr@users.noreply.github.com>
  • Loading branch information
josephschorr committed Oct 5, 2021
1 parent 75b5a6f commit 21e1b85
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions internal/datastore/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,27 @@ const (
batchDeleteSize = 1000
)

var gcDurationHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "postgres_gc_duration",
Help: "postgres garbage collection duration distribution in seconds.",
Buckets: []float64{0.01, 0.1, 0.5, 1, 5, 10, 25, 60, 120},
})
var (
gcDurationHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "postgres_gc_duration",
Help: "postgres garbage collection duration distribution in seconds.",
Buckets: []float64{0.01, 0.1, 0.5, 1, 5, 10, 25, 60, 120},
})

gcRelationshipsClearedGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "postgres_relationships_cleared",
Help: "number of relationships cleared by postgres garbage collection.",
})

gcTransactionsClearedGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "postgres_transactions_cleared",
Help: "number of transactions cleared by postgres garbage collection.",
})
)

func init() {
dbsql.Register(tracingDriverName, sqlmw.Driver(stdlib.GetDefaultDriver(), new(traceInterceptor)))
prometheus.MustRegister(gcDurationHistogram)
prometheus.MustRegister(gcDurationHistogram, gcRelationshipsClearedGauge, gcTransactionsClearedGauge)
}

var (
Expand Down Expand Up @@ -280,6 +292,7 @@ func (pgd *pgDatastore) collectGarbageForTransaction(ctx context.Context, highes
}

log.Trace().Uint64("highest_transaction_id", highest).Int64("relationships_deleted", relCount).Msg("deleted stale relationships")
gcRelationshipsClearedGauge.Set(float64(relCount))

// Delete all transaction rows with ID < the transaction ID. We don't delete the transaction
// itself to ensure there is always at least one transaction present.
Expand All @@ -289,6 +302,7 @@ func (pgd *pgDatastore) collectGarbageForTransaction(ctx context.Context, highes
}

log.Trace().Uint64("highest_transaction_id", highest).Int64("transactions_deleted", transactionCount).Msg("deleted stale transactions")
gcTransactionsClearedGauge.Set(float64(transactionCount))
return relCount, transactionCount, nil
}

Expand Down

0 comments on commit 21e1b85

Please sign in to comment.