Skip to content

Commit

Permalink
chore(bstracker): add more metrics (#123)
Browse files Browse the repository at this point in the history
Adds more metrics for better visibility
  • Loading branch information
Lazar955 committed Nov 29, 2024
1 parent e5f4ed8 commit 4cf377f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#123](https://github.com/babylonlabs-io/vigilante/pull/123) more metrics for bstracker

## v0.17.1

### Improvements
Expand Down
16 changes: 13 additions & 3 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
inclusionBlockHash chainhash.Hash,
requiredDepth uint32,
) {
sew.metrics.NumberOfActivationInProgress.Inc()
defer sew.metrics.NumberOfActivationInProgress.Dec()

ctx, cancel := sew.quitContext()
defer cancel()

Expand All @@ -628,8 +631,17 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
sew.logger.Debugf("skipping tx %s is not in pending tracker, err: %v", stakingTxHash, err)
}

defer func() {
// in case we don't succeed activating, reset the in progress flag
if err := sew.pendingTracker.UpdateActivation(stakingTxHash, false); err != nil {
sew.logger.Debugf("skipping tx %s is not in pending tracker [this is ok], err: %v", stakingTxHash, err)
}
}()

sew.waitForRequiredDepth(ctx, stakingTxHash, &inclusionBlockHash, requiredDepth)

defer sew.latency("activateDelegationRPC")()

_ = retry.Do(func() error {
verified, err := sew.babylonNodeAdapter.IsDelegationVerified(stakingTxHash)
if err != nil {
Expand Down Expand Up @@ -707,9 +719,7 @@ func (sew *StakingEventWatcher) latency(method string) func() {
startTime := time.Now()
return func() {
duration := time.Since(startTime)
sew.logger.Debug("execution time",
zap.String("method", method),
zap.String("latency", duration.String()))
sew.logger.Debugf("execution time for method: %s, duration: %s", method, duration.String())
sew.metrics.MethodExecutionLatency.WithLabelValues(method).Observe(duration.Seconds())
}
}
48 changes: 31 additions & 17 deletions metrics/btcstaking_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type UnbondingWatcherMetrics struct {
DetectedNonUnbondingTransactionsCounter prometheus.Counter
FailedReportedActivateDelegations prometheus.Counter
ReportedActivateDelegationsCounter prometheus.Counter
NumberOfActivationInProgress prometheus.Gauge
MethodExecutionLatency *prometheus.HistogramVec
}

Expand All @@ -40,38 +41,51 @@ func newUnbondingWatcherMetrics(registry *prometheus.Registry) *UnbondingWatcher
uwMetrics := &UnbondingWatcherMetrics{
Registry: registry,
ReportedUnbondingTransactionsCounter: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_reported_unbonding_transactions",
Help: "The total number of unbonding transactions successfully reported to Babylon node",
Namespace: "vigilante",
Name: "unbonding_watcher_reported_unbonding_transactions",
Help: "The total number of unbonding transactions successfully reported to Babylon node",
}),
FailedReportedUnbondingTransactions: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_failed_reported_unbonding_transactions",
Help: "The total number times reporting unbonding transactions to Babylon node failed",
Namespace: "vigilante",
Name: "unbonding_watcher_failed_reported_unbonding_transactions",
Help: "The total number times reporting unbonding transactions to Babylon node failed",
}),
NumberOfTrackedActiveDelegations: registerer.NewGauge(prometheus.GaugeOpts{
Name: "unbonding_watcher_tracked_active_delegations",
Help: "The number of active delegations tracked by unbonding watcher",
Namespace: "vigilante",
Name: "unbonding_watcher_tracked_active_delegations",
Help: "The number of active delegations tracked by unbonding watcher",
}),
DetectedUnbondingTransactionsCounter: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_detected_unbonding_transactions",
Help: "The total number of unbonding transactions detected by unbonding watcher",
Namespace: "vigilante",
Name: "unbonding_watcher_detected_unbonding_transactions",
Help: "The total number of unbonding transactions detected by unbonding watcher",
}),
DetectedNonUnbondingTransactionsCounter: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_detected_non_unbonding_transactions",
Help: "The total number of non unbonding (slashing or withdrawal) transactions detected by unbonding watcher",
Namespace: "vigilante",
Name: "unbonding_watcher_detected_non_unbonding_transactions",
Help: "The total number of non unbonding (slashing or withdrawal) transactions detected by unbonding watcher",
}),
FailedReportedActivateDelegations: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_failed_reported_activate_delegation",
Help: "The total number times reporting activation delegation failed on Babylon node",
Namespace: "vigilante",
Name: "unbonding_watcher_failed_reported_activate_delegation",
Help: "The total number times reporting activation delegation failed on Babylon node",
}),
ReportedActivateDelegationsCounter: registerer.NewCounter(prometheus.CounterOpts{
Name: "unbonding_watcher_reported_activate_delegations",
Help: "The total number of unbonding transactions successfully reported to Babylon node",
Namespace: "vigilante",
Name: "unbonding_watcher_reported_activate_delegations",
Help: "The total number of unbonding transactions successfully reported to Babylon node",
}),
MethodExecutionLatency: registerer.NewHistogramVec(prometheus.HistogramOpts{
Name: "unbonding_watcher_method_latency_seconds",
Help: "Latency in seconds",
Buckets: []float64{.001, .002, .005, .01, .025, .05, .1},
Namespace: "vigilante",
Name: "unbonding_watcher_method_latency_seconds",
Help: "Latency in seconds",
Buckets: []float64{.001, .002, .005, .01, .025, .05, .1},
}, []string{"method"}),
NumberOfActivationInProgress: registerer.NewGauge(prometheus.GaugeOpts{
Namespace: "vigilante",
Name: "unbonding_watcher_number_of_activation_in_progress",
Help: "The number of activations in progress",
}),
}

return uwMetrics
Expand Down

0 comments on commit 4cf377f

Please sign in to comment.