Skip to content

Commit ddbf5d2

Browse files
committed
core: expose various counter metrics for grafana (ethereum#19692)
1 parent 65baaaa commit ddbf5d2

File tree

4 files changed

+130
-74
lines changed

4 files changed

+130
-74
lines changed

core/lending_pool.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func (pool *LendingPool) add(tx *types.LendingTransaction, local bool) (bool, er
669669
// If the transaction fails basic validation, discard it
670670
if err := pool.validateTx(tx, local); err != nil {
671671
log.Debug("Discarding invalid lending transaction", "hash", hash, "userAddress", tx.UserAddress, "status", tx.Status, "err", err)
672-
invalidTxCounter.Inc(1)
672+
invalidTxMeter.Mark(1)
673673
return false, err
674674
}
675675
from, _ := types.LendingSender(pool.signer, tx) // already validated
@@ -683,12 +683,12 @@ func (pool *LendingPool) add(tx *types.LendingTransaction, local bool) (bool, er
683683
if list := pool.pending[from]; list != nil && list.Overlaps(tx) {
684684
inserted, old := list.Add(tx)
685685
if !inserted {
686-
pendingDiscardCounter.Inc(1)
686+
pendingDiscardMeter.Mark(1)
687687
return false, ErrPendingNonceTooLow
688688
}
689689
if old != nil {
690690
delete(pool.all, old.Hash())
691-
pendingReplaceCounter.Inc(1)
691+
pendingReplaceMeter.Mark(1)
692692
}
693693
pool.all[tx.Hash()] = tx
694694
pool.journalTx(from, tx)
@@ -724,13 +724,13 @@ func (pool *LendingPool) enqueueTx(hash common.Hash, tx *types.LendingTransactio
724724
inserted, old := pool.queue[from].Add(tx)
725725
if !inserted {
726726
// An older transaction was better, discard this
727-
queuedDiscardCounter.Inc(1)
727+
pendingDiscardMeter.Mark(1)
728728
return false, ErrPendingNonceTooLow
729729
}
730730
// Discard any previous transaction and mark this
731731
if old != nil {
732732
delete(pool.all, old.Hash())
733-
queuedReplaceCounter.Inc(1)
733+
queuedReplaceMeter.Mark(1)
734734
}
735735
pool.all[hash] = tx
736736
return old != nil, nil
@@ -762,13 +762,13 @@ func (pool *LendingPool) promoteTx(addr common.Address, hash common.Hash, tx *ty
762762
if !inserted {
763763
// An older transaction was better, discard this
764764
delete(pool.all, hash)
765-
pendingDiscardCounter.Inc(1)
765+
pendingDiscardMeter.Mark(1)
766766
return
767767
}
768768
// Otherwise discard any previous transaction and mark this
769769
if old != nil {
770770
delete(pool.all, old.Hash())
771-
pendingReplaceCounter.Inc(1)
771+
pendingReplaceMeter.Mark(1)
772772
}
773773
// Failsafe to work around direct pending inserts (tests)
774774
if pool.all[hash] == nil {
@@ -979,7 +979,7 @@ func (pool *LendingPool) promoteExecutables(accounts []common.Address) {
979979
hash := tx.Hash()
980980
delete(pool.all, hash)
981981

982-
queuedRateLimitCounter.Inc(1)
982+
queuedRateLimitMeter.Mark(1)
983983
log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
984984
}
985985
}
@@ -1055,7 +1055,7 @@ func (pool *LendingPool) promoteExecutables(accounts []common.Address) {
10551055
}
10561056
}
10571057
}
1058-
pendingRateLimitCounter.Inc(int64(pendingBeforeCap - pending))
1058+
pendingRateLimitMeter.Mark(int64(pendingBeforeCap - pending))
10591059
}
10601060
// If we've queued more transactions than the hard limit, drop oldest ones
10611061
queued := uint64(0)
@@ -1085,15 +1085,15 @@ func (pool *LendingPool) promoteExecutables(accounts []common.Address) {
10851085
pool.removeTx(tx.Hash())
10861086
}
10871087
drop -= size
1088-
queuedRateLimitCounter.Inc(int64(size))
1088+
queuedRateLimitMeter.Mark(int64(size))
10891089
continue
10901090
}
10911091
// Otherwise drop only last few transactions
10921092
txs := list.Flatten()
10931093
for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
10941094
pool.removeTx(txs[i].Hash())
10951095
drop--
1096-
queuedRateLimitCounter.Inc(1)
1096+
queuedRateLimitMeter.Mark(1)
10971097
}
10981098
}
10991099
}

