Skip to content

Commit 7256212

Browse files
authored
*: add MVCC version ratio to slow log metrics (#44897) (#47645)
close #44896
1 parent f42521f commit 7256212

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

executor/adapter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,9 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
16061606
executor_metrics.TotalQueryProcHistogramGeneral.Observe(costTime.Seconds())
16071607
executor_metrics.TotalCopProcHistogramGeneral.Observe(execDetail.TimeDetail.ProcessTime.Seconds())
16081608
executor_metrics.TotalCopWaitHistogramGeneral.Observe(execDetail.TimeDetail.WaitTime.Seconds())
1609+
if execDetail.ScanDetail != nil && execDetail.ScanDetail.ProcessedKeys != 0 {
1610+
executor_metrics.CopMVCCRatioHistogramGeneral.Observe(float64(execDetail.ScanDetail.TotalKeys) / float64(execDetail.ScanDetail.ProcessedKeys))
1611+
}
16091612
}
16101613
var userString string
16111614
if sessVars.User != nil {

executor/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
TotalQueryProcHistogramGeneral prometheus.Observer
4444
TotalCopProcHistogramGeneral prometheus.Observer
4545
TotalCopWaitHistogramGeneral prometheus.Observer
46+
CopMVCCRatioHistogramGeneral prometheus.Observer
4647
TotalQueryProcHistogramInternal prometheus.Observer
4748
TotalCopProcHistogramInternal prometheus.Observer
4849
TotalCopWaitHistogramInternal prometheus.Observer
@@ -137,6 +138,7 @@ func InitMetricsVars() {
137138
TotalQueryProcHistogramGeneral = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblGeneral)
138139
TotalCopProcHistogramGeneral = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblGeneral)
139140
TotalCopWaitHistogramGeneral = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblGeneral)
141+
CopMVCCRatioHistogramGeneral = metrics.CopMVCCRatioHistogram.WithLabelValues(metrics.LblGeneral)
140142
TotalQueryProcHistogramInternal = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblInternal)
141143
TotalCopProcHistogramInternal = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblInternal)
142144
TotalCopWaitHistogramInternal = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblInternal)

metrics/grafana/tidb.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -814,31 +814,44 @@
814814
"pointradius": 5,
815815
"points": false,
816816
"renderer": "flot",
817-
"seriesOverrides": [],
817+
"seriesOverrides": [
818+
{
819+
"$$hashKey": "object:211",
820+
"alias": "/mvcc_ratio/",
821+
"yaxis": 2
822+
}
823+
],
818824
"spaceLength": 10,
819825
"stack": false,
820826
"steppedLine": false,
821827
"targets": [
822828
{
823-
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le,sql_type))",
829+
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", sql_type=\"general\"}[1m])) by (le,sql_type))",
824830
"format": "time_series",
825831
"intervalFactor": 2,
826-
"legendFormat": "all_proc_{{sql_type}}",
832+
"legendFormat": "all_proc",
827833
"refId": "A"
828834
},
829835
{
830-
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le,sql_type))",
836+
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", sql_type=\"general\"}[1m])) by (le,sql_type))",
831837
"format": "time_series",
832838
"intervalFactor": 2,
833-
"legendFormat": "all_cop_proc_{{sql_type}}",
839+
"legendFormat": "all_cop_proc",
834840
"refId": "B"
835841
},
836842
{
837-
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le,sql_type))",
843+
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", sql_type=\"general\"}[1m])) by (le,sql_type))",
838844
"format": "time_series",
839845
"intervalFactor": 2,
840-
"legendFormat": "all_cop_wait_{{sql_type}}",
846+
"legendFormat": "all_cop_wait",
841847
"refId": "C"
848+
},
849+
{
850+
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_mvcc_ratio_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", sql_type=\"general\"}[1m])) by (le,sql_type))",
851+
"format": "time_series",
852+
"intervalFactor": 2,
853+
"legendFormat": "mvcc_ratio",
854+
"refId": "D"
842855
}
843856
],
844857
"thresholds": [],
@@ -861,6 +874,7 @@
861874
},
862875
"yaxes": [
863876
{
877+
"$$hashKey": "object:119",
864878
"format": "s",
865879
"label": null,
866880
"logBase": 2,
@@ -869,6 +883,7 @@
869883
"show": true
870884
},
871885
{
886+
"$$hashKey": "object:120",
872887
"format": "short",
873888
"label": null,
874889
"logBase": 1,

metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func RegisterMetrics() {
204204
prometheus.MustRegister(TotalQueryProcHistogram)
205205
prometheus.MustRegister(TotalCopProcHistogram)
206206
prometheus.MustRegister(TotalCopWaitHistogram)
207+
prometheus.MustRegister(CopMVCCRatioHistogram)
207208
prometheus.MustRegister(HandleSchemaValidate)
208209
prometheus.MustRegister(MaxProcs)
209210
prometheus.MustRegister(GOGC)

metrics/server.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
TotalQueryProcHistogram *prometheus.HistogramVec
5757
TotalCopProcHistogram *prometheus.HistogramVec
5858
TotalCopWaitHistogram *prometheus.HistogramVec
59+
CopMVCCRatioHistogram *prometheus.HistogramVec
5960
MaxProcs prometheus.Gauge
6061
GOGC prometheus.Gauge
6162
ConnIdleDurationHistogram *prometheus.HistogramVec
@@ -256,6 +257,15 @@ func InitServerMetrics() {
256257
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
257258
}, []string{LblSQLType})
258259

260+
CopMVCCRatioHistogram = NewHistogramVec(
261+
prometheus.HistogramOpts{
262+
Namespace: "tidb",
263+
Subsystem: "server",
264+
Name: "slow_query_cop_mvcc_ratio",
265+
Help: "Bucketed histogram of all cop total keys / processed keys in slow queries.",
266+
Buckets: prometheus.ExponentialBuckets(0.5, 2, 21), // 0.5 ~ 262144
267+
}, []string{LblSQLType})
268+
259269
MaxProcs = NewGauge(
260270
prometheus.GaugeOpts{
261271
Namespace: "tidb",

0 commit comments

Comments
 (0)