Skip to content

Commit

Permalink
Merge #80771
Browse files Browse the repository at this point in the history
80771: tree: move telemetry references to sql package r=ajwerner a=otan

Individual commits should be fairly easy to review by themselves!

There are still indirect references as of writing, but this removes the direct ones!

Co-authored-by: Oliver Tan <[email protected]>
  • Loading branch information
craig[bot] and otan committed May 17, 2022
2 parents 2d53147 + c2138b7 commit dc79c28
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 304 deletions.
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ go_library(
"tablewriter_insert.go",
"tablewriter_update.go",
"tablewriter_upsert_opt.go",
"telemetry.go",
"telemetry_logging.go",
"temporary_schema.go",
"tenant.go",
Expand Down
6 changes: 4 additions & 2 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func (p *planner) AlterTable(ctx context.Context, n *tree.AlterTable) (planNode,
tree.Name(tableDesc.GetName()), tree.Name(tableDesc.GetName()))
}

n.HoistAddColumnConstraints()
n.HoistAddColumnConstraints(func() {
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra("table", "add_column.references"))
})

// See if there's any "inject statistics" in the query and type check the
// expressions.
Expand Down Expand Up @@ -165,7 +167,7 @@ func (n *alterTableNode) startExec(params runParams) error {
}

for i, cmd := range n.n.Cmds {
telemetry.Inc(cmd.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra("table", cmd.TelemetryName()))

if !n.tableDesc.HasPrimaryKey() && !isAlterCmdValidWithoutPrimaryKey(cmd) {
return errors.Newf("table %q does not have a primary key, cannot perform%s", n.tableDesc.Name, tree.AsString(cmd))
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/alter_table_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/sql/decodeusername"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
)

Expand Down Expand Up @@ -79,7 +80,10 @@ func (p *planner) AlterTableOwner(ctx context.Context, n *tree.AlterTableOwner)
}

func (n *alterTableOwnerNode) startExec(params runParams) error {
telemetry.Inc(n.n.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra(
tree.GetTableType(n.n.IsSequence, n.n.IsView, n.n.IsMaterialized),
n.n.TelemetryName(),
))
ctx := params.ctx
p := params.p
tableDesc := n.desc
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/alter_table_set_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
)

Expand Down Expand Up @@ -96,7 +97,10 @@ func (p *planner) AlterTableSetSchema(
}

func (n *alterTableSetSchemaNode) startExec(params runParams) error {
telemetry.Inc(n.n.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra(
tree.GetTableType(n.n.IsSequence, n.n.IsView, n.n.IsMaterialized),
n.n.TelemetryName(),
))
ctx := params.ctx
p := params.p
tableDesc := n.tableDesc
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/alter_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p *planner) AlterType(ctx context.Context, n *tree.AlterType) (planNode, e
}

func (n *alterTypeNode) startExec(params runParams) error {
telemetry.Inc(n.n.Cmd.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra("type", n.n.Cmd.TelemetryName()))

typeName := tree.AsStringWithFQNames(n.n.Type, params.p.Ann())
eventLogDone := false
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/drop_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -90,7 +91,9 @@ func (p *planner) DropView(ctx context.Context, n *tree.DropView) (planNode, err
func (n *dropViewNode) ReadingOwnWrites() {}

func (n *dropViewNode) startExec(params runParams) error {
telemetry.Inc(n.n.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaChangeDropCounter(
tree.GetTableType(false /* isSequence */, true /* isView */, n.n.IsMaterialized),
))

ctx := params.ctx
for _, toDel := range n.td {
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/refresh_materialized_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"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"
)

type refreshMaterializedViewNode struct {
Expand Down Expand Up @@ -79,7 +80,7 @@ func (n *refreshMaterializedViewNode) startExec(params runParams) error {
// results of the view query into the new set of indexes, and then change the
// set of indexes over to the new set of indexes atomically.

telemetry.Inc(n.n.TelemetryCounter())
telemetry.Inc(sqltelemetry.SchemaRefreshMaterializedView)

// Inform the user that CONCURRENTLY is not needed.
if n.n.Concurrently {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scbuild/internal/scbuildstmt",
visibility = ["//pkg/sql/schemachanger/scbuild:__subpackages__"],
deps = [
"//pkg/server/telemetry",
"//pkg/settings/cluster",
"//pkg/sql/catalog",
"//pkg/sql/catalog/catpb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ package scbuildstmt
import (
"reflect"

"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -52,7 +54,9 @@ func init() {
func AlterTable(b BuildCtx, n *tree.AlterTable) {
// Hoist the constraints to separate clauses because other code assumes that
// that is how the commands will look.
n.HoistAddColumnConstraints()
n.HoistAddColumnConstraints(func() {
telemetry.Inc(sqltelemetry.SchemaChangeAlterCounterWithExtra("table", "add_column.references"))
})
// Check if an entry exists for the statement type, in which
// case. It's either fully or partially supported. Check the commands
// first, since we don't want to do extra work in this transaction
Expand Down
8 changes: 7 additions & 1 deletion pkg/sql/sem/builtins/all_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"fmt"
"sort"

"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/cockroach/pkg/sql/types"
)

Expand Down Expand Up @@ -59,7 +61,7 @@ func init() {
} else if def.props.Class == tree.WindowClass {
AllWindowBuiltinNames = append(AllWindowBuiltinNames, name)
}
for _, overload := range def.overloads {
for i, overload := range def.overloads {
fnCount := 0
if overload.Fn != nil {
fnCount++
Expand All @@ -84,6 +86,10 @@ func init() {
name, fnCount,
))
}
c := sqltelemetry.BuiltinCounter(name, overload.Signature(false))
def.overloads[i].OnTypeCheck = func() {
telemetry.Inc(c)
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/sem/tree/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ go_library(
"name_part.go",
"name_resolution.go",
"object_name.go",
"operators.go",
"overload.go",
"parse_array.go",
"parse_string.go", # keep
Expand Down Expand Up @@ -119,7 +118,6 @@ go_library(
deps = [
"//pkg/geo",
"//pkg/geo/geopb",
"//pkg/server/telemetry",
"//pkg/sql/lex",
"//pkg/sql/lexbase",
"//pkg/sql/pgwire/pgcode",
Expand All @@ -134,7 +132,6 @@ go_library(
"//pkg/sql/sem/tree/treewindow",
"//pkg/sql/sem/volatility",
"//pkg/sql/sessiondatapb",
"//pkg/sql/sqltelemetry",
"//pkg/sql/types",
"//pkg/util",
"//pkg/util/bitarray",
Expand Down
Loading

0 comments on commit dc79c28

Please sign in to comment.