feat: last syncdate metric

This commit is contained in:
Richard Ramos 2024-07-19 18:24:49 -04:00
parent ed15fd2dd8
commit eca44f86eb
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 24 additions and 0 deletions

View File

@ -379,6 +379,10 @@ func (app *Application) fetchStoreNodeMessages(ctx context.Context, runId string
func (app *Application) retrieveHistory(ctx context.Context, runId string, storenodes []peer.AddrInfo, topic string, lastSyncTimestamp *time.Time, tx *sql.Tx, logger *zap.Logger) { func (app *Application) retrieveHistory(ctx context.Context, runId string, storenodes []peer.AddrInfo, topic string, lastSyncTimestamp *time.Time, tx *sql.Tx, logger *zap.Logger) {
logger = logger.With(zap.String("topic", topic), zap.Timep("lastSyncTimestamp", lastSyncTimestamp)) logger = logger.With(zap.String("topic", topic), zap.Timep("lastSyncTimestamp", lastSyncTimestamp))
if lastSyncTimestamp != nil {
app.metrics.RecordLastSyncDate(topic, *lastSyncTimestamp)
}
now := app.node.Timesource().Now() now := app.node.Timesource().Now()
// Query is done with a delay // Query is done with a delay
@ -410,6 +414,9 @@ func (app *Application) retrieveHistory(ctx context.Context, runId string, store
if err != nil { if err != nil {
logger.Panic("could not update topic sync state", zap.Error(err)) logger.Panic("could not update topic sync state", zap.Error(err))
} }
app.metrics.RecordLastSyncDate(topic, endTime)
} }
func (app *Application) verifyMessageExistence(ctx context.Context, runId string, peerID peer.ID, messageHashes []pb.MessageHash, logger *zap.Logger) { func (app *Application) verifyMessageExistence(ctx context.Context, runId string, peerID peer.ID, messageHashes []pb.MessageHash, logger *zap.Logger) {

View File

@ -1,6 +1,8 @@
package metrics package metrics
import ( import (
"time"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/metricshelper" "github.com/libp2p/go-libp2p/p2p/metricshelper"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -30,6 +32,14 @@ var storenodeAvailability = prometheus.NewGaugeVec(
[]string{"storenode"}, []string{"storenode"},
) )
var topicLastSync = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "msgcounter_topic_lastsyncdate_seconds",
Help: "Indicates the last syncdate for a pubsubtopic",
},
[]string{"pubsubtopic"},
)
var collectors = []prometheus.Collector{ var collectors = []prometheus.Collector{
missingMessages, missingMessages,
storenodeAvailability, storenodeAvailability,
@ -40,6 +50,7 @@ type Metrics interface {
RecordMissingMessages(peerID peer.ID, status string, length int) RecordMissingMessages(peerID peer.ID, status string, length int)
RecordStorenodeAvailability(peerID peer.ID, available bool) RecordStorenodeAvailability(peerID peer.ID, available bool)
RecordTotalMissingMessages(cnt int) RecordTotalMissingMessages(cnt int)
RecordLastSyncDate(topic string, date time.Time)
} }
type metricsImpl struct { type metricsImpl struct {
@ -76,3 +87,9 @@ func (m *metricsImpl) RecordTotalMissingMessages(cnt int) {
totalMissingMessages.Set(float64(cnt)) totalMissingMessages.Set(float64(cnt))
}() }()
} }
func (m *metricsImpl) RecordLastSyncDate(topic string, date time.Time) {
go func() {
topicLastSync.WithLabelValues(topic).Set(float64(date.Unix()))
}()
}