From dc994c7f0b0cb2cddff6b1c3b91b53673539c8b8 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Mon, 4 Nov 2024 11:38:57 +0800 Subject: [PATCH] Add a TSO wait failed duration observer Signed-off-by: JmPotato --- client/metrics.go | 6 ++++-- client/tso_request.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/metrics.go b/client/metrics.go index d1b375aea8ac..fdcdd88f0168 100644 --- a/client/metrics.go +++ b/client/metrics.go @@ -139,7 +139,7 @@ func initMetrics(constLabels prometheus.Labels) { } var ( - cmdDurationWait prometheus.Observer + cmdDurationTSOWait prometheus.Observer cmdDurationTSO prometheus.Observer cmdDurationTSOAsyncWait prometheus.Observer cmdDurationGetRegion prometheus.Observer @@ -166,6 +166,7 @@ var ( cmdDurationUpdateServiceSafePointV2 prometheus.Observer cmdFailDurationGetRegion prometheus.Observer + cmdFailDurationTSOWait prometheus.Observer cmdFailDurationTSO prometheus.Observer cmdFailDurationGetAllMembers prometheus.Observer cmdFailDurationGetPrevRegion prometheus.Observer @@ -189,7 +190,7 @@ var ( func initCmdDurations() { // WithLabelValues is a heavy operation, define variable to avoid call it every time. - cmdDurationWait = cmdDuration.WithLabelValues("wait") + cmdDurationTSOWait = cmdDuration.WithLabelValues("wait") cmdDurationTSO = cmdDuration.WithLabelValues("tso") cmdDurationTSOAsyncWait = cmdDuration.WithLabelValues("tso_async_wait") cmdDurationGetRegion = cmdDuration.WithLabelValues("get_region") @@ -216,6 +217,7 @@ func initCmdDurations() { cmdDurationUpdateServiceSafePointV2 = cmdDuration.WithLabelValues("update_service_safe_point_v2") cmdFailDurationGetRegion = cmdFailedDuration.WithLabelValues("get_region") + cmdFailDurationTSOWait = cmdFailedDuration.WithLabelValues("wait") cmdFailDurationTSO = cmdFailedDuration.WithLabelValues("tso") cmdFailDurationGetAllMembers = cmdFailedDuration.WithLabelValues("get_member_info") cmdFailDurationGetPrevRegion = cmdFailedDuration.WithLabelValues("get_prev_region") diff --git a/client/tso_request.go b/client/tso_request.go index 5c959673a8b5..4872d4ac9858 100644 --- a/client/tso_request.go +++ b/client/tso_request.go @@ -75,12 +75,13 @@ func (req *tsoRequest) waitCtx(ctx context.Context) (physical int64, logical int defer trace.StartRegion(req.requestCtx, "pdclient.tsoReqDone").End() err = errors.WithStack(err) if err != nil { + cmdFailDurationTSOWait.Observe(time.Since(start).Seconds()) cmdFailDurationTSO.Observe(time.Since(req.start).Seconds()) return 0, 0, err } physical, logical = req.physical, req.logical now := time.Now() - cmdDurationWait.Observe(now.Sub(start).Seconds()) + cmdDurationTSOWait.Observe(now.Sub(start).Seconds()) cmdDurationTSO.Observe(now.Sub(req.start).Seconds()) return case <-ctx.Done():