Skip to content

Commit

Permalink
add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Mar 29, 2024
1 parent 0fd87f1 commit 4c1224e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ testnet.g
dist/
/docker/networksimulator/docker-compose.yaml
/docker/networksimulator/prometheus/prometheus.yml
/docker/networksimulator/.env
12 changes: 12 additions & 0 deletions gossip/emitter/control.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emitter

import (
"github.com/ethereum/go-ethereum/metrics"
"time"

"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
Expand All @@ -11,6 +12,11 @@ import (
"github.com/Fantom-foundation/go-opera/inter"
)

var (
allowedToEmitCount = metrics.GetOrRegisterGauge("opera/control/allowedToEmit", nil)
notAllowedToEmitCount = metrics.GetOrRegisterGauge("opera/control/notAllowedToEmit", nil)
)

func scalarUpdMetric(diff idx.Event, weight pos.Weight, totalWeight pos.Weight) ancestor.Metric {
return ancestor.Metric(scalarUpdMetricF(uint64(diff)*piecefunc.DecimalUnit)) * ancestor.Metric(weight) / ancestor.Metric(totalWeight)
}
Expand Down Expand Up @@ -73,6 +79,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
"power", e.GasPowerLeft().String(),
"selfParentPower", selfParent.GasPowerLeft().String(),
"stake%", 100*float64(em.validators.Get(e.Creator()))/float64(em.validators.TotalWeight()))
notAllowedToEmitCount.Inc(1)
return false
}
}
Expand All @@ -87,6 +94,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
if passedTime >= em.intervals.Max ||
passedBlocks >= maxBlocks*4/5 && metric >= piecefunc.DecimalUnit/2 ||
passedBlocks >= maxBlocks {
allowedToEmitCount.Inc(1)
return true
}
}
Expand All @@ -109,6 +117,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
if passedTime < em.intervals.Max &&
em.idle() &&
!eTxs {
notAllowedToEmitCount.Inc(1)
return false
}
}
Expand All @@ -119,15 +128,18 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
}
if adjustedPassedTime < em.intervals.Min &&
!em.idle() {
notAllowedToEmitCount.Inc(1)
return false
}
if adjustedPassedIdleTime < em.intervals.Confirming &&
!em.idle() &&
!eTxs {
notAllowedToEmitCount.Inc(1)
return false
}
}

allowedToEmitCount.Inc(1)
return true
}

Expand Down
9 changes: 9 additions & 0 deletions gossip/emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (
)

var eventCounter = metrics.GetOrRegisterCounter("opera/events", nil)
var callCreatedCounter = metrics.GetOrRegisterCounter("opera/events/callCreated", nil)
var callEmitCounter = metrics.GetOrRegisterCounter("opera/events/callEmit", nil)
var worldBusyGauge = metrics.GetOrRegisterGauge("opera/events/worldBusy", nil)

type Emitter struct {
config Config
Expand Down Expand Up @@ -189,7 +192,10 @@ func (em *Emitter) tick() {
em.busyRate.Mark(1)
}
if em.world.IsBusy() {
worldBusyGauge.Update(1)
return
} else {
worldBusyGauge.Update(0)
}

em.recheckChallenges()
Expand Down Expand Up @@ -233,6 +239,8 @@ func (em *Emitter) EmitEvent() (*inter.EventPayload, error) {
// short circuit if not a validator
return nil, nil
}
callEmitCounter.Inc(1)

sortedTxs := em.getSortedTxs()

if em.world.IsBusy() {
Expand Down Expand Up @@ -295,6 +303,7 @@ func (em *Emitter) createEvent(sortedTxs *types.TransactionsByPriceAndNonce) (*i
if !em.isValidator() {
return nil, nil
}
callCreatedCounter.Inc(1)

if synced := em.logSyncStatus(em.isSyncedToEmit()); !synced {
// I'm reindexing my old events, so don't create events until connect all the existing self-events
Expand Down
2 changes: 2 additions & 0 deletions gossip/emitter/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
isMyTurnCounter = metrics.GetOrRegisterCounter("opera/txs/isMyTurn", nil)
isNotMyTurnCounter = metrics.GetOrRegisterCounter("opera/txs/isNotMyTurn", nil)
outdatedCounter = metrics.GetOrRegisterCounter("opera/txs/outdated", nil)
invalidTxCounter = metrics.GetOrRegisterCounter("opera/txs/invalidTxCounter", nil)

gasPowerUsedGauge = metrics.GetOrRegisterGauge("opera/txs/gasPowerUsed", nil)
gasPowerLeftShortGauge = metrics.GetOrRegisterGauge("opera/txs/gasPowerLeftShort", nil)
Expand Down Expand Up @@ -156,6 +157,7 @@ func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.Transactio
sender, _ := types.Sender(em.world.TxSigner, tx)
// check transaction epoch rules
if epochcheck.CheckTxs(types.Transactions{tx}, rules) != nil {
invalidTxCounter.Inc(1)
sorted.Pop()
continue
}
Expand Down

0 comments on commit 4c1224e

Please sign in to comment.