Skip to content

Commit

Permalink
Add a TSO wait failed duration observer
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Nov 4, 2024
1 parent 60b960a commit dc994c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions client/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -166,6 +166,7 @@ var (
cmdDurationUpdateServiceSafePointV2 prometheus.Observer

cmdFailDurationGetRegion prometheus.Observer
cmdFailDurationTSOWait prometheus.Observer
cmdFailDurationTSO prometheus.Observer
cmdFailDurationGetAllMembers prometheus.Observer
cmdFailDurationGetPrevRegion prometheus.Observer
Expand All @@ -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")
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion client/tso_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit dc994c7

Please sign in to comment.