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

store: Add metrics for pd api call time #30062

Merged
merged 13 commits into from
Dec 1, 2021
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
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TopSQLIgnoredCounter)
prometheus.MustRegister(TopSQLReportDurationHistogram)
prometheus.MustRegister(TopSQLReportDataHistogram)
prometheus.MustRegister(PDApiExecutionHistogram)

tikvmetrics.InitMetrics(TiDB, TiKVClient)
tikvmetrics.RegisterMetrics()
Expand Down
9 changes: 9 additions & 0 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved
)

// ExecuteErrorToLabel converts an execute error to label.
Expand Down
3 changes: 3 additions & 0 deletions store/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
jyz0309 marked this conversation as resolved.
Show resolved Hide resolved

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