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

feat(zetaclient): add TSS sign latency histogram #2567

Merged
merged 2 commits into from
Jul 26, 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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [2497](https://github.com/zeta-chain/node/pull/2416) - support for runtime chain (de)provisioning
* [2518](https://github.com/zeta-chain/node/pull/2518) - add support for Solana address in zetacore
* [2483](https://github.com/zeta-chain/node/pull/2483) - add priorityFee (gasTipCap) gas to the state
* [2567](https://github.com/zeta-chain/node/pull/2567) - add sign latency metric to zetaclient (zetaclient_sign_latency)

### Refactor

Expand Down
2 changes: 0 additions & 2 deletions contrib/localnet/docker-compose-monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ services:
hostname: prometheus
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
mynetwork:
ipv4_address: 172.20.0.31
Expand Down
8 changes: 8 additions & 0 deletions zetaclient/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ var (
Name: "percentage_of_rate_reached",
Help: "Percentage of the rate limiter rate reached",
})

// SignLatency is a histogram of of the TSS keysign latency
SignLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ZetaClientNamespace,
Name: "sign_latency",
Help: "Histogram of the TSS keysign latency",
Buckets: []float64{1, 7, 15, 30, 60, 120, 240},
}, []string{"result"})
)

// NewMetrics creates a new Metrics instance
Expand Down
33 changes: 23 additions & 10 deletions zetaclient/tss/concurrent_keysigns_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package tss

import (
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"

"github.com/zeta-chain/zetacore/zetaclient/metrics"
Expand All @@ -25,26 +27,37 @@ func NewKeysignsTracker(logger zerolog.Logger) *ConcurrentKeysignsTracker {
}

// StartMsgSign is incrementing the number of active signing ceremonies as well as updating the prometheus metric
func (k *ConcurrentKeysignsTracker) StartMsgSign() {
//
// Call the returned function to signify the signing is complete
func (k *ConcurrentKeysignsTracker) StartMsgSign() func(bool) {
k.mu.Lock()
defer k.mu.Unlock()
k.numActiveMsgSigns++
metrics.NumActiveMsgSigns.Inc()
k.Logger.Debug().Msgf("Start TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns)
}

// EndMsgSign is decrementing the number of active signing ceremonies as well as updating the prometheus metric
func (k *ConcurrentKeysignsTracker) EndMsgSign() {
k.mu.Lock()
defer k.mu.Unlock()
if k.numActiveMsgSigns > 0 {
k.numActiveMsgSigns--
metrics.NumActiveMsgSigns.Dec()
startTime := time.Now()

return func(hasError bool) {
k.mu.Lock()
defer k.mu.Unlock()
if k.numActiveMsgSigns > 0 {
k.numActiveMsgSigns--
metrics.NumActiveMsgSigns.Dec()
}
k.Logger.Debug().Msgf("End TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns)

result := "success"
if hasError {
result = "error"
}
metrics.SignLatency.With(prometheus.Labels{"result": result}).Observe(time.Since(startTime).Seconds())
}
k.Logger.Debug().Msgf("End TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns)
}

// GetNumActiveMessageSigns gets the current number of active signing ceremonies
func (k *ConcurrentKeysignsTracker) GetNumActiveMessageSigns() int64 {
k.mu.Lock()
gartnera marked this conversation as resolved.
Show resolved Hide resolved
defer k.mu.Unlock()
return k.numActiveMsgSigns
}
9 changes: 4 additions & 5 deletions zetaclient/tss/concurrent_keysigns_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ func TestKeySignManager_StartMsgSign(t *testing.T) {

func TestKeySignManager_EndMsgSign(t *testing.T) {
ksman := NewKeysignsTracker(zerolog.Logger{})
ksman.StartMsgSign()
ksman.StartMsgSign()
ksman.EndMsgSign()
ksman.EndMsgSign()
ksman.EndMsgSign()
end1 := ksman.StartMsgSign()
end2 := ksman.StartMsgSign()
end1(true)
end2(false)
require.Equal(t, int64(0), ksman.GetNumActiveMessageSigns())
}
8 changes: 4 additions & 4 deletions zetaclient/tss/tss_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@
nil,
"0.14.0",
)
tss.KeysignsTracker.StartMsgSign()
end := tss.KeysignsTracker.StartMsgSign()

Check warning on line 249 in zetaclient/tss/tss_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/tss/tss_signer.go#L249

Added line #L249 was not covered by tests
ksRes, err := tss.Server.KeySign(keysignReq)
tss.KeysignsTracker.EndMsgSign()
end(err != nil || ksRes.Status == thorcommon.Fail)

Check warning on line 251 in zetaclient/tss/tss_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/tss/tss_signer.go#L251

Added line #L251 was not covered by tests
if err != nil {
log.Warn().Msg("keysign fail")
}
Expand Down Expand Up @@ -328,9 +328,9 @@
// #nosec G115 always in range
keysignReq := keysign.NewRequest(tssPubkey, digestBase64, int64(height), nil, "0.14.0")

tss.KeysignsTracker.StartMsgSign()
end := tss.KeysignsTracker.StartMsgSign()

Check warning on line 331 in zetaclient/tss/tss_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/tss/tss_signer.go#L331

Added line #L331 was not covered by tests
ksRes, err := tss.Server.KeySign(keysignReq)
tss.KeysignsTracker.EndMsgSign()
end(err != nil || ksRes.Status == thorcommon.Fail)

Check warning on line 333 in zetaclient/tss/tss_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/tss/tss_signer.go#L333

Added line #L333 was not covered by tests
gartnera marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Warn().Err(err).Msg("keysign fail")
}
Expand Down
Loading