From c69dea6da6ae961d84747e501d8d3db6c57d3e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Wed, 23 Oct 2024 17:38:04 -0400 Subject: [PATCH] feat: missing messags in the last hour (#12) --- cmd/storemsgcounter/execute.go | 18 ++++++++++++++---- internal/metrics/metrics.go | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/storemsgcounter/execute.go b/cmd/storemsgcounter/execute.go index 60117ef..63eaaca 100644 --- a/cmd/storemsgcounter/execute.go +++ b/cmd/storemsgcounter/execute.go @@ -214,7 +214,7 @@ func Execute(ctx context.Context, options Options) error { runIdLogger.Info("missing messages recheck complete") - syncCheckTimer.Reset(30 * time.Minute) + syncCheckTimer.Reset(15 * time.Minute) }() } } @@ -442,12 +442,22 @@ func (app *Application) checkMissingMessageStatus(ctx context.Context, storenode } func (app *Application) countMissingMessages(storenodes []peer.ID) error { + now := app.node.Timesource().Now().Add(-delay) + + // Count messages in last hour (not including last 5 minutes) + results, err := app.db.CountMissingMessages(now.Add(-time.Hour), now) + if err != nil { + return err + } + for storenode, cnt := range results { + app.metrics.RecordMissingMessagesLastHour(storenode, cnt) + } // not including last two hours in now to let sync work - now := app.node.Timesource().Now().Add(-2 * time.Hour) + _2hAgo := now.Add(-2 * time.Hour) // Count messages in last day (not including last two hours) - results, err := app.db.CountMissingMessages(now.Add(-24*time.Hour), now) + results, err = app.db.CountMissingMessages(now.Add(-24*time.Hour), _2hAgo) if err != nil { return err } @@ -456,7 +466,7 @@ func (app *Application) countMissingMessages(storenodes []peer.ID) error { } // Count messages in last week (not including last two hours) - results, err = app.db.CountMissingMessages(now.Add(-24*time.Hour*7), now) + results, err = app.db.CountMissingMessages(_2hAgo.Add(-24*time.Hour*7), _2hAgo) if err != nil { return err } diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 747628b..6614670 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -41,6 +41,14 @@ var topicLastSync = prometheus.NewGaugeVec( []string{"fleetName", "pubsubtopic"}, ) +var missingMessagesLastHour = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "msgcounter_missing_messages_last_hour", + Help: "The number of messages missing in last hour (excluding the last 5 minutes)", + }, + []string{"fleetName", "storenode"}, +) + var missingMessagesLastDay = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "msgcounter_missing_messages_last_day", @@ -81,6 +89,7 @@ type Metrics interface { RecordStorenodeAvailability(peerID peer.ID, available bool) RecordTotalMissingMessages(cnt int) RecordLastSyncDate(topic string, date time.Time) + RecordMissingMessagesLastHour(peerID peer.ID, cnt int) RecordMissingMessagesLastDay(peerID peer.ID, cnt int) RecordMissingMessagesLastWeek(peerID peer.ID, cnt int) RecordMissingMessagesPrevHour(peerID peer.ID, cnt int) @@ -131,6 +140,12 @@ func (m *metricsImpl) RecordLastSyncDate(topic string, date time.Time) { }() } +func (m *metricsImpl) RecordMissingMessagesLastHour(peerID peer.ID, cnt int) { + go func() { + missingMessagesLastHour.WithLabelValues(m.fleetName, peerID.String()).Set(float64(cnt)) + }() +} + func (m *metricsImpl) RecordMissingMessagesLastDay(peerID peer.ID, cnt int) { go func() { missingMessagesLastDay.WithLabelValues(m.fleetName, peerID.String()).Set(float64(cnt))