Skip to content

Commit

Permalink
Address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc committed May 14, 2024
1 parent b2662ce commit 0130407
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions avssync/avssync.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewAvsSync(
prometheusServerAddr string,
prometheusRegistry *prometheus.Registry,
) *AvsSync {
metrics := NewMetrics(prometheusRegistry, prometheusServerAddr)
metrics := NewMetrics(prometheusRegistry)

return &AvsSync{
AvsReader: avsReader,
Expand Down Expand Up @@ -135,7 +135,7 @@ func (a *AvsSync) updateStakes() {
if err != nil {
// no quorum label means we are updating all quorums
for _, quorum := range a.quorums {
a.Metrics.UpdateStakeAttempt(UpdateStakeStatusError, strconv.Itoa(int(quorum)))
a.Metrics.UpdateStakeAttemptInc(UpdateStakeStatusError, strconv.Itoa(int(quorum)))
}
a.logger.Error("Error updating stakes of operator subset for all quorums", err)
return
Expand Down Expand Up @@ -203,14 +203,14 @@ func (a *AvsSync) tryNTimesUpdateStakesOfEntireOperatorSetForQuorum(quorum byte,
}

// Update metrics on success
a.Metrics.UpdateStakeAttempt(UpdateStakeStatusSucceed, strconv.Itoa(int(quorum)))
a.Metrics.UpdateStakeAttemptInc(UpdateStakeStatusSucceed, strconv.Itoa(int(quorum)))
a.Metrics.OperatorsUpdatedSet(strconv.Itoa(int(quorum)), len(operators))

return
}

// Update metrics on failure
a.Metrics.UpdateStakeAttempt(UpdateStakeStatusError, strconv.Itoa(int(quorum)))
a.Metrics.UpdateStakeAttemptInc(UpdateStakeStatusError, strconv.Itoa(int(quorum)))
a.logger.Error("Giving up after retrying", "retryNTimes", retryNTimes)
}

Expand Down
21 changes: 10 additions & 11 deletions avssync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ const (
)

type Metrics struct {
UpdateStakeAttempts *prometheus.CounterVec
TxRevertedTotal prometheus.Counter
OperatorsUpdated *prometheus.GaugeVec
updateStakeAttempts *prometheus.CounterVec
txRevertedTotal prometheus.Counter
operatorsUpdated *prometheus.GaugeVec

registry *prometheus.Registry
}

func NewMetrics(reg *prometheus.Registry) *Metrics {
metrics := &Metrics{
UpdateStakeAttempts: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
updateStakeAttempts: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNamespace,
Name: "update_stake_attempt",
Help: "Result from an update stake attempt. Either succeed or error (either tx was mined but reverted, or failed to get processed by chain).",
}, []string{"status", "quorum"}),

TxRevertedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
txRevertedTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: metricsNamespace,
Name: "tx_reverted_total",
Help: "The total number of transactions that made it onchain but reverted (most likely because out of gas)",
}),

OperatorsUpdated: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
operatorsUpdated: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "operators_updated",
Help: "The total number of operators updated (during the last quorum sync)",
Expand All @@ -51,17 +51,16 @@ func NewMetrics(reg *prometheus.Registry) *Metrics {
return metrics
}

func (g *Metrics) UpdateStakeAttempt(status UpdateStakeStatus, quorum string) {
g.UpdateStakeAttempts.WithLabelValues(string(status), quorum).Inc()
func (g *Metrics) UpdateStakeAttemptInc(status UpdateStakeStatus, quorum string) {
g.updateStakeAttempts.WithLabelValues(string(status), quorum).Inc()
}

func (g *Metrics) TxRevertedTotalInc() {
g.TxRevertedTotal.Inc()
g.txRevertedTotal.Inc()
}

// operatorsUpdated.With(prometheus.Labels{"quorum": strconv.Itoa(int(quorum))}).Set(float64(len(operators)))
func (g *Metrics) OperatorsUpdatedSet(quorum string, operators int) {
g.OperatorsUpdated.WithLabelValues(quorum).Set(float64(operators))
g.operatorsUpdated.WithLabelValues(quorum).Set(float64(operators))
}

func (g *Metrics) Start(metricsAddr string) {
Expand Down

0 comments on commit 0130407

Please sign in to comment.