Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sew): measure latency (#105) #107

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements
* [#105](https://github.com/babylonlabs-io/vigilante/pull/105) Measure latency

## v0.16.0

* [#94](https://github.com/babylonlabs-io/vigilante/pull/94) adds gosec and fixes gosec issues
Expand Down
15 changes: 15 additions & 0 deletions btcstaking-tracker/stakingeventwatcher/stakingeventwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (sew *StakingEventWatcher) handleNewBlocks(blockNotifier *notifier.BlockEpo
// checkBabylonDelegations iterates over all active babylon delegations, and reports not already
// tracked delegations to the unbondingDelegationChan
func (sew *StakingEventWatcher) checkBabylonDelegations(status btcstakingtypes.BTCDelegationStatus, addDel func(del Delegation)) error {
defer sew.latency(fmt.Sprintf("checkBabylonDelegations: %s", status))()

var i = uint64(0)
for {
delegations, err := sew.babylonNodeAdapter.DelegationsByStatus(status, i, sew.cfg.NewDelegationsBatchSize)
Expand Down Expand Up @@ -610,6 +612,8 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
ctx, cancel := sew.quitContext()
defer cancel()

defer sew.latency("activateBtcDelegation")()

if err := sew.pendingTracker.UpdateActivation(stakingTxHash, true); err != nil {
sew.logger.Debugf("skipping tx %s is not in pending tracker, err: %v", stakingTxHash, err)
}
Expand Down Expand Up @@ -647,3 +651,14 @@ func (sew *StakingEventWatcher) activateBtcDelegation(
}),
)
}

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.Duration("latency", duration))
sew.metrics.MethodExecutionLatency.WithLabelValues(method).Observe(duration.Seconds())
}
}
6 changes: 6 additions & 0 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
MethodExecutionLatency *prometheus.HistogramVec
}

func newUnbondingWatcherMetrics(registry *prometheus.Registry) *UnbondingWatcherMetrics {
Expand Down Expand Up @@ -66,6 +67,11 @@ func newUnbondingWatcherMetrics(registry *prometheus.Registry) *UnbondingWatcher
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},
}, []string{"method"}),
}

return uwMetrics
Expand Down
Loading