Skip to content

Commit be48f07

Browse files
authored
feat(zetaclient): add TSS sign latency histogram (#2567)
* feat(zetaclient): add TSS sign latency histogram * add changelog entry and another bin
1 parent 545896d commit be48f07

6 files changed

+40
-21
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* [2497](https://github.com/zeta-chain/node/pull/2416) - support for runtime chain (de)provisioning
3636
* [2518](https://github.com/zeta-chain/node/pull/2518) - add support for Solana address in zetacore
3737
* [2483](https://github.com/zeta-chain/node/pull/2483) - add priorityFee (gasTipCap) gas to the state
38+
* [2567](https://github.com/zeta-chain/node/pull/2567) - add sign latency metric to zetaclient (zetaclient_sign_latency)
3839

3940
### Refactor
4041

contrib/localnet/docker-compose-monitoring.yml

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ services:
1818
hostname: prometheus
1919
volumes:
2020
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
21-
ports:
22-
- "9090:9090"
2321
networks:
2422
mynetwork:
2523
ipv4_address: 172.20.0.31

zetaclient/metrics/metrics.go

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ var (
104104
Name: "percentage_of_rate_reached",
105105
Help: "Percentage of the rate limiter rate reached",
106106
})
107+
108+
// SignLatency is a histogram of of the TSS keysign latency
109+
SignLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
110+
Namespace: ZetaClientNamespace,
111+
Name: "sign_latency",
112+
Help: "Histogram of the TSS keysign latency",
113+
Buckets: []float64{1, 7, 15, 30, 60, 120, 240},
114+
}, []string{"result"})
107115
)
108116

109117
// NewMetrics creates a new Metrics instance

zetaclient/tss/concurrent_keysigns_tracker.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package tss
22

33
import (
44
"sync"
5+
"time"
56

7+
"github.com/prometheus/client_golang/prometheus"
68
"github.com/rs/zerolog"
79

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

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

36-
// EndMsgSign is decrementing the number of active signing ceremonies as well as updating the prometheus metric
37-
func (k *ConcurrentKeysignsTracker) EndMsgSign() {
38-
k.mu.Lock()
39-
defer k.mu.Unlock()
40-
if k.numActiveMsgSigns > 0 {
41-
k.numActiveMsgSigns--
42-
metrics.NumActiveMsgSigns.Dec()
39+
startTime := time.Now()
40+
41+
return func(hasError bool) {
42+
k.mu.Lock()
43+
defer k.mu.Unlock()
44+
if k.numActiveMsgSigns > 0 {
45+
k.numActiveMsgSigns--
46+
metrics.NumActiveMsgSigns.Dec()
47+
}
48+
k.Logger.Debug().Msgf("End TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns)
49+
50+
result := "success"
51+
if hasError {
52+
result = "error"
53+
}
54+
metrics.SignLatency.With(prometheus.Labels{"result": result}).Observe(time.Since(startTime).Seconds())
4355
}
44-
k.Logger.Debug().Msgf("End TSS message sign, numActiveMsgSigns: %d", k.numActiveMsgSigns)
4556
}
4657

4758
// GetNumActiveMessageSigns gets the current number of active signing ceremonies
4859
func (k *ConcurrentKeysignsTracker) GetNumActiveMessageSigns() int64 {
60+
k.mu.Lock()
61+
defer k.mu.Unlock()
4962
return k.numActiveMsgSigns
5063
}

zetaclient/tss/concurrent_keysigns_tracker_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ func TestKeySignManager_StartMsgSign(t *testing.T) {
1818

1919
func TestKeySignManager_EndMsgSign(t *testing.T) {
2020
ksman := NewKeysignsTracker(zerolog.Logger{})
21-
ksman.StartMsgSign()
22-
ksman.StartMsgSign()
23-
ksman.EndMsgSign()
24-
ksman.EndMsgSign()
25-
ksman.EndMsgSign()
21+
end1 := ksman.StartMsgSign()
22+
end2 := ksman.StartMsgSign()
23+
end1(true)
24+
end2(false)
2625
require.Equal(t, int64(0), ksman.GetNumActiveMessageSigns())
2726
}

zetaclient/tss/tss_signer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ func (tss *TSS) Sign(
246246
nil,
247247
"0.14.0",
248248
)
249-
tss.KeysignsTracker.StartMsgSign()
249+
end := tss.KeysignsTracker.StartMsgSign()
250250
ksRes, err := tss.Server.KeySign(keysignReq)
251-
tss.KeysignsTracker.EndMsgSign()
251+
end(err != nil || ksRes.Status == thorcommon.Fail)
252252
if err != nil {
253253
log.Warn().Msg("keysign fail")
254254
}
@@ -328,9 +328,9 @@ func (tss *TSS) SignBatch(
328328
// #nosec G115 always in range
329329
keysignReq := keysign.NewRequest(tssPubkey, digestBase64, int64(height), nil, "0.14.0")
330330

331-
tss.KeysignsTracker.StartMsgSign()
331+
end := tss.KeysignsTracker.StartMsgSign()
332332
ksRes, err := tss.Server.KeySign(keysignReq)
333-
tss.KeysignsTracker.EndMsgSign()
333+
end(err != nil || ksRes.Status == thorcommon.Fail)
334334
if err != nil {
335335
log.Warn().Err(err).Msg("keysign fail")
336336
}

0 commit comments

Comments
 (0)