Skip to content

Commit

Permalink
Merge #80895
Browse files Browse the repository at this point in the history
80895: roleoption: remove sqltelemetry dependency r=ajwerner a=otan

For GetStmts, instead use a function hook to inject any necessary
telemetry calls. This is one more step towards removing `util/log`
dependencies from the `tree` package.

Release note: None

Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
  • Loading branch information
craig[bot] and otan committed May 3, 2022
2 parents 01572da + d5170bb commit d63a369
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pkg/sql/alter_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func (n *alterRoleNode) startExec(params runParams) error {
}

// Get a map of statements to execute for role options and their values.
stmts, err := n.roleOptions.GetSQLStmts(sqltelemetry.AlterRole)
stmts, err := n.roleOptions.GetSQLStmts(func(o roleoption.Option) {
sqltelemetry.IncIAMOptionCounter(sqltelemetry.AlterRole, strings.ToLower(o.String()))
})
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/create_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package sql
import (
"context"
"fmt"
"strings"

"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/security/password"
Expand Down Expand Up @@ -168,7 +169,9 @@ func (n *CreateRoleNode) startExec(params runParams) error {
}

// Get a map of statements to execute for role options and their values.
stmts, err := n.roleOptions.GetSQLStmts(sqltelemetry.CreateRole)
stmts, err := n.roleOptions.GetSQLStmts(func(o roleoption.Option) {
sqltelemetry.IncIAMOptionCounter(sqltelemetry.CreateRole, strings.ToLower(o.String()))
})
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/roleoption/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
deps = [
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/sqltelemetry",
"@com_github_cockroachdb_errors//:errors",
],
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/roleoption/role_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -148,7 +147,9 @@ type List []RoleOption

// GetSQLStmts returns a map of SQL stmts to apply each role option.
// Maps stmts to values (value of the role option).
func (rol List) GetSQLStmts(op string) (map[string]func() (bool, string, error), error) {
func (rol List) GetSQLStmts(
onRoleOption func(Option),
) (map[string]func() (bool, string, error), error) {
if len(rol) <= 0 {
return nil, nil
}
Expand All @@ -161,10 +162,9 @@ func (rol List) GetSQLStmts(op string) (map[string]func() (bool, string, error),
}

for _, ro := range rol {
sqltelemetry.IncIAMOptionCounter(
op,
strings.ToLower(ro.Option.String()),
)
if onRoleOption != nil {
onRoleOption(ro.Option)
}
// Skip PASSWORD and DEFAULTSETTINGS options.
// Since PASSWORD still resides in system.users, we handle setting PASSWORD
// outside of this set stmt.
Expand Down

0 comments on commit d63a369

Please sign in to comment.