From 8840d640d1c9c22c1387dc26164dc3ddd339c053 Mon Sep 17 00:00:00 2001 From: sev7n <47801637+sev7ndayyoo@users.noreply.github.com> Date: Fri, 15 Jan 2021 14:26:57 +0800 Subject: [PATCH 1/2] cherry pick #22350 to release-4.0 Signed-off-by: ti-srebot --- executor/adapter.go | 22 ++++++++++++++++++++++ metrics/grafana/tidb.json | 12 ++++++------ metrics/server.go | 12 ++++++------ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 4c1c2a2343194..8bd4d351fe48f 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -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) @@ -915,9 +925,21 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) } else { logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems)) +<<<<<<< HEAD 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.TimeDetail.ProcessTime.Seconds()) + totalCopWaitHistogramInternal.Observe(execDetail.TimeDetail.WaitTime.Seconds()) + } else { + totalQueryProcHistogramGeneral.Observe(costTime.Seconds()) + totalCopProcHistogramGeneral.Observe(execDetail.TimeDetail.ProcessTime.Seconds()) + totalCopWaitHistogramGeneral.Observe(execDetail.TimeDetail.WaitTime.Seconds()) + } +>>>>>>> 42edd7a29... executor: metrics slow query is divided into internal and general (#22350) var userString string if sessVars.User != nil { userString = sessVars.User.String() diff --git a/metrics/grafana/tidb.json b/metrics/grafana/tidb.json index 25722461ea235..966246d36a73b 100644 --- a/metrics/grafana/tidb.json +++ b/metrics/grafana/tidb.json @@ -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" } ], diff --git a/metrics/server.go b/metrics/server.go index 17fa1f998788d..0e6c420fd4301 100644 --- a/metrics/server.go +++ b/metrics/server.go @@ -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{ From 4b11c1a6ef544e542799329cba38f2b36eb8a0ff Mon Sep 17 00:00:00 2001 From: sev7ndayyoo <47801637+sev7ndayyoo@users.noreply.github.com> Date: Fri, 15 Jan 2021 17:32:13 +0800 Subject: [PATCH 2/2] Resolve conflicts. --- executor/adapter.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 8bd4d351fe48f..e785799b5ec26 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -925,21 +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)) -<<<<<<< HEAD - 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.TimeDetail.ProcessTime.Seconds()) - totalCopWaitHistogramInternal.Observe(execDetail.TimeDetail.WaitTime.Seconds()) + totalCopProcHistogramInternal.Observe(execDetail.ProcessTime.Seconds()) + totalCopWaitHistogramInternal.Observe(execDetail.WaitTime.Seconds()) } else { totalQueryProcHistogramGeneral.Observe(costTime.Seconds()) - totalCopProcHistogramGeneral.Observe(execDetail.TimeDetail.ProcessTime.Seconds()) - totalCopWaitHistogramGeneral.Observe(execDetail.TimeDetail.WaitTime.Seconds()) + totalCopProcHistogramGeneral.Observe(execDetail.ProcessTime.Seconds()) + totalCopWaitHistogramGeneral.Observe(execDetail.WaitTime.Seconds()) } ->>>>>>> 42edd7a29... executor: metrics slow query is divided into internal and general (#22350) var userString string if sessVars.User != nil { userString = sessVars.User.String()