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

metrics: distinguish transactions by mode #17912

Merged
merged 6 commits into from
Jun 15, 2020
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
10 changes: 5 additions & 5 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import (
)

var (
transactionDurationInternalRollback = metrics.TransactionDuration.WithLabelValues(metrics.LblInternal, metrics.LblRollback)
transactionDurationGeneralRollback = metrics.TransactionDuration.WithLabelValues(metrics.LblGeneral, metrics.LblRollback)
transactionDurationPessimisticRollback = metrics.TransactionDuration.WithLabelValues(metrics.LblPessimistic, metrics.LblRollback)
transactionDurationOptimisticRollback = metrics.TransactionDuration.WithLabelValues(metrics.LblOptimistic, metrics.LblRollback)
)

// SimpleExec represents simple statement executor.
Expand Down Expand Up @@ -649,10 +649,10 @@ func (e *SimpleExec) executeRollback(s *ast.RollbackStmt) error {
}
if txn.Valid() {
duration := time.Since(sessVars.TxnCtx.CreateTime).Seconds()
if sessVars.InRestrictedSQL {
transactionDurationInternalRollback.Observe(duration)
if sessVars.TxnCtx.IsPessimistic {
transactionDurationPessimisticRollback.Observe(duration)
} else {
transactionDurationGeneralRollback.Observe(duration)
transactionDurationOptimisticRollback.Observe(duration)
}
sessVars.TxnCtx.ClearDelta()
return txn.Rollback()
Expand Down
28 changes: 14 additions & 14 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3375,7 +3375,7 @@
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "TiDB transaction processing counts by type and source. Internal means TiDB inner transcation calls",
"description": "TiDB transaction processing counts by type and source.",
"editable": true,
"error": false,
"fill": 1,
Expand Down Expand Up @@ -3416,10 +3416,10 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tidb_session_transaction_duration_seconds_count[1m])) by (type, sql_type)",
"expr": "sum(rate(tidb_session_transaction_duration_seconds_count[1m])) by (type, txn_mode)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{type}}-{{sql_type}}",
"legendFormat": "{{type}}-{{txn_mode}}",
"refId": "A",
"step": 10
}
Expand Down Expand Up @@ -3510,24 +3510,24 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, sql_type))",
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "99-{{sql_type}}",
"legendFormat": "99-{{txn_mode}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, sql_type))",
"expr": "histogram_quantile(0.95, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "95-{{sql_type}}",
"legendFormat": "95-{{txn_mode}}",
"refId": "B"
},
{
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, sql_type))",
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_duration_seconds_bucket[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "80-{{sql_type}}",
"legendFormat": "80-{{txn_mode}}",
"refId": "C"
}
],
Expand Down Expand Up @@ -3578,7 +3578,7 @@
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "TiDB statements numbers within one transaction. Internal means TiDB inner transaction",
"description": "TiDB statements numbers within one transaction.",
"fill": 1,
"fillGradient": 0,
"gridPos": {
Expand Down Expand Up @@ -3616,17 +3616,17 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_statement_num_bucket[30s])) by (le, sql_type))",
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_statement_num_bucket[30s])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "99-{{sql_type}}",
"legendFormat": "99-{{txn_mode}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_statement_num_bucket[30s])) by (le, sql_type))",
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_statement_num_bucket[30s])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "80-{{sql_type}}",
"legendFormat": "80-{{txn_mode}}",
"refId": "B"
}
],
Expand Down
20 changes: 10 additions & 10 deletions metrics/grafana/tidb_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -1632,10 +1632,10 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tidb_session_transaction_duration_seconds_count{sql_type=\"general\"}[1m])) by (type)",
"expr": "sum(rate(tidb_session_transaction_duration_seconds_count[1m])) by (type, txn_mode)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{type}}",
"legendFormat": "{{type}}-{{txn_mode}}",
"refId": "A",
"step": 10
}
Expand Down Expand Up @@ -1723,24 +1723,24 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le))",
"expr": "histogram_quantile(0.99, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "99",
"legendFormat": "99-{{txn_mode}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.95, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le))",
"expr": "histogram_quantile(0.95, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "95",
"legendFormat": "95-{{txn_mode}}",
"refId": "B"
},
{
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le))",
"expr": "histogram_quantile(0.80, sum(rate(tidb_session_transaction_duration_seconds_bucket{sql_type=\"general\"}[1m])) by (le, txn_mode))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "80",
"legendFormat": "80-{{txn_mode}}",
"refId": "C"
}
],
Expand Down Expand Up @@ -1825,10 +1825,10 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(1, sum(rate(tidb_session_transaction_statement_num_bucket{sql_type=\"general\"}[30s])) by (le))",
"expr": "histogram_quantile(1, sum(rate(tidb_session_transaction_statement_num_bucket[30s])) by (le))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "99",
"legendFormat": "max",
"refId": "A"
}
],
Expand Down
7 changes: 5 additions & 2 deletions metrics/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var (
Name: "transaction_statement_num",
Help: "Bucketed histogram of statements count in each transaction.",
Buckets: prometheus.ExponentialBuckets(1, 2, 16), // 1 ~ 32768
}, []string{LblSQLType, LblType})
}, []string{LbTxnMode, LblType})

TransactionDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Expand All @@ -89,7 +89,7 @@ var (
Name: "transaction_duration_seconds",
Help: "Bucketed histogram of a transaction execution duration, including retry.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
}, []string{LblSQLType, LblType})
}, []string{LbTxnMode, LblType})

StatementDeadlockDetectDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Expand Down Expand Up @@ -135,6 +135,9 @@ const (
LblSQLType = "sql_type"
LblGeneral = "general"
LblInternal = "internal"
LbTxnMode = "txn_mode"
LblPessimistic = "pessimistic"
LblOptimistic = "optimistic"
LblStore = "store"
LblAddress = "address"
)
34 changes: 17 additions & 17 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ import (
)

var (
statementPerTransactionInternalOK = metrics.StatementPerTransaction.WithLabelValues(metrics.LblInternal, "ok")
statementPerTransactionInternalError = metrics.StatementPerTransaction.WithLabelValues(metrics.LblInternal, "error")
statementPerTransactionGeneralOK = metrics.StatementPerTransaction.WithLabelValues(metrics.LblGeneral, "ok")
statementPerTransactionGeneralError = metrics.StatementPerTransaction.WithLabelValues(metrics.LblGeneral, "error")
transactionDurationInternalCommit = metrics.TransactionDuration.WithLabelValues(metrics.LblInternal, metrics.LblCommit)
transactionDurationInternalAbort = metrics.TransactionDuration.WithLabelValues(metrics.LblInternal, metrics.LblAbort)
transactionDurationGeneralCommit = metrics.TransactionDuration.WithLabelValues(metrics.LblGeneral, metrics.LblCommit)
transactionDurationGeneralAbort = metrics.TransactionDuration.WithLabelValues(metrics.LblGeneral, metrics.LblAbort)
statementPerTransactionPessimisticOK = metrics.StatementPerTransaction.WithLabelValues(metrics.LblPessimistic, metrics.LblOK)
statementPerTransactionPessimisticError = metrics.StatementPerTransaction.WithLabelValues(metrics.LblPessimistic, metrics.LblError)
statementPerTransactionOptimisticOK = metrics.StatementPerTransaction.WithLabelValues(metrics.LblOptimistic, metrics.LblOK)
statementPerTransactionOptimisticError = metrics.StatementPerTransaction.WithLabelValues(metrics.LblOptimistic, metrics.LblError)
transactionDurationPessimisticCommit = metrics.TransactionDuration.WithLabelValues(metrics.LblPessimistic, metrics.LblCommit)
transactionDurationPessimisticAbort = metrics.TransactionDuration.WithLabelValues(metrics.LblPessimistic, metrics.LblAbort)
transactionDurationOptimisticCommit = metrics.TransactionDuration.WithLabelValues(metrics.LblOptimistic, metrics.LblCommit)
transactionDurationOptimisticAbort = metrics.TransactionDuration.WithLabelValues(metrics.LblOptimistic, metrics.LblAbort)

sessionExecuteCompileDurationInternal = metrics.SessionExecuteCompileDuration.WithLabelValues(metrics.LblInternal)
sessionExecuteCompileDurationGeneral = metrics.SessionExecuteCompileDuration.WithLabelValues(metrics.LblGeneral)
Expand Down Expand Up @@ -2240,21 +2240,21 @@ func logQuery(query string, vars *variable.SessionVars) {
}

func (s *session) recordOnTransactionExecution(err error, counter int, duration float64) {
if s.isInternal() {
if s.sessionVars.TxnCtx.IsPessimistic {
if err != nil {
statementPerTransactionInternalError.Observe(float64(counter))
transactionDurationInternalAbort.Observe(duration)
statementPerTransactionPessimisticError.Observe(float64(counter))
transactionDurationPessimisticAbort.Observe(duration)
} else {
statementPerTransactionInternalOK.Observe(float64(counter))
transactionDurationInternalCommit.Observe(duration)
statementPerTransactionPessimisticOK.Observe(float64(counter))
transactionDurationPessimisticCommit.Observe(duration)
}
} else {
if err != nil {
statementPerTransactionGeneralError.Observe(float64(counter))
transactionDurationGeneralAbort.Observe(duration)
statementPerTransactionOptimisticError.Observe(float64(counter))
transactionDurationOptimisticAbort.Observe(duration)
} else {
statementPerTransactionGeneralOK.Observe(float64(counter))
transactionDurationGeneralCommit.Observe(duration)
statementPerTransactionOptimisticOK.Observe(float64(counter))
transactionDurationOptimisticCommit.Observe(duration)
}
}
}
6 changes: 3 additions & 3 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func Compile(ctx context.Context, sctx sessionctx.Context, stmtNode ast.StmtNode

func recordAbortTxnDuration(sessVars *variable.SessionVars) {
duration := time.Since(sessVars.TxnCtx.CreateTime).Seconds()
if sessVars.InRestrictedSQL {
transactionDurationInternalAbort.Observe(duration)
if sessVars.TxnCtx.IsPessimistic {
transactionDurationPessimisticAbort.Observe(duration)
} else {
transactionDurationGeneralAbort.Observe(duration)
transactionDurationOptimisticAbort.Observe(duration)
}
}

Expand Down