Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add poller last triggered block metric and improve block number handling #86

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ var (
})
)

var (
PollerLastTriggeredBlock = promauto.NewGauge(prometheus.GaugeOpts{
Name: "poller_last_triggered_block",
Help: "The last block number that the poller was triggered for",
})
)

// Failure Recoverer Metrics
var (
FailureRecovererLastTriggeredBlock = promauto.NewGauge(prometheus.GaugeOpts{
Expand Down
3 changes: 3 additions & 0 deletions internal/orchestrator/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (p *Poller) Start() {
}
log.Debug().Msgf("Polling %d blocks starting from %s to %s", len(blockNumbers), blockNumbers[0], endBlock)

endBlockNumberFloat, _ := endBlock.Float64()
metrics.PollerLastTriggeredBlock.Set(endBlockNumberFloat)

worker := worker.NewWorker(p.rpc)
results := worker.Run(blockNumbers)
p.handleWorkerResults(results)
Expand Down
5 changes: 2 additions & 3 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ func (w *Worker) Run(blockNumbers []*big.Int) []WorkerResult {

// track the last fetched block number
if len(results) > 0 {
// dividing by 10 to avoid scientific notation (e.g. 1.23456e+07)
// TODO: find a solution
metrics.LastFetchedBlock.Set(float64(results[len(results)-1].BlockNumber.Uint64()) / 10)
lastBlockNumberFloat, _ := results[len(results)-1].BlockNumber.Float64()
iuwqyir marked this conversation as resolved.
Show resolved Hide resolved
metrics.LastFetchedBlock.Set(lastBlockNumberFloat)
}
return results
}
Expand Down
Loading