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

client/tso: add a TSO wait failed duration observer #8763

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 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
7 changes: 4 additions & 3 deletions client/tso_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ func (req *tsoRequest) waitCtx(ctx context.Context) (physical int64, logical int
defer req.pool.Put(req)
defer trace.StartRegion(req.requestCtx, "pdclient.tsoReqDone").End()
err = errors.WithStack(err)
now := time.Now()
if err != nil {
cmdFailDurationTSO.Observe(time.Since(req.start).Seconds())
cmdFailDurationTSOWait.Observe(now.Sub(start).Seconds())
cmdFailDurationTSO.Observe(now.Sub(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