Skip to content

Commit c853ddc

Browse files
jackyspAndreMouche
andauthored
metrics: add txn ttl lifetime (#766)
Signed-off-by: Jack Yu <[email protected]> Co-authored-by: Shirly <[email protected]>
1 parent 67e56a9 commit c853ddc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

metrics/metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var (
7575
TiKVRangeTaskPushDuration *prometheus.HistogramVec
7676
TiKVTokenWaitDuration prometheus.Histogram
7777
TiKVTxnHeartBeatHistogram *prometheus.HistogramVec
78+
TiKVTTLManagerHistogram prometheus.Histogram
7879
TiKVPessimisticLockKeysDuration prometheus.Histogram
7980
TiKVTTLLifeTimeReachCounter prometheus.Counter
8081
TiKVNoAvailableConnectionCounter prometheus.Counter
@@ -422,6 +423,15 @@ func initMetrics(namespace, subsystem string) {
422423
Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms ~ 524s
423424
}, []string{LblType})
424425

426+
TiKVTTLManagerHistogram = prometheus.NewHistogram(
427+
prometheus.HistogramOpts{
428+
Namespace: namespace,
429+
Subsystem: subsystem,
430+
Name: "txn_ttl_manager",
431+
Help: "Bucketed histogram of the txn ttl manager lifetime duration.",
432+
Buckets: prometheus.ExponentialBuckets(1, 2, 20), // 1s ~ 524288s
433+
})
434+
425435
TiKVPessimisticLockKeysDuration = prometheus.NewHistogram(
426436
prometheus.HistogramOpts{
427437
Namespace: namespace,
@@ -677,6 +687,7 @@ func RegisterMetrics() {
677687
prometheus.MustRegister(TiKVRangeTaskPushDuration)
678688
prometheus.MustRegister(TiKVTokenWaitDuration)
679689
prometheus.MustRegister(TiKVTxnHeartBeatHistogram)
690+
prometheus.MustRegister(TiKVTTLManagerHistogram)
680691
prometheus.MustRegister(TiKVPessimisticLockKeysDuration)
681692
prometheus.MustRegister(TiKVTTLLifeTimeReachCounter)
682693
prometheus.MustRegister(TiKVNoAvailableConnectionCounter)

txnkv/transaction/2pc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ func keepAlive(c *twoPhaseCommitter, closeCh chan struct{}, primaryKey []byte, l
11441144
// Ticker is set to 1/2 of the ManagedLockTTL.
11451145
ticker := time.NewTicker(time.Duration(atomic.LoadUint64(&ManagedLockTTL)) * time.Millisecond / 2)
11461146
defer ticker.Stop()
1147+
startKeepAlive := time.Now()
1148+
defer func() {
1149+
metrics.TiKVTTLManagerHistogram.Observe(time.Since(startKeepAlive).Seconds())
1150+
}()
11471151
keepFail := 0
11481152
for {
11491153
select {

0 commit comments

Comments
 (0)