Skip to content

Commit

Permalink
services/horizon: Add ledger_fetch_duration_seconds metric (#4016)
Browse files Browse the repository at this point in the history
Add `horizon_ingest_ledger_fetch_duration_seconds` metric indicating time
required to fetch a ledger from `LedgerBackend`. We don't track this value
outside logging but it can be useful (ex. alerting if ledger backend is slow).
  • Loading branch information
bartekn authored Oct 21, 2021
1 parent bbccb6a commit 68b39bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions services/horizon/internal/ingest/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,14 @@ func (r resumeState) run(s *system) (transition, error) {
if err != nil {
return start(), errors.Wrap(err, "error getting ledger blocking")
}
duration := time.Since(startTime).Seconds()
log.WithFields(logpkg.F{
"sequence": ingestLedger,
"duration": time.Since(startTime).Seconds(),
"duration": duration,
}).Info("Ledger returned from the backend")

s.Metrics().LedgerFetchDurationSummary.Observe(float64(duration))

if err = s.historyQ.Begin(); err != nil {
return retryResume(r),
errors.Wrap(err, "Error starting a transaction")
Expand Down Expand Up @@ -480,7 +483,7 @@ func (r resumeState) run(s *system) (transition, error) {
log.WithError(err).Warn("error updating stellar-core cursor")
}

duration := time.Since(startTime).Seconds()
duration = time.Since(startTime).Seconds()
s.Metrics().LedgerIngestionDuration.Observe(float64(duration))

// Update stats metrics
Expand Down
11 changes: 11 additions & 0 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ type Metrics struct {
// ProcessorsRunDurationSummary exposes processors run durations.
ProcessorsRunDurationSummary *prometheus.SummaryVec

// LedgerFetchDurationSummary exposes a summary of durations required to
// fetch data from ledger backend.
LedgerFetchDurationSummary prometheus.Summary

// CaptiveStellarCoreSynced exposes synced status of Captive Stellar-Core.
// 1 if sync, 0 if not synced, -1 if unable to connect or HTTP server disabled.
CaptiveStellarCoreSynced prometheus.GaugeFunc
Expand Down Expand Up @@ -353,6 +357,13 @@ func (s *system) initMetrics() {
[]string{"name"},
)

s.metrics.LedgerFetchDurationSummary = prometheus.NewSummary(
prometheus.SummaryOpts{
Namespace: "horizon", Subsystem: "ingest", Name: "ledger_fetch_duration_seconds",
Help: "duration of fetching ledgers from ledger backend, sliding window = 10m",
},
)

s.metrics.CaptiveStellarCoreSynced = prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Namespace: "horizon", Subsystem: "ingest", Name: "captive_stellar_core_synced",
Expand Down

0 comments on commit 68b39bd

Please sign in to comment.