Skip to content

Commit

Permalink
metrics: add txn ttl lifetime (#766)
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jackysp@gmail.com>
Co-authored-by: Shirly <AndreMouche@126.com>
  • Loading branch information
jackysp and AndreMouche committed Apr 14, 2023
1 parent 67e56a9 commit c853ddc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var (
TiKVRangeTaskPushDuration *prometheus.HistogramVec
TiKVTokenWaitDuration prometheus.Histogram
TiKVTxnHeartBeatHistogram *prometheus.HistogramVec
TiKVTTLManagerHistogram prometheus.Histogram
TiKVPessimisticLockKeysDuration prometheus.Histogram
TiKVTTLLifeTimeReachCounter prometheus.Counter
TiKVNoAvailableConnectionCounter prometheus.Counter
Expand Down Expand Up @@ -422,6 +423,15 @@ func initMetrics(namespace, subsystem string) {
Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms ~ 524s
}, []string{LblType})

TiKVTTLManagerHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "txn_ttl_manager",
Help: "Bucketed histogram of the txn ttl manager lifetime duration.",
Buckets: prometheus.ExponentialBuckets(1, 2, 20), // 1s ~ 524288s
})

TiKVPessimisticLockKeysDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Expand Down Expand Up @@ -677,6 +687,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVRangeTaskPushDuration)
prometheus.MustRegister(TiKVTokenWaitDuration)
prometheus.MustRegister(TiKVTxnHeartBeatHistogram)
prometheus.MustRegister(TiKVTTLManagerHistogram)
prometheus.MustRegister(TiKVPessimisticLockKeysDuration)
prometheus.MustRegister(TiKVTTLLifeTimeReachCounter)
prometheus.MustRegister(TiKVNoAvailableConnectionCounter)
Expand Down
4 changes: 4 additions & 0 deletions txnkv/transaction/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ func keepAlive(c *twoPhaseCommitter, closeCh chan struct{}, primaryKey []byte, l
// Ticker is set to 1/2 of the ManagedLockTTL.
ticker := time.NewTicker(time.Duration(atomic.LoadUint64(&ManagedLockTTL)) * time.Millisecond / 2)
defer ticker.Stop()
startKeepAlive := time.Now()
defer func() {
metrics.TiKVTTLManagerHistogram.Observe(time.Since(startKeepAlive).Seconds())
}()
keepFail := 0
for {
select {
Expand Down

0 comments on commit c853ddc

Please sign in to comment.