Skip to content

Commit

Permalink
sql: Add telemetry for some partitioning UX improvements
Browse files Browse the repository at this point in the history
Add telemetry for the following operations:
* show partitions
* show ranges
* show locality
* show create table (intending to capture usage of new partitioning info)

Release justification: Low risk improvement to monitoring.

Release note: None
  • Loading branch information
Rohan Yadav committed Sep 17, 2019
1 parent 5cee194 commit d0a699d
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/partitioning
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ ok1 CREATE TABLE ok1 (
)
-- Warning: Partitioned table with no zone configurations.

query T
SELECT feature_name FROM crdb_internal.feature_usage WHERE feature_name='sql.show.create' AND usage_count > 0
----
sql.show.create

query T
EXPLAIN (OPT, CATALOG) SELECT * from ok1
----
Expand Down Expand Up @@ -923,3 +928,8 @@ query TTTTTTTT
SHOW PARTITIONS FROM INDEX """".t@primary
----
" t p1 NULL x t@primary (1) NULL

query T
SELECT feature_name FROM crdb_internal.feature_usage WHERE feature_name='sql.show.partitions' AND usage_count > 0
----
sql.show.partitions
2 changes: 2 additions & 0 deletions pkg/sql/delegate/show_partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/errors"
)

func (d *delegator) delegateShowPartitions(n *tree.ShowPartitions) (tree.Statement, error) {
sqltelemetry.IncrementShowCounter(sqltelemetry.Partitions)
if n.IsTable {
flags := cat.Flags{AvoidDescriptorCaches: true, NoTableStats: true}
tn := n.Table.ToTableName()
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/delegate/show_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/opt/cat"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
)

// delegateShowRanges implements the SHOW RANGES statement:
Expand All @@ -28,6 +29,7 @@ import (
// These statements show the ranges corresponding to the given table or index,
// along with the list of replicas and the lease holder.
func (d *delegator) delegateShowRanges(n *tree.ShowRanges) (tree.Statement, error) {
sqltelemetry.IncrementShowCounter(sqltelemetry.Ranges)
if n.DatabaseName != "" {
const dbQuery = `
SELECT
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/delegate/show_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/lex"
"github.com/cockroachdb/cockroach/pkg/sql/opt/cat"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
)

func (d *delegator) delegateShowCreate(n *tree.ShowCreate) (tree.Statement, error) {
sqltelemetry.IncrementShowCounter(sqltelemetry.Create)
const showCreateQuery = `
SELECT
%[3]s AS table_name,
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/delegate/show_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
)

// ValidVars contains the set of variable names; initialized from the SQL
Expand All @@ -29,6 +30,10 @@ func (d *delegator) delegateShowVar(n *tree.ShowVar) (tree.Statement, error) {
origName := n.Name
name := strings.ToLower(n.Name)

if name == "locality" {
sqltelemetry.IncrementShowCounter(sqltelemetry.Locality)
}

if name == "all" {
return parse(
"SELECT variable, value FROM crdb_internal.session_variables WHERE hidden = FALSE",
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,8 @@ query TT
SELECT start_key, end_key FROM [SHOW RANGES FROM INDEX """".t@primary]
----
NULL NULL

query T
SELECT feature_name FROM crdb_internal.feature_usage WHERE feature_name='sql.show.ranges' AND usage_count > 0
----
sql.show.ranges
14 changes: 13 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function Error
detail source SQL: foo ^


# Test the SHOW INDEXES FROM DATABSE COMMAND
# Test the SHOW INDEXES FROM DATABASE COMMAND
statement ok
CREATE DATABASE showdbindexestest;

Expand Down Expand Up @@ -374,3 +374,15 @@ SHOW INDEXES FROM DATABASE "$peci@l";
----
table1 primary false 1 key1 ASC false false
table2 primary false 1 key2 ASC false false

# Test SHOW LOCALITY telemetry.
query T
SHOW LOCALITY
----
region=test,dc=dc1

query T
SELECT feature_name FROM crdb_internal.feature_usage WHERE feature_name='sql.show.locality' AND usage_count > 0
----
sql.show.locality

58 changes: 58 additions & 0 deletions pkg/sql/sqltelemetry/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2019 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 (
"fmt"

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

// ShowTelemetryType is an enum used to represent the different show commands
// that we are recording telemetry for.
type ShowTelemetryType int

const (
_ ShowTelemetryType = iota
// Ranges represents the SHOW RANGES command.
Ranges
// Partitions represents the SHOW PARTITIONS command.
Partitions
// Locality represents the SHOW LOCALITY command.
Locality
// Create represents the SHOW CREATE command.
Create
)

var showTelemetryNameMap = map[ShowTelemetryType]string{
Ranges: "ranges",
Partitions: "partitions",
Locality: "locality",
Create: "create",
}

func (s ShowTelemetryType) String() string {
return showTelemetryNameMap[s]
}

var showTelemetryCounters map[ShowTelemetryType]telemetry.Counter

func init() {
showTelemetryCounters = make(map[ShowTelemetryType]telemetry.Counter)
for ty, s := range showTelemetryNameMap {
showTelemetryCounters[ty] = telemetry.GetCounterOnce(fmt.Sprintf("sql.show.%s", s))
}
}

// IncrementShowCounter is used to increment the telemetry counter for a particular show command.
func IncrementShowCounter(showType ShowTelemetryType) {
telemetry.Inc(showTelemetryCounters[showType])
}

0 comments on commit d0a699d

Please sign in to comment.