Skip to content

Commit

Permalink
Move metrics update to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Oct 22, 2020
1 parent cf68d25 commit d6f557b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions services/horizon/internal/ingest/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,10 @@ func (r resumeState) run(s *system) (transition, error) {

// Update stats metrics
changeStatsMap := changeStats.Map()
for stat, value := range changeStatsMap {
stat = strings.Replace(stat, "stats_", "change_", 1)
s.Metrics().LedgerStatsCounter.
With(prometheus.Labels{"type": stat}).Add(float64(value.(int64)))
}
r.addLedgerStatsMetricFromMap(s, "change", changeStatsMap)

ledgerTransactionStatsMap := ledgerTransactionStats.Map()
for stat, value := range ledgerTransactionStatsMap {
stat = strings.Replace(stat, "stats_", "ledger_", 1)
s.Metrics().LedgerStatsCounter.
With(prometheus.Labels{"type": stat}).Add(float64(value.(int64)))
}
r.addLedgerStatsMetricFromMap(s, "ledger", ledgerTransactionStatsMap)

log.
WithFields(changeStatsMap).
Expand All @@ -506,6 +498,14 @@ func (r resumeState) run(s *system) (transition, error) {
return resumeImmediately(ingestLedger), nil
}

func (r resumeState) addLedgerStatsMetricFromMap(s *system, prefix string, m map[string]interface{}) {
for stat, value := range m {
stat = strings.Replace(stat, "stats_", prefix+"_", 1)
s.Metrics().LedgerStatsCounter.
With(prometheus.Labels{"type": stat}).Add(float64(value.(int64)))
}
}

type historyRangeState struct {
fromLedger uint32
toLedger uint32
Expand Down

0 comments on commit d6f557b

Please sign in to comment.