Skip to content

Commit

Permalink
*: add MVCC version ratio to slow log metrics (#44897)
Browse files Browse the repository at this point in the history
close #44896
  • Loading branch information
jackysp authored Jun 23, 2023
1 parent cc8d299 commit d6143a2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,9 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
executor_metrics.TotalQueryProcHistogramGeneral.Observe(costTime.Seconds())
executor_metrics.TotalCopProcHistogramGeneral.Observe(execDetail.TimeDetail.ProcessTime.Seconds())
executor_metrics.TotalCopWaitHistogramGeneral.Observe(execDetail.TimeDetail.WaitTime.Seconds())
if execDetail.ScanDetail != nil && execDetail.ScanDetail.ProcessedKeys != 0 {
executor_metrics.CopMVCCRatioHistogramGeneral.Observe(float64(execDetail.ScanDetail.TotalKeys) / float64(execDetail.ScanDetail.ProcessedKeys))
}
}
var userString string
if sessVars.User != nil {
Expand Down
2 changes: 2 additions & 0 deletions executor/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
TotalQueryProcHistogramGeneral prometheus.Observer
TotalCopProcHistogramGeneral prometheus.Observer
TotalCopWaitHistogramGeneral prometheus.Observer
CopMVCCRatioHistogramGeneral prometheus.Observer
TotalQueryProcHistogramInternal prometheus.Observer
TotalCopProcHistogramInternal prometheus.Observer
TotalCopWaitHistogramInternal prometheus.Observer
Expand Down Expand Up @@ -137,6 +138,7 @@ func InitMetricsVars() {
TotalQueryProcHistogramGeneral = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblGeneral)
TotalCopProcHistogramGeneral = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblGeneral)
TotalCopWaitHistogramGeneral = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblGeneral)
CopMVCCRatioHistogramGeneral = metrics.CopMVCCRatioHistogram.WithLabelValues(metrics.LblGeneral)
TotalQueryProcHistogramInternal = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblInternal)
TotalCopProcHistogramInternal = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblInternal)
TotalCopWaitHistogramInternal = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblInternal)
Expand Down
29 changes: 22 additions & 7 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -814,31 +814,44 @@
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"seriesOverrides": [
{
"$$hashKey": "object:211",
"alias": "/mvcc_ratio/",
"yaxis": 2
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"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))",
"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))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_proc_{{sql_type}}",
"legendFormat": "all_proc",
"refId": "A"
},
{
"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))",
"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))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_proc_{{sql_type}}",
"legendFormat": "all_cop_proc",
"refId": "B"
},
{
"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))",
"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))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_wait_{{sql_type}}",
"legendFormat": "all_cop_wait",
"refId": "C"
},
{
"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))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "mvcc_ratio",
"refId": "D"
}
],
"thresholds": [],
Expand All @@ -861,6 +874,7 @@
},
"yaxes": [
{
"$$hashKey": "object:119",
"format": "s",
"label": null,
"logBase": 2,
Expand All @@ -869,6 +883,7 @@
"show": true
},
{
"$$hashKey": "object:120",
"format": "short",
"label": null,
"logBase": 1,
Expand Down
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TotalQueryProcHistogram)
prometheus.MustRegister(TotalCopProcHistogram)
prometheus.MustRegister(TotalCopWaitHistogram)
prometheus.MustRegister(CopMVCCRatioHistogram)
prometheus.MustRegister(HandleSchemaValidate)
prometheus.MustRegister(MaxProcs)
prometheus.MustRegister(GOGC)
Expand Down
10 changes: 10 additions & 0 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
TotalQueryProcHistogram *prometheus.HistogramVec
TotalCopProcHistogram *prometheus.HistogramVec
TotalCopWaitHistogram *prometheus.HistogramVec
CopMVCCRatioHistogram *prometheus.HistogramVec
MaxProcs prometheus.Gauge
GOGC prometheus.Gauge
ConnIdleDurationHistogram *prometheus.HistogramVec
Expand Down Expand Up @@ -256,6 +257,15 @@ func InitServerMetrics() {
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
}, []string{LblSQLType})

CopMVCCRatioHistogram = NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_cop_mvcc_ratio",
Help: "Bucketed histogram of all cop total keys / processed keys in slow queries.",
Buckets: prometheus.ExponentialBuckets(0.5, 2, 21), // 0.5 ~ 262144
}, []string{LblSQLType})

MaxProcs = NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Expand Down

0 comments on commit d6143a2

Please sign in to comment.