Refine the SafeTS gap metric (#90)

Signed-off-by: JmPotato <ghzpotato@gmail.com>
This commit is contained in:
JmPotato 2021-06-17 19:58:13 +08:00 committed by GitHub
parent bc884ee6ac
commit 8d4847a868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -60,7 +60,7 @@ var (
TiKVForwardRequestCounter *prometheus.CounterVec TiKVForwardRequestCounter *prometheus.CounterVec
TiKVTSFutureWaitDuration prometheus.Histogram TiKVTSFutureWaitDuration prometheus.Histogram
TiKVSafeTSUpdateCounter *prometheus.CounterVec TiKVSafeTSUpdateCounter *prometheus.CounterVec
TiKVSafeTSGapHistogram *prometheus.HistogramVec TiKVMinSafeTSGapSeconds *prometheus.GaugeVec
TiKVReplicaSelectorFailureCounter *prometheus.CounterVec TiKVReplicaSelectorFailureCounter *prometheus.CounterVec
TiKVRequestRetryTimesHistogram prometheus.Histogram TiKVRequestRetryTimesHistogram prometheus.Histogram
TiKVTxnCommitBackoffSeconds prometheus.Histogram TiKVTxnCommitBackoffSeconds prometheus.Histogram
@ -429,13 +429,12 @@ func initMetrics(namespace, subsystem string) {
Help: "Counter of tikv safe_ts being updated.", Help: "Counter of tikv safe_ts being updated.",
}, []string{LblResult, LblStore}) }, []string{LblResult, LblStore})
TiKVSafeTSGapHistogram = prometheus.NewHistogramVec( TiKVMinSafeTSGapSeconds = prometheus.NewGaugeVec(
prometheus.HistogramOpts{ prometheus.GaugeOpts{
Namespace: namespace, Namespace: namespace,
Subsystem: subsystem, Subsystem: subsystem,
Name: "safets_gap_seconds", Name: "min_safets_gap_seconds",
Help: "Histogram of the gap between SafeTS and current time.", Help: "The minimal (non-zero) SafeTS gap for each store.",
Buckets: prometheus.ExponentialBuckets(0.001, 2.0, 24),
}, []string{LblStore}) }, []string{LblStore})
TiKVReplicaSelectorFailureCounter = prometheus.NewCounterVec( TiKVReplicaSelectorFailureCounter = prometheus.NewCounterVec(
@ -536,7 +535,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVForwardRequestCounter) prometheus.MustRegister(TiKVForwardRequestCounter)
prometheus.MustRegister(TiKVTSFutureWaitDuration) prometheus.MustRegister(TiKVTSFutureWaitDuration)
prometheus.MustRegister(TiKVSafeTSUpdateCounter) prometheus.MustRegister(TiKVSafeTSUpdateCounter)
prometheus.MustRegister(TiKVSafeTSGapHistogram) prometheus.MustRegister(TiKVMinSafeTSGapSeconds)
prometheus.MustRegister(TiKVReplicaSelectorFailureCounter) prometheus.MustRegister(TiKVReplicaSelectorFailureCounter)
prometheus.MustRegister(TiKVRequestRetryTimesHistogram) prometheus.MustRegister(TiKVRequestRetryTimesHistogram)
prometheus.MustRegister(TiKVTxnCommitBackoffSeconds) prometheus.MustRegister(TiKVTxnCommitBackoffSeconds)

View File

@ -485,7 +485,7 @@ func (s *KVStore) updateSafeTS(ctx context.Context) {
s.setSafeTS(storeID, safeTS) s.setSafeTS(storeID, safeTS)
metrics.TiKVSafeTSUpdateCounter.WithLabelValues("success", storeIDStr).Inc() metrics.TiKVSafeTSUpdateCounter.WithLabelValues("success", storeIDStr).Inc()
safeTSTime := oracle.GetTimeFromTS(safeTS) safeTSTime := oracle.GetTimeFromTS(safeTS)
metrics.TiKVSafeTSGapHistogram.WithLabelValues(storeIDStr).Observe(time.Since(safeTSTime).Seconds()) metrics.TiKVMinSafeTSGapSeconds.WithLabelValues(storeIDStr).Set(time.Since(safeTSTime).Seconds())
}(ctx, wg, storeID, storeAddr) }(ctx, wg, storeID, storeAddr)
} }
wg.Wait() wg.Wait()