Skip to content

Commit

Permalink
add more metrics to bstracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Nov 29, 2024
1 parent 2d3a35b commit 60e2421
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
17 changes: 14 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 @@ -662,6 +674,7 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
sew.logger.Debugf("retrying to submit activation tx, for staking tx: %s. Attempt: %d. Err: %v", stakingTxHash, n, err)
}),
)

}

Check failure on line 678 in btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

unnecessary trailing newline (whitespace)

func (sew *StakingEventWatcher) waitForRequiredDepth(
Expand Down Expand Up @@ -707,9 +720,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 60e2421

Please sign in to comment.