Skip to content

Commit

Permalink
ttl: add telemetry
Browse files Browse the repository at this point in the history
This commit adds telemetry to row level TTL configuration, as well as
executions of the row level TTL job.

Release note: None

Release justification: low risk high benefit changes to new
functionality
  • Loading branch information
otan committed Feb 28, 2022
1 parent 4fa089a commit df93409
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,8 @@ func handleTTLStorageParamChange(
return err
}
case before != nil && after == nil:
telemetry.Inc(sqltelemetry.RowLevelTTLDropped)

// Keep the TTL from beforehand, but create the DROP COLUMN job and the
// associated mutation.
tableDesc.RowLevelTTL = before
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ func CreateRowLevelTTLScheduledJob(
tblID descpb.ID,
ttl *catpb.RowLevelTTL,
) (*jobs.ScheduledJob, error) {
telemetry.Inc(sqltelemetry.RowLevelTTLCreated)
env := JobSchedulerEnv(execCfg)
j, err := newRowLevelTTLScheduledJob(env, owner, tblID, ttl)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/paramparse/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/geo/geoindex",
"//pkg/server/telemetry",
"//pkg/sql/catalog/catpb",
"//pkg/sql/catalog/descpb",
"//pkg/sql/catalog/tabledesc",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/pgwire/pgnotice",
"//pkg/sql/sem/tree",
"//pkg/sql/sqltelemetry",
"//pkg/sql/types",
"//pkg/util/duration",
"//pkg/util/errorutil/unimplemented",
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/paramparse/paramobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
"strings"

"github.com/cockroachdb/cockroach/pkg/geo/geoindex"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/duration"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
Expand All @@ -42,6 +44,8 @@ func SetStorageParameters(
if sp.Value == nil {
return pgerror.Newf(pgcode.InvalidParameterValue, "storage parameter %q requires a value", key)
}
telemetry.Inc(sqltelemetry.SetTableStorageParameter(key))

// Expressions may be an unresolved name.
// Cast these as strings.
expr := UnresolvedNameToStrVal(sp.Value)
Expand Down Expand Up @@ -75,6 +79,7 @@ func ResetStorageParameters(
paramObserver StorageParamObserver,
) error {
for _, p := range params {
telemetry.Inc(sqltelemetry.ResetTableStorageParameter(string(p)))
if err := paramObserver.onReset(evalCtx, string(p)); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sqltelemetry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
"schema.go",
"session.go",
"show.go",
"ttl.go",
"user_defined_schema.go",
"virtual_schema.go",
],
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/sqltelemetry/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,15 @@ var SchemaRefreshMaterializedView = telemetry.GetCounterOnce("sql.schema.refresh
func SchemaChangeErrorCounter(typ string) telemetry.Counter {
return telemetry.GetCounter(fmt.Sprintf("sql.schema_changer.errors.%s", typ))
}

// SetTableStorageParameter is to be incremented every time a table storage
// parameter has been SET (through CREATE TABLE or ALTER TABLE).
func SetTableStorageParameter(param string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.table_storage_parameter." + param + ".set")
}

// ResetTableStorageParameter is to be incremented every time a table storage
// parameter has been RESET.
func ResetTableStorageParameter(param string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.table_storage_parameter." + param + ".reset")
}
25 changes: 25 additions & 0 deletions pkg/sql/sqltelemetry/ttl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package sqltelemetry

import "github.com/cockroachdb/cockroach/pkg/server/telemetry"

var (
// RowLevelTTLCreated is incremented when a row level TTL table is created.
RowLevelTTLCreated = telemetry.GetCounterOnce("sql.row_level_ttl.created")

// RowLevelTTLDropped is incremented when a row level TTL has been dropped
// from a table.
RowLevelTTLDropped = telemetry.GetCounterOnce("sql.row_level_ttl.dropped")

// RowLevelTTLExecuted is incremented when a row level TTL job has executed.
RowLevelTTLExecuted = telemetry.GetCounterOnce("sql.row_level_ttl.job_executed")
)
34 changes: 34 additions & 0 deletions pkg/sql/testdata/telemetry/ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
feature-allowlist
sql.schema.table_storage_parameter.*
sql.row_level_ttl.created
sql.row_level_ttl.dropped
----

feature-usage
CREATE TABLE tbl () WITH (ttl_expire_after = '10 minutes', ttl_select_batch_size = 100)
----
sql.row_level_ttl.created
sql.schema.table_storage_parameter.ttl_expire_after.set
sql.schema.table_storage_parameter.ttl_select_batch_size.set

feature-usage
ALTER TABLE tbl SET (ttl_delete_batch_size = 200)
----
sql.schema.table_storage_parameter.ttl_delete_batch_size.set

feature-usage
ALTER TABLE tbl RESET (ttl_select_batch_size)
----
sql.schema.table_storage_parameter.ttl_select_batch_size.reset

feature-usage
ALTER TABLE tbl RESET (ttl)
----
sql.row_level_ttl.dropped
sql.schema.table_storage_parameter.ttl.reset

feature-usage
ALTER TABLE tbl SET (ttl_expire_after = '10 hours')
----
sql.row_level_ttl.created
sql.schema.table_storage_parameter.ttl_expire_after.set
2 changes: 2 additions & 0 deletions pkg/sql/ttl/ttljob/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
"//pkg/keys",
"//pkg/kv",
"//pkg/roachpb",
"//pkg/server/telemetry",
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/sql",
Expand All @@ -23,6 +24,7 @@ go_library(
"//pkg/sql/lexbase",
"//pkg/sql/rowenc",
"//pkg/sql/sem/tree",
"//pkg/sql/sqltelemetry",
"//pkg/sql/types",
"//pkg/util/ctxgroup",
"//pkg/util/metric",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/ttl/ttljob/ttljob.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/metric"
Expand Down Expand Up @@ -225,6 +227,8 @@ func (t rowLevelTTLResumer) Resume(ctx context.Context, execCtx interface{}) err
)
}

telemetry.Inc(sqltelemetry.RowLevelTTLExecuted)

var knobs sql.TTLTestingKnobs
if ttlKnobs := p.ExecCfg().TTLTestingKnobs; ttlKnobs != nil {
knobs = *ttlKnobs
Expand Down

0 comments on commit df93409

Please sign in to comment.