Skip to content

Commit

Permalink
add observe
Browse files Browse the repository at this point in the history
Signed-off-by: jyz0309 <45495947@qq.com>
  • Loading branch information
jyz0309 committed Nov 30, 2021
1 parent e426c20 commit fa928af
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i
if body != nil {
req.Header.Set("Content-Type", "application/json")
}

start := time.Now()
res, err = doRequestWithFailpoint(req)
if err == nil {
metrics.PDApiExecutionHistogram.WithLabelValues("placement").Observe(time.Since(start).Seconds())
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ var (
Help: "Counter of TiFlash queries.",
}, []string{LblType, LblResult})

PDApiExecutionHistogram = prometheus.NewHistogram(
PDApiExecutionHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "pd_api_execution_duration_seconds",
Help: "Bucketed histogram of all pd api execution time (s)",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), // 1ms ~ 524s
})
}, []string{LblType})
)

// ExecuteErrorToLabel converts an execute error to label.
Expand Down
2 changes: 1 addition & 1 deletion store/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ func (h *Helper) requestPD(method, uri string, body io.Reader, res interface{})
if err != nil {
return errors.Trace(err)
}
metrics.PDApiExecutionHistogram.Observe(time.Since(start).Seconds())
metrics.PDApiExecutionHistogram.WithLabelValues("common").Observe(time.Since(start).Seconds())

defer func() {
err = resp.Body.Close()
Expand Down

0 comments on commit fa928af

Please sign in to comment.