From fa928af627a473ec67ba1602cb1d8cbfa2153e42 Mon Sep 17 00:00:00 2001 From: jyz0309 <45495947@qq.com> Date: Tue, 30 Nov 2021 09:54:24 +0800 Subject: [PATCH] add observe Signed-off-by: jyz0309 <45495947@qq.com> --- domain/infosync/info.go | 3 ++- metrics/server.go | 4 ++-- store/helper/helper.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/domain/infosync/info.go b/domain/infosync/info.go index b159100f0f92e..721a9452fd7d7 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -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 diff --git a/metrics/server.go b/metrics/server.go index c9d9e86a758ae..68f8e8b3abf86 100644 --- a/metrics/server.go +++ b/metrics/server.go @@ -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. diff --git a/store/helper/helper.go b/store/helper/helper.go index dd14a85b67432..125052d10cd75 100644 --- a/store/helper/helper.go +++ b/store/helper/helper.go @@ -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()