Skip to content

Commit

Permalink
feat: restart the service if fail to push msg (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab authored Jun 17, 2024
1 parent 1196325 commit c04e2af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/observability/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
metricsRouter *chi.Mux
pollDurationHistogram *prometheus.HistogramVec
btcClientDurationHistogram *prometheus.HistogramVec
queueSendErrorCounter prometheus.Counter
)

// Init initializes the metrics package.
Expand Down Expand Up @@ -77,9 +78,18 @@ func registerMetrics() {
[]string{"function", "status"},
)

// add a counter for the number of errors from the fail to push message into queue
queueSendErrorCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "queue_send_error_count",
Help: "The total number of errors when sending messages to the queue",
},
)

prometheus.MustRegister(
pollDurationHistogram,
btcClientDurationHistogram,
queueSendErrorCounter,
)
}

Expand All @@ -105,3 +115,7 @@ func RecordBtcClientMetrics[T any](clientRequest func() (T, error)) (T, error) {

return result, err
}

func RecordQueueSendError() {
queueSendErrorCounter.Inc()
}
4 changes: 3 additions & 1 deletion internal/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/rs/zerolog/log"

"github.com/babylonchain/staking-expiry-checker/internal/observability/metrics"
"github.com/babylonchain/staking-queue-client/client"
queueConfig "github.com/babylonchain/staking-queue-client/config"
)
Expand Down Expand Up @@ -36,7 +37,8 @@ func (qm *QueueManager) SendExpiredStakingEvent(ctx context.Context, ev client.E
log.Debug().Str("tx_hash", ev.StakingTxHashHex).Msg("publishing expired staking event")
err = qm.stakingExpiredEventQueue.SendMessage(ctx, messageBody)
if err != nil {
return fmt.Errorf("failed to publish staking event: %w", err)
metrics.RecordQueueSendError()
log.Fatal().Err(err).Str("tx_hash", ev.StakingTxHashHex).Msg("failed to publish staking event")
}
log.Debug().Str("tx_hash", ev.StakingTxHashHex).Msg("successfully published expired staking event")

Expand Down

0 comments on commit c04e2af

Please sign in to comment.