Skip to content

Commit

Permalink
set all metrics to 0 for unregistered quorums (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur authored Apr 26, 2024
1 parent 36307ab commit 1725e3b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions node/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Metrics struct {
onchainMetricsInterval int64
tx core.Transactor
chainState core.ChainState
allQuorumCache map[core.QuorumID]bool
}

func NewMetrics(eigenMetrics eigenmetrics.Metrics, reg *prometheus.Registry, logger logging.Logger, socketAddr string, operatorId core.OperatorID, onchainMetricsInterval int64, tx core.Transactor, chainState core.ChainState) *Metrics {
Expand Down Expand Up @@ -136,6 +137,7 @@ func NewMetrics(eigenMetrics eigenmetrics.Metrics, reg *prometheus.Registry, log
onchainMetricsInterval: onchainMetricsInterval,
tx: tx,
chainState: chainState,
allQuorumCache: make(map[core.QuorumID]bool),
}

return metrics
Expand Down Expand Up @@ -198,6 +200,7 @@ func (g *Metrics) collectOnchainMetrics() {
}
quorumIds := eth.BitmapToQuorumIds(bitmaps[0])
if len(quorumIds) == 0 {
g.ResetQuorumMetrics(blockNum)
g.logger.Warn("This node is currently not in any quorum", "blockNumber", blockNum, "operatorId", g.operatorId.Hex())
continue
}
Expand Down Expand Up @@ -225,12 +228,29 @@ func (g *Metrics) collectOnchainMetrics() {
})
for i, op := range operatorStakeShares {
if op.operatorId == g.operatorId {
g.allQuorumCache[q] = true
g.RegisteredQuorumsStakeShare.WithLabelValues(fmt.Sprintf("%d", q)).Set(op.stakeShare)
g.RegisteredQuorumsRank.WithLabelValues(fmt.Sprintf("%d", q)).Set(float64(i + 1))
g.logger.Info("Current operator registration onchain", "operatorId", g.operatorId.Hex(), "blockNumber", blockNum, "quorumId", q, "stakeShare (basis point)", op.stakeShare, "rank", i+1)
break
}
}
}
// Check if operator deregistered for an existing quorum, set the stake share and rank to 0
g.ResetQuorumMetrics(blockNum)
}
}

func (g *Metrics) ResetQuorumMetrics(blockNum uint32) {
// Check if operator deregistered for an existing quorum, set the stake share and rank to 0
for q := range g.allQuorumCache {
// If this quorum was deregistered then set the stake share and rank to 0
if !g.allQuorumCache[q] {
g.RegisteredQuorumsStakeShare.WithLabelValues(fmt.Sprintf("%d", q)).Set(0)
g.RegisteredQuorumsRank.WithLabelValues(fmt.Sprintf("%d", q)).Set(0)
g.logger.Info("Current operator deregistration onchain", "operatorId", g.operatorId.Hex(), "blockNumber", blockNum, "quorumId", q)
}
// Reset the cache to false for all quorum for next cycle
g.allQuorumCache[q] = false
}
}

0 comments on commit 1725e3b

Please sign in to comment.