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

executor: metrics slow query is divided into internal and general (#22350) #22405

Merged
merged 3 commits into from
Jan 20, 2021
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
22 changes: 19 additions & 3 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ import (
"go.uber.org/zap/zapcore"
)

// metrics option
var (
totalQueryProcHistogramGeneral = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopProcHistogramGeneral = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopWaitHistogramGeneral = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblGeneral)
totalQueryProcHistogramInternal = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopProcHistogramInternal = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopWaitHistogramInternal = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblInternal)
)

// processinfoSetter is the interface use to set current running process info.
type processinfoSetter interface {
SetProcessInfo(string, time.Time, byte, uint64)
Expand Down Expand Up @@ -915,9 +925,15 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems))
} else {
logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems))
metrics.TotalQueryProcHistogram.Observe(costTime.Seconds())
metrics.TotalCopProcHistogram.Observe(execDetail.ProcessTime.Seconds())
metrics.TotalCopWaitHistogram.Observe(execDetail.WaitTime.Seconds())
if sessVars.InRestrictedSQL {
totalQueryProcHistogramInternal.Observe(costTime.Seconds())
totalCopProcHistogramInternal.Observe(execDetail.ProcessTime.Seconds())
totalCopWaitHistogramInternal.Observe(execDetail.WaitTime.Seconds())
} else {
totalQueryProcHistogramGeneral.Observe(costTime.Seconds())
totalCopProcHistogramGeneral.Observe(execDetail.ProcessTime.Seconds())
totalCopWaitHistogramGeneral.Observe(execDetail.WaitTime.Seconds())
}
var userString string
if sessVars.User != nil {
userString = sessVars.User.String()
Expand Down
12 changes: 6 additions & 6 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,24 +629,24 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_proc",
"legendFormat": "all_proc_{{sql_type}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_proc",
"legendFormat": "all_cop_proc_{{sql_type}}",
"refId": "B"
},
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_wait",
"legendFormat": "all_cop_wait_{{sql_type}}",
"refId": "C"
}
],
Expand Down
12 changes: 6 additions & 6 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,30 @@ var (
Buckets: prometheus.ExponentialBuckets(1, 2, 30), // 1us ~ 528s
})

TotalQueryProcHistogram = prometheus.NewHistogram(
TotalQueryProcHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_process_duration_seconds",
Help: "Bucketed histogram of processing time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
TotalCopProcHistogram = prometheus.NewHistogram(
}, []string{LblSQLType})
TotalCopProcHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_cop_duration_seconds",
Help: "Bucketed histogram of all cop processing time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
TotalCopWaitHistogram = prometheus.NewHistogram(
}, []string{LblSQLType})
TotalCopWaitHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_wait_duration_seconds",
Help: "Bucketed histogram of all cop waiting time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
}, []string{LblSQLType})

MaxProcs = prometheus.NewGauge(
prometheus.GaugeOpts{
Expand Down