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

ttl: add telemetry #77108

Merged
merged 1 commit into from
Mar 3, 2022
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
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 @@ -15,6 +15,7 @@ go_library(
"//pkg/kv",
"//pkg/roachpb",
"//pkg/security",
"//pkg/server/telemetry",
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/sql",
Expand All @@ -27,6 +28,7 @@ go_library(
"//pkg/sql/sem/tree",
"//pkg/sql/sessiondata",
"//pkg/sql/sessiondatapb",
"//pkg/sql/sqltelemetry",
"//pkg/sql/types",
"//pkg/util/ctxgroup",
"//pkg/util/log",
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 @@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security"
"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 @@ -34,6 +35,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb"
"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/log"
Expand Down Expand Up @@ -253,6 +255,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