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

store, metrics: Add metrics for safetTS updating #24687

Merged
merged 6 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"math"
"math/rand"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -414,17 +415,20 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
storeAddr := store.addr
go func(ctx context.Context, wg *sync.WaitGroup, storeID uint64, storeAddr string) {
defer wg.Done()
// TODO: add metrics for updateSafeTS
resp, err := tikvClient.SendRequest(ctx, storeAddr, tikvrpc.NewRequest(tikvrpc.CmdStoreSafeTS, &kvrpcpb.StoreSafeTSRequest{KeyRange: &kvrpcpb.KeyRange{
StartKey: []byte(""),
EndKey: []byte(""),
}}), ReadTimeoutShort)
storeIDStr := strconv.Itoa(int(storeID))
if err != nil {
metrics.TiKVSafeTSUpdateCounter.WithLabelValues("fail", storeIDStr).Inc()
logutil.BgLogger().Debug("update safeTS failed", zap.Error(err), zap.Uint64("store-id", storeID))
return
}
safeTSResp := resp.Resp.(*kvrpcpb.StoreSafeTSResponse)
s.setSafeTS(storeID, safeTSResp.GetSafeTs())
metrics.TiKVSafeTSUpdateCounter.WithLabelValues("success", storeIDStr).Inc()
metrics.TiKVSafeTSUpdateStats.WithLabelValues(storeIDStr).Set(float64(safeTSResp.GetSafeTs()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont timestamp exceed the float64 limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it won't happen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some loss of precision.

}(ctx, wg, storeID, storeAddr)
}
wg.Wait()
Expand Down
20 changes: 20 additions & 0 deletions store/tikv/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var (
TiKVPanicCounter *prometheus.CounterVec
TiKVForwardRequestCounter *prometheus.CounterVec
TiKVTSFutureWaitDuration prometheus.Histogram
TiKVSafeTSUpdateCounter *prometheus.CounterVec
TiKVSafeTSUpdateStats *prometheus.GaugeVec
)

// Label constants.
Expand Down Expand Up @@ -414,6 +416,22 @@ func initMetrics(namespace, subsystem string) {
Buckets: prometheus.ExponentialBuckets(0.000005, 2, 30), // 5us ~ 2560s
})

TiKVSafeTSUpdateCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "safets_update_counter",
Help: "Counter of tikv safe_ts being updated.",
}, []string{LblResult, LblStore})

TiKVSafeTSUpdateStats = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "safets_update_stats",
Help: "stat of tikv updating safe_ts stats",
}, []string{LblStore})

initShortcuts()
}

Expand Down Expand Up @@ -468,6 +486,8 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVPanicCounter)
prometheus.MustRegister(TiKVForwardRequestCounter)
prometheus.MustRegister(TiKVTSFutureWaitDuration)
prometheus.MustRegister(TiKVSafeTSUpdateCounter)
prometheus.MustRegister(TiKVSafeTSUpdateStats)
}

// readCounter reads the value of a prometheus.Counter.
Expand Down