diff --git a/domain/infosync/info.go b/domain/infosync/info.go index b159100f0f92e..29b71e8b9f276 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -343,8 +343,9 @@ 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) + metrics.PDApiExecutionHistogram.WithLabelValues("placement").Observe(time.Since(start).Seconds()) if err == nil { bodyBytes, err := io.ReadAll(res.Body) if err != nil { diff --git a/metrics/metrics.go b/metrics/metrics.go index 772663f530575..f5c1faf5bb3aa 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -157,6 +157,7 @@ func RegisterMetrics() { prometheus.MustRegister(TopSQLIgnoredCounter) prometheus.MustRegister(TopSQLReportDurationHistogram) prometheus.MustRegister(TopSQLReportDataHistogram) + prometheus.MustRegister(PDApiExecutionHistogram) tikvmetrics.InitMetrics(TiDB, TiKVClient) tikvmetrics.RegisterMetrics() diff --git a/metrics/server.go b/metrics/server.go index 3bc764f6f9afa..68f8e8b3abf86 100644 --- a/metrics/server.go +++ b/metrics/server.go @@ -229,6 +229,15 @@ var ( Name: "tiflash_query_total", Help: "Counter of TiFlash queries.", }, []string{LblType, LblResult}) + + 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 3b8e122071959..125052d10cd75 100644 --- a/store/helper/helper.go +++ b/store/helper/helper.go @@ -34,6 +34,7 @@ import ( "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/log" "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/parser/model" derr "github.com/pingcap/tidb/store/driver/error" "github.com/pingcap/tidb/tablecodec" @@ -767,10 +768,12 @@ func (h *Helper) requestPD(method, uri string, body io.Reader, res interface{}) if err != nil { return err } + start := time.Now() resp, err := util.InternalHTTPClient().Do(req) if err != nil { return errors.Trace(err) } + metrics.PDApiExecutionHistogram.WithLabelValues("common").Observe(time.Since(start).Seconds()) defer func() { err = resp.Body.Close()