diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index d7782bf8df91..ef39fbe83887 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -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 @@ -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( @@ -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( @@ -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() diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 5810317dba75..c1cacd08281f 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -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", @@ -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", diff --git a/pkg/ts/catalog/chart_catalog.go b/pkg/ts/catalog/chart_catalog.go index dd7f94c7ce60..7d3abeffedfa 100644 --- a/pkg/ts/catalog/chart_catalog.go +++ b/pkg/ts/catalog/chart_catalog.go @@ -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", },