Skip to content

Commit

Permalink
sqltelemetry,sql: Add telemetry for partitioning related improvements
Browse files Browse the repository at this point in the history
This PR adds telemetry for the ALTER PARTITION FROM INDEX t@* command,
as well as sets up some boilerplate code for adding more partitioning
specific telemetry counters.

Work for https://github.com/cockroachlabs/registration/issues/228.

Release justification: Low risk monitoring improvement.

Release note: None
  • Loading branch information
Rohan Yadav committed Sep 18, 2019
1 parent 8e15411 commit 90a3f30
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ CREATE INDEX x2 ON t2 (x) PARTITION BY LIST (x) (
statement ok
ALTER PARTITION p1 OF INDEX t2@* CONFIGURE ZONE USING num_replicas = 1

query T
SELECT feature_name FROM crdb_internal.feature_usage WHERE feature_name='sql.partitioning.alter-all-partitions' AND usage_count > 0
----
sql.partitioning.alter-all-partitions

statement error index "t2" does not exist\nHINT: try specifying the index as <tablename>@<indexname>
ALTER PARTITION p1 OF INDEX t2 CONFIGURE ZONE USING num_replicas = 1

Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/set_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -270,6 +271,7 @@ func (n *setZoneConfigNode) startExec(params runParams) error {
// of them.
var specifiers []tree.ZoneSpecifier
if n.zoneSpecifier.TargetsPartition() && n.allIndexes {
sqltelemetry.IncrementPartitioningCounter(sqltelemetry.AlterAllPartitions)
for _, idx := range table.AllNonDropIndexes() {
if p := idx.FindPartitionByName(string(n.zoneSpecifier.Partition)); p != nil {
zs := n.zoneSpecifier
Expand Down
49 changes: 49 additions & 0 deletions pkg/sql/sqltelemetry/partitioning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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"
)

// PartitioningTelemetryType is an enum used to represent the different partitioning related operations
// that we are recording telemetry for.
type PartitioningTelemetryType int

const (
_ PartitioningTelemetryType = iota
// AlterAllPartitions represents an ALTER ALL PARTITIONS statement (ALTER PARTITION OF INDEX t@*)
AlterAllPartitions
)

var partitioningTelemetryMap = map[PartitioningTelemetryType]string{
AlterAllPartitions: "alter-all-partitions",
}

func (p PartitioningTelemetryType) String() string {
return partitioningTelemetryMap[p]
}

var partitioningTelemetryCounters map[PartitioningTelemetryType]telemetry.Counter

func init() {
partitioningTelemetryCounters = make(map[PartitioningTelemetryType]telemetry.Counter)
for ty, s := range partitioningTelemetryMap {
partitioningTelemetryCounters[ty] = telemetry.GetCounterOnce(fmt.Sprintf("sql.partitioning.%s", s))
}
}

// IncrementPartitioningCounter is used to increment the telemetry counter for a particular partitioning operation.
func IncrementPartitioningCounter(partitioningType PartitioningTelemetryType) {
telemetry.Inc(partitioningTelemetryCounters[partitioningType])
}

0 comments on commit 90a3f30

Please sign in to comment.