Skip to content

Commit

Permalink
sql: separate metrics for restart and non-restart savepoints
Browse files Browse the repository at this point in the history
Release note (sql change): CockroachDB now collects separate sets of
metrics for usage of SAVEPOINT: one set for regular SQL savepoints and
one set for uses dedicated to CockroachDB's client-side transaction
retry protocol.
  • Loading branch information
knz authored and andreimatei committed Mar 5, 2020
1 parent c13702d commit 19b91d7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
38 changes: 29 additions & 9 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2364,11 +2364,12 @@ type StatementCounters struct {
TxnCommitCount telemetry.CounterWithMetric
TxnRollbackCount telemetry.CounterWithMetric

// Savepoint operations. SavepointCount is for real SQL savepoints
// (which we don't yet support; this is just a placeholder for
// telemetry); the RestartSavepoint variants are for the
// Savepoint operations. SavepointCount is for real SQL savepoints;
// the RestartSavepoint variants are for the
// cockroach-specific client-side retry protocol.
SavepointCount telemetry.CounterWithMetric
ReleaseSavepointCount telemetry.CounterWithMetric
RollbackToSavepointCount telemetry.CounterWithMetric
RestartSavepointCount telemetry.CounterWithMetric
ReleaseRestartSavepointCount telemetry.CounterWithMetric
RollbackToRestartSavepointCount telemetry.CounterWithMetric
Expand All @@ -2388,14 +2389,18 @@ func makeStartedStatementCounters(internal bool) StatementCounters {
getMetricMeta(MetaTxnCommitStarted, internal)),
TxnRollbackCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaTxnRollbackStarted, internal)),
SavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSavepointStarted, internal)),
RestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRestartSavepointStarted, internal)),
ReleaseRestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaReleaseRestartSavepointStarted, internal)),
RollbackToRestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRollbackToRestartSavepointStarted, internal)),
SavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSavepointStarted, internal)),
ReleaseSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaReleaseSavepointStarted, internal)),
RollbackToSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRollbackToSavepointStarted, internal)),
SelectCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSelectStarted, internal)),
UpdateCount: telemetry.NewCounterWithMetric(
Expand All @@ -2421,14 +2426,18 @@ func makeExecutedStatementCounters(internal bool) StatementCounters {
getMetricMeta(MetaTxnCommitExecuted, internal)),
TxnRollbackCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaTxnRollbackExecuted, internal)),
SavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSavepointExecuted, internal)),
RestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRestartSavepointExecuted, internal)),
ReleaseRestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaReleaseRestartSavepointExecuted, internal)),
RollbackToRestartSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRollbackToRestartSavepointExecuted, internal)),
SavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSavepointExecuted, internal)),
ReleaseSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaReleaseSavepointExecuted, internal)),
RollbackToSavepointCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaRollbackToSavepointExecuted, internal)),
SelectCount: telemetry.NewCounterWithMetric(
getMetricMeta(MetaSelectExecuted, internal)),
UpdateCount: telemetry.NewCounterWithMetric(
Expand Down Expand Up @@ -2464,15 +2473,26 @@ func (sc *StatementCounters) incrementCount(ex *connExecutor, stmt tree.Statemen
case *tree.RollbackTransaction:
sc.TxnRollbackCount.Inc()
case *tree.Savepoint:
// TODO(knz): Sanitize this.
if err := ex.validateSavepointName(t.Name); err == nil {
sc.RestartSavepointCount.Inc()
} else {
sc.SavepointCount.Inc()
}
case *tree.ReleaseSavepoint:
sc.ReleaseRestartSavepointCount.Inc()
// TODO(knz): Sanitize this.
if err := ex.validateSavepointName(t.Savepoint); err == nil {
sc.ReleaseRestartSavepointCount.Inc()
} else {
sc.ReleaseSavepointCount.Inc()
}
case *tree.RollbackToSavepoint:
sc.RollbackToRestartSavepointCount.Inc()
// TODO(knz): Sanitize this.
if err := ex.validateSavepointName(t.Savepoint); err == nil {
sc.RollbackToRestartSavepointCount.Inc()
} else {
sc.RollbackToSavepointCount.Inc()
}
default:
if tree.CanModifySchema(stmt) {
sc.DdlCount.Inc()
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ var (
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaReleaseSavepointStarted = metric.Metadata{
Name: "sql.savepoint.release.started.count",
Help: "Number of `RELEASE SAVEPOINT` statements started",
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaRollbackToSavepointStarted = metric.Metadata{
Name: "sql.savepoint.rollback.started.count",
Help: "Number of `ROLLBACK TO SAVEPOINT` statements started",
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaRestartSavepointStarted = metric.Metadata{
Name: "sql.restart_savepoint.started.count",
Help: "Number of `SAVEPOINT cockroach_restart` statements started",
Expand Down Expand Up @@ -461,6 +473,18 @@ var (
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaReleaseSavepointExecuted = metric.Metadata{
Name: "sql.savepoint.release.count",
Help: "Number of `RELEASE SAVEPOINT` statements successfully executed",
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaRollbackToSavepointExecuted = metric.Metadata{
Name: "sql.savepoint.rollback.count",
Help: "Number of `ROLLBACK TO SAVEPOINT` statements successfully executed",
Measurement: "SQL Statements",
Unit: metric.Unit_COUNT,
}
MetaRestartSavepointExecuted = metric.Metadata{
Name: "sql.restart_savepoint.count",
Help: "Number of `SAVEPOINT cockroach_restart` statements successfully executed",
Expand Down
8 changes: 8 additions & 0 deletions pkg/ts/catalog/chart_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,14 @@ var charts = []sectionDescription{
"sql.savepoint.count.internal",
"sql.savepoint.started.count",
"sql.savepoint.started.count.internal",
"sql.savepoint.rollback.count",
"sql.savepoint.rollback.count.internal",
"sql.savepoint.rollback.started.count",
"sql.savepoint.rollback.started.count.internal",
"sql.savepoint.release.count",
"sql.savepoint.release.count.internal",
"sql.savepoint.release.started.count",
"sql.savepoint.release.started.count.internal",
},
AxisLabel: "SQL Statements",
},
Expand Down

0 comments on commit 19b91d7

Please sign in to comment.