diff --git a/CHANGELOG.md b/CHANGELOG.md index 75d2424..3585d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go index 1309055..19810c2 100644 --- a/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go +++ b/btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go @@ -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() @@ -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 { @@ -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()) } } diff --git a/metrics/btcstaking_tracker.go b/metrics/btcstaking_tracker.go index cf32a64..177a8b2 100644 --- a/metrics/btcstaking_tracker.go +++ b/metrics/btcstaking_tracker.go @@ -31,6 +31,7 @@ type UnbondingWatcherMetrics struct { DetectedNonUnbondingTransactionsCounter prometheus.Counter FailedReportedActivateDelegations prometheus.Counter ReportedActivateDelegationsCounter prometheus.Counter + NumberOfActivationInProgress prometheus.Gauge MethodExecutionLatency *prometheus.HistogramVec } @@ -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