core/order_pool.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func (pool *OrderPool) add(tx *types.OrderTransaction, local bool) (bool, error)
578578
// If the transaction fails basic validation, discard it
579579
if err := pool.validateTx(tx, local); err != nil {
580580
log.Debug("Discarding invalid order transaction", "hash", hash, "userAddress", tx.UserAddress().Hex(), "status", tx.Status, "err", err)
581-
invalidTxCounter.Inc(1)
581+
invalidTxMeter.Mark(1)
582582
return false, err
583583
}
584584
from, _ := types.OrderSender(pool.signer, tx) // already validated
@@ -592,12 +592,12 @@ func (pool *OrderPool) add(tx *types.OrderTransaction, local bool) (bool, error)
592592
if list := pool.pending[from]; list != nil && list.Overlaps(tx) {
593593
inserted, old := list.Add(tx)
594594
if !inserted {
595-
pendingDiscardCounter.Inc(1)
595+
pendingDiscardMeter.Mark(1)
596596
return false, ErrPendingNonceTooLow
597597
}
598598
if old != nil {
599599
delete(pool.all, old.Hash())
600-
pendingReplaceCounter.Inc(1)
600+
pendingReplaceMeter.Mark(1)
601601
}
602602
pool.all[tx.Hash()] = tx
603603
pool.journalTx(from, tx)
@@ -635,13 +635,13 @@ func (pool *OrderPool) enqueueTx(hash common.Hash, tx *types.OrderTransaction) (
635635
inserted, old := pool.queue[from].Add(tx)
636636
if !inserted {
637637
// An older transaction was better, discard this
638-
queuedDiscardCounter.Inc(1)
638+
queuedDiscardMeter.Mark(1)
639639
return false, ErrPendingNonceTooLow
640640
}
641641
// Discard any previous transaction and mark this
642642
if old != nil {
643643
delete(pool.all, old.Hash())
644-
queuedReplaceCounter.Inc(1)
644+
queuedReplaceMeter.Mark(1)
645645
}
646646
pool.all[hash] = tx
647647
return old != nil, nil
@@ -674,13 +674,13 @@ func (pool *OrderPool) promoteTx(addr common.Address, hash common.Hash, tx *type
674674
if !inserted {
675675
// An older transaction was better, discard this
676676
delete(pool.all, hash)
677-
pendingDiscardCounter.Inc(1)
677+
pendingDiscardMeter.Mark(1)
678678
return
679679
}
680680
// Otherwise discard any previous transaction and mark this
681681
if old != nil {
682682
delete(pool.all, old.Hash())
683-
pendingReplaceCounter.Inc(1)
683+
pendingReplaceMeter.Mark(1)
684684
}
685685
// Failsafe to work around direct pending inserts (tests)
686686
if pool.all[hash] == nil {
@@ -895,7 +895,7 @@ func (pool *OrderPool) promoteExecutables(accounts []common.Address) {
895895
hash := tx.Hash()
896896
delete(pool.all, hash)
897897

898-
queuedRateLimitCounter.Inc(1)
898+
queuedRateLimitMeter.Mark(1)
899899
log.Debug("Removed cap-exceeding queued transaction", "addr", tx.UserAddress().Hex(), "nonce", tx.Nonce(), "ohash", tx.OrderHash().Hex(), "status", tx.Status(), "orderid", tx.OrderID())
900900
}
901901
}
@@ -972,7 +972,7 @@ func (pool *OrderPool) promoteExecutables(accounts []common.Address) {
972972
}
973973
}
974974
}
975-
pendingRateLimitCounter.Inc(int64(pendingBeforeCap - pending))
975+
pendingRateLimitMeter.Mark(int64(pendingBeforeCap - pending))
976976
}
977977
// If we've queued more transactions than the hard limit, drop oldest ones
978978
queued := uint64(0)
@@ -1002,15 +1002,15 @@ func (pool *OrderPool) promoteExecutables(accounts []common.Address) {
10021002
pool.removeTx(tx.Hash())
10031003
}
10041004
drop -= size
1005-
queuedRateLimitCounter.Inc(int64(size))
1005+
queuedRateLimitMeter.Mark(int64(size))
10061006
continue
10071007
}
10081008
// Otherwise drop only last few transactions
10091009
txs := list.Flatten()
10101010
for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
10111011
pool.removeTx(txs[i].Hash())
10121012
drop--
1013-
queuedRateLimitCounter.Inc(1)
1013+
queuedRateLimitMeter.Mark(1)
10141014
}
10151015
}
10161016
}

core/tx_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ func (l *txPricedList) Put(tx *types.Transaction) {
429429
// Removed notifies the prices transaction list that an old transaction dropped
430430
// from the pool. The list will just keep a counter of stale objects and update
431431
// the heap if a large enough ratio of transactions go stale.
432-
func (l *txPricedList) Removed() {
432+
func (l *txPricedList) Removed(count int) {
433433
// Bump the stale counter, but exit if still too low (< 25%)
434-
l.stales++
434+
l.stales += count
435435
if l.stales <= len(*l.items)/4 {
436436
return
437437
}

0 commit comments

Comments
 (0)