From 10b797f749d482d677cf4616a0f5e36d5d02f334 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 11 Mar 2020 07:56:47 -0700 Subject: [PATCH 1/5] roachtest: adjust tpchvec Release justification: non-production code change. This commit unskips query 9 and removes some code that was put in place to handle missing disk spilling in the vectorized engine. Release note: None --- pkg/cmd/roachtest/tpchvec.go | 72 ++++++++++++++---------------------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/pkg/cmd/roachtest/tpchvec.go b/pkg/cmd/roachtest/tpchvec.go index 7daa02549631..f9c169c01189 100644 --- a/pkg/cmd/roachtest/tpchvec.go +++ b/pkg/cmd/roachtest/tpchvec.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/cockroachdb/cockroach/pkg/util/randutil" - tpchworkload "github.com/cockroachdb/cockroach/pkg/workload/tpch" ) func registerTPCHVec(r *testRegistry) { @@ -49,10 +48,6 @@ func registerTPCHVec(r *testRegistry) { 9: "can cause OOM", 19: "can cause OOM", } - queriesToSkipByVersionPrefix["v20.1"] = map[int]string{ - // TODO(yuzefovich): remove this once disk spilling is in place. - 9: "needs disk spilling", - } runTPCHVec := func(ctx context.Context, t *test, c *cluster) { TPCHTables := []string{ @@ -522,14 +517,7 @@ RESTORE tpch.* FROM 'gs://cockroach-fixtures/workload/tpch/scalefactor=1/backup' if err != nil { // Note: if you see an error like "exit status 1", it is likely caused // by the erroneous output of the query. - t.Status(fmt.Sprintf("\n%s", err)) - // We expect that with low workmem limit some queries can hit OOM - // error, and we don't want to fail the test in such scenarios. - // TODO(yuzefovich): remove the condition once disk spilling is in - // place. - if !strings.Contains(string(workloadOutput), "memory budget exceeded") { - t.Fatal(err) - } + t.Fatal(err) } parseOutput := func(output []byte, timeByQueryNum map[int][]float64) { runtimeRegex := regexp.MustCompile(`.*\[q([\d]+)\] returned \d+ rows after ([\d]+\.[\d]+) seconds.*`) @@ -551,17 +539,9 @@ RESTORE tpch.* FROM 'gs://cockroach-fixtures/workload/tpch/scalefactor=1/backup' } } parseOutput(workloadOutput, timeByQueryNum[configIdx]) - // We want to fail the test only if wrong results were returned (we - // ignore errors like OOM and unsupported features in order to not - // short-circuit the run of this test). - if strings.Contains(string(workloadOutput), tpchworkload.TPCHWrongOutputErrorPrefix) { - t.Fatal("tpch workload found wrong results") - } } } - // TODO(yuzefovich): remove the note when disk spilling is in place. - t.Status("comparing the runtimes (only median values for each query are compared).\n" + - "NOTE: the comparison might not be fair because vec ON doesn't spill to disk") + t.Status("comparing the runtimes (only median values for each query are compared)") for queryNum := 1; queryNum <= numTPCHQueries; queryNum++ { if _, skipped := queriesToSkip[queryNum]; skipped { continue @@ -572,32 +552,36 @@ RESTORE tpch.* FROM 'gs://cockroach-fixtures/workload/tpch/scalefactor=1/backup' } vecOnTimes := timeByQueryNum[vecOnConfig][queryNum] vecOffTimes := timeByQueryNum[vecOffConfig][queryNum] + if len(vecOnTimes) != numRunsPerQuery { + t.Fatal(fmt.Sprintf("[q%d] unexpectedly wrong number of run times "+ + "recorded with vec ON config: %v", queryNum, vecOnTimes)) + } if len(vecOffTimes) != numRunsPerQuery { t.Fatal(fmt.Sprintf("[q%d] unexpectedly wrong number of run times "+ "recorded with vec OFF config: %v", queryNum, vecOffTimes)) } - // It is possible that the query errored out on vec ON config. We want to - // compare the run times only if that's not the case. - if len(vecOnTimes) > 0 { - vecOnTime := findMedian(vecOnTimes) - vecOffTime := findMedian(vecOffTimes) - if vecOffTime < vecOnTime { - t.l.Printf( - fmt.Sprintf("[q%d] vec OFF was faster by %.2f%%: "+ - "%.2fs ON vs %.2fs OFF --- WARNING", - queryNum, 100*(vecOnTime-vecOffTime)/vecOffTime, vecOnTime, vecOffTime)) - } else { - t.l.Printf( - fmt.Sprintf("[q%d] vec ON was faster by %.2f%%: "+ - "%.2fs ON vs %.2fs OFF", - queryNum, 100*(vecOffTime-vecOnTime)/vecOnTime, vecOnTime, vecOffTime)) - } - if vecOnTime >= vecOnSlowerFailFactor*vecOffTime { - t.Fatal(fmt.Sprintf( - "[q%d] vec ON is slower by %.2f%% than vec OFF\n"+ - "vec ON times: %v\nvec OFF times: %v", - queryNum, 100*(vecOnTime-vecOffTime)/vecOffTime, vecOnTimes, vecOffTimes)) - } + vecOnTime := findMedian(vecOnTimes) + vecOffTime := findMedian(vecOffTimes) + if vecOffTime < vecOnTime { + t.l.Printf( + fmt.Sprintf("[q%d] vec OFF was faster by %.2f%%: "+ + "%.2fs ON vs %.2fs OFF --- WARNING\n"+ + "vec ON times: %v\t vec OFF times: %v", + queryNum, 100*(vecOnTime-vecOffTime)/vecOffTime, + vecOnTime, vecOffTime, vecOnTimes, vecOffTimes)) + } else { + t.l.Printf( + fmt.Sprintf("[q%d] vec ON was faster by %.2f%%: "+ + "%.2fs ON vs %.2fs OFF\n"+ + "vec ON times: %v\t vec OFF times: %v", + queryNum, 100*(vecOffTime-vecOnTime)/vecOnTime, + vecOnTime, vecOffTime, vecOnTimes, vecOffTimes)) + } + if vecOnTime >= vecOnSlowerFailFactor*vecOffTime { + t.Fatal(fmt.Sprintf( + "[q%d] vec ON is slower by %.2f%% than vec OFF\n"+ + "vec ON times: %v\nvec OFF times: %v", + queryNum, 100*(vecOnTime-vecOffTime)/vecOffTime, vecOnTimes, vecOffTimes)) } } } From 73c02a039ab5877df9845d4398b7daed0e2f6019 Mon Sep 17 00:00:00 2001 From: Bilal Akhtar Date: Thu, 12 Mar 2020 11:50:03 -0400 Subject: [PATCH 2/5] vendor, rocksdb: Bump rocksdb and pebble refs Bumps rocksdb ref to pick up https://github.com/cockroachdb/rocksdb/pull/75 Bumps pebble ref to pick up SeqNum fix and standardization of initial and last SeqNum handling with RocksDB. New pebble revision is d2ecbc248decea8d177e2d2777d8ef458267eddc Release note: None --- Gopkg.lock | 4 ++-- c-deps/rocksdb | 2 +- vendor | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c4c60a0704d6..a78bf9192bf4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -472,7 +472,7 @@ [[projects]] branch = "master" - digest = "1:01bf778f6e655358343f994d5d2f2869572308fa99947222397a9cbce98b0643" + digest = "1:b04136030905c3098f8b6ad62d968b626a8263c7471232fb2fed41505a0e355e" name = "github.com/cockroachdb/pebble" packages = [ ".", @@ -498,7 +498,7 @@ "vfs", ] pruneopts = "UT" - revision = "4cd6b788322117605dc3a64b3525555805ec499f" + revision = "d2ecbc248decea8d177e2d2777d8ef458267eddc" [[projects]] branch = "master" diff --git a/c-deps/rocksdb b/c-deps/rocksdb index 9cee3b54aae2..31a10dcf79ae 160000 --- a/c-deps/rocksdb +++ b/c-deps/rocksdb @@ -1 +1 @@ -Subproject commit 9cee3b54aae29d14fdab520edf4475e408dade98 +Subproject commit 31a10dcf79aea3cf45012a67562906da84bff8f3 diff --git a/vendor b/vendor index 8fe45c23f649..4a0c4acfe6ef 160000 --- a/vendor +++ b/vendor @@ -1 +1 @@ -Subproject commit 8fe45c23f6490f086b7f20eed4ede6b123c879f9 +Subproject commit 4a0c4acfe6ef61a8cac36411a29433a210038415 From 3a83207a6d9ae1ce5b36b2ab866c5e613fbcf5a9 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 11 Mar 2020 15:02:18 -0700 Subject: [PATCH 3/5] sql: remove some unused code Release justification: non-production code changes. This code is no longer needed since the optimizer took over planning of the window functions. Release note: None --- pkg/sql/sem/transform/window.go | 48 ----------------------- pkg/sql/sem/tree/expr.go | 20 ---------- pkg/sql/window.go | 69 --------------------------------- 3 files changed, 137 deletions(-) delete mode 100644 pkg/sql/sem/transform/window.go diff --git a/pkg/sql/sem/transform/window.go b/pkg/sql/sem/transform/window.go deleted file mode 100644 index 4b3c52866e78..000000000000 --- a/pkg/sql/sem/transform/window.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 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 transform - -import "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" - -var _ tree.Visitor = &ContainsWindowVisitor{} - -// ContainsWindowVisitor checks if walked expressions contain window functions. -type ContainsWindowVisitor struct { - sawWindow bool -} - -// VisitPre satisfies the Visitor interface. -func (v *ContainsWindowVisitor) VisitPre(expr tree.Expr) (recurse bool, newExpr tree.Expr) { - switch t := expr.(type) { - case *tree.FuncExpr: - if t.IsWindowFunctionApplication() { - v.sawWindow = true - return false, expr - } - case *tree.Subquery: - return false, expr - } - return true, expr -} - -// VisitPost satisfies the Visitor interface. -func (*ContainsWindowVisitor) VisitPost(expr tree.Expr) tree.Expr { return expr } - -// ContainsWindowFunc determines if an Expr contains a window function. -func (v *ContainsWindowVisitor) ContainsWindowFunc(expr tree.Expr) bool { - if expr != nil { - tree.WalkExprConst(v, expr) - ret := v.sawWindow - v.sawWindow = false - return ret - } - return false -} diff --git a/pkg/sql/sem/tree/expr.go b/pkg/sql/sem/tree/expr.go index 53e812072901..3d5929c07cc2 100644 --- a/pkg/sql/sem/tree/expr.go +++ b/pkg/sql/sem/tree/expr.go @@ -1266,26 +1266,6 @@ func (node *FuncExpr) ResolvedOverload() *Overload { return node.fn } -// GetAggregateConstructor exposes the AggregateFunc field for use by -// the group node in package sql. -func (node *FuncExpr) GetAggregateConstructor() func(*EvalContext, Datums) AggregateFunc { - if node.fn == nil || node.fn.AggregateFunc == nil { - return nil - } - return func(evalCtx *EvalContext, arguments Datums) AggregateFunc { - types := typesOfExprs(node.Exprs) - return node.fn.AggregateFunc(types, evalCtx, arguments) - } -} - -func typesOfExprs(exprs Exprs) []*types.T { - types := make([]*types.T, len(exprs)) - for i, expr := range exprs { - types[i] = expr.(TypedExpr).ResolvedType() - } - return types -} - // IsGeneratorApplication returns true iff the function applied is a generator (SRF). func (node *FuncExpr) IsGeneratorApplication() bool { return node.fn != nil && node.fn.Generator != nil diff --git a/pkg/sql/window.go b/pkg/sql/window.go index 4a607251c7b6..232c13c17ed0 100644 --- a/pkg/sql/window.go +++ b/pkg/sql/window.go @@ -13,9 +13,6 @@ package sql import ( "context" - "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" - "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" - "github.com/cockroachdb/cockroach/pkg/sql/sem/transform" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" "github.com/cockroachdb/cockroach/pkg/sql/types" @@ -73,75 +70,9 @@ func (n *windowNode) Close(ctx context.Context) { n.plan.Close(ctx) } -type extractWindowFuncsVisitor struct { - n *windowNode - - // Avoids allocations. - subWindowVisitor transform.ContainsWindowVisitor - - // Persisted visitor state. - aggregatesSeen map[*tree.FuncExpr]struct{} - windowFnCount int - err error -} - -var _ tree.Visitor = &extractWindowFuncsVisitor{} - -func (v *extractWindowFuncsVisitor) VisitPre(expr tree.Expr) (recurse bool, newExpr tree.Expr) { - if v.err != nil { - return false, expr - } - - switch t := expr.(type) { - case *tree.FuncExpr: - switch { - case t.IsWindowFunctionApplication(): - // Check if a parent node above this window function is an aggregate. - if len(v.aggregatesSeen) > 0 { - v.err = sqlbase.NewWindowInAggError() - return false, expr - } - - // Make sure this window function does not contain another window function. - for _, argExpr := range t.Exprs { - if v.subWindowVisitor.ContainsWindowFunc(argExpr) { - v.err = pgerror.Newf(pgcode.Windowing, "window function calls cannot be nested") - return false, expr - } - } - - f := &windowFuncHolder{ - expr: t, - args: t.Exprs, - window: v.n, - filterColIdx: noFilterIdx, - } - v.windowFnCount++ - v.n.funcs = append(v.n.funcs, f) - return false, f - - case t.GetAggregateConstructor() != nil: - // If we see an aggregation that is not used in a window function, we save it - // in the visitor's seen aggregate set. The aggregate function will remain in - // this set until the recursion into its children is complete. - v.aggregatesSeen[t] = struct{}{} - } - } - return true, expr -} - -func (v *extractWindowFuncsVisitor) VisitPost(expr tree.Expr) tree.Expr { - if fn, ok := expr.(*tree.FuncExpr); ok { - delete(v.aggregatesSeen, fn) - } - return expr -} - var _ tree.TypedExpr = &windowFuncHolder{} var _ tree.VariableExpr = &windowFuncHolder{} -const noFilterIdx = -1 - type windowFuncHolder struct { window *windowNode From bbb3afbe1c29b5f1f5aa770d2ba5c846e71862bd Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 11 Mar 2020 15:11:00 -0700 Subject: [PATCH 4/5] sql: add telemetry for window functions Release justification: telemetry change. Release note: None --- pkg/sql/opt/exec/execbuilder/relational.go | 3 +++ pkg/sql/sqltelemetry/planning.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/sql/opt/exec/execbuilder/relational.go b/pkg/sql/opt/exec/execbuilder/relational.go index b116f33a2018..c9bd36429e34 100644 --- a/pkg/sql/opt/exec/execbuilder/relational.go +++ b/pkg/sql/opt/exec/execbuilder/relational.go @@ -1796,6 +1796,9 @@ func (b *Builder) buildWindow(w *memo.WindowExpr) (execPlan, error) { item := &w.Windows[i] fn := b.extractWindowFunction(item.Function) name, overload := memo.FindWindowOverload(fn) + if !b.disableTelemetry { + telemetry.Inc(sqltelemetry.WindowFunctionCounter(name)) + } props, _ := builtins.GetBuiltinProperties(name) args := make([]tree.TypedExpr, fn.ChildCount()) diff --git a/pkg/sql/sqltelemetry/planning.go b/pkg/sql/sqltelemetry/planning.go index 52ce5a7251a0..fde5c88a46e8 100644 --- a/pkg/sql/sqltelemetry/planning.go +++ b/pkg/sql/sqltelemetry/planning.go @@ -120,3 +120,9 @@ func ReportJoinReorderLimit(value int) { telemetry.Inc(reorderJoinLimitMoreCounter) } } + +// WindowFunctionCounter is to be incremented every time a window function is +// being planned. +func WindowFunctionCounter(wf string) telemetry.Counter { + return telemetry.GetCounter("sql.plan.window_function." + wf) +} From 0495ab272a3d5b2d92322fa109f605c57b42f38b Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Thu, 12 Mar 2020 09:41:07 -0700 Subject: [PATCH 5/5] sqltelemetry: adjust IAM telemetry methods to have Inc/Counter Trying to standardise the sqltelemetry package such that every name ends with `Counter`, so this is a `sed` replace to do just that. Also noticed that `IAMAlter` has a different name, so fixing that form too. Release justification: Refactoring of names only. Release note: None --- pkg/ccl/roleccl/role.go | 4 +- pkg/sql/alter_role.go | 4 +- pkg/sql/create_role.go | 4 +- pkg/sql/drop_role.go | 4 +- pkg/sql/grant_revoke.go | 8 ++-- pkg/sql/roleoption/role_option.go | 2 +- pkg/sql/sqltelemetry/iam.go | 68 +++++++++++++++---------------- 7 files changed, 46 insertions(+), 48 deletions(-) diff --git a/pkg/ccl/roleccl/role.go b/pkg/ccl/roleccl/role.go index 5c2f784f47d3..850c76402722 100644 --- a/pkg/ccl/roleccl/role.go +++ b/pkg/ccl/roleccl/role.go @@ -96,7 +96,7 @@ func grantRolePlanHook( return nil, nil, nil, false, nil } - sqltelemetry.IncIAMGrant(grant.AdminOption) + sqltelemetry.IncIAMGrantCounter(grant.AdminOption) fn = func(ctx context.Context, _ []sql.PlanNode, _ chan<- tree.Datums) error { // TODO(dan): Move this span into sql. @@ -250,7 +250,7 @@ func revokeRolePlanHook( return nil, nil, nil, false, nil } - sqltelemetry.IncIAMRevoke(revoke.AdminOption) + sqltelemetry.IncIAMRevokeCounter(revoke.AdminOption) fn = func(ctx context.Context, _ []sql.PlanNode, _ chan<- tree.Datums) error { // TODO(dan): Move this span into sql. diff --git a/pkg/sql/alter_role.go b/pkg/sql/alter_role.go index cdb57f02b083..b0d4ca6173fd 100644 --- a/pkg/sql/alter_role.go +++ b/pkg/sql/alter_role.go @@ -86,10 +86,10 @@ type alterRoleRun struct { func (n *alterRoleNode) startExec(params runParams) error { var opName string if n.isRole { - sqltelemetry.IAMAlter(sqltelemetry.Role) + sqltelemetry.IncIAMAlterCounter(sqltelemetry.Role) opName = "alter-role" } else { - sqltelemetry.IAMAlter(sqltelemetry.User) + sqltelemetry.IncIAMAlterCounter(sqltelemetry.User) opName = "alter-user" } name, err := n.name() diff --git a/pkg/sql/create_role.go b/pkg/sql/create_role.go index 7be47ec6ad85..3a257cb19ec0 100644 --- a/pkg/sql/create_role.go +++ b/pkg/sql/create_role.go @@ -97,10 +97,10 @@ func (p *planner) CreateRoleNode( func (n *CreateRoleNode) startExec(params runParams) error { var opName string if n.isRole { - sqltelemetry.IncIAMCreate(sqltelemetry.Role) + sqltelemetry.IncIAMCreateCounter(sqltelemetry.Role) opName = "create-role" } else { - sqltelemetry.IncIAMCreate(sqltelemetry.User) + sqltelemetry.IncIAMCreateCounter(sqltelemetry.User) opName = "create-user" } diff --git a/pkg/sql/drop_role.go b/pkg/sql/drop_role.go index f97714f621ac..dee2dd06f949 100644 --- a/pkg/sql/drop_role.go +++ b/pkg/sql/drop_role.go @@ -70,10 +70,10 @@ type dropRoleRun struct { func (n *DropRoleNode) startExec(params runParams) error { var opName string if n.isRole { - sqltelemetry.IncIAMDrop(sqltelemetry.Role) + sqltelemetry.IncIAMDropCounter(sqltelemetry.Role) opName = "drop-role" } else { - sqltelemetry.IncIAMDrop(sqltelemetry.User) + sqltelemetry.IncIAMDropCounter(sqltelemetry.User) opName = "drop-user" } diff --git a/pkg/sql/grant_revoke.go b/pkg/sql/grant_revoke.go index 8550f0003d4a..a45b00798f9e 100644 --- a/pkg/sql/grant_revoke.go +++ b/pkg/sql/grant_revoke.go @@ -31,9 +31,9 @@ import ( // mysql requires the "grant option" and the same privileges, and sometimes superuser. func (p *planner) Grant(ctx context.Context, n *tree.Grant) (planNode, error) { if n.Targets.Databases != nil { - sqltelemetry.IncIAMGrantPrivileges(sqltelemetry.OnDatabase) + sqltelemetry.IncIAMGrantPrivilegesCounter(sqltelemetry.OnDatabase) } else { - sqltelemetry.IncIAMGrantPrivileges(sqltelemetry.OnTable) + sqltelemetry.IncIAMGrantPrivilegesCounter(sqltelemetry.OnTable) } return &changePrivilegesNode{ @@ -57,9 +57,9 @@ func (p *planner) Grant(ctx context.Context, n *tree.Grant) (planNode, error) { // mysql requires the "grant option" and the same privileges, and sometimes superuser. func (p *planner) Revoke(ctx context.Context, n *tree.Revoke) (planNode, error) { if n.Targets.Databases != nil { - sqltelemetry.IncIAMRevokePrivileges(sqltelemetry.OnDatabase) + sqltelemetry.IncIAMRevokePrivilegesCounter(sqltelemetry.OnDatabase) } else { - sqltelemetry.IncIAMRevokePrivileges(sqltelemetry.OnTable) + sqltelemetry.IncIAMRevokePrivilegesCounter(sqltelemetry.OnTable) } return &changePrivilegesNode{ diff --git a/pkg/sql/roleoption/role_option.go b/pkg/sql/roleoption/role_option.go index 19dd570077c2..61e0bb85d743 100644 --- a/pkg/sql/roleoption/role_option.go +++ b/pkg/sql/roleoption/role_option.go @@ -97,7 +97,7 @@ func (rol List) GetSQLStmts(op string) (map[string]func() (bool, string, error), } for _, ro := range rol { - sqltelemetry.IncIAMOption( + sqltelemetry.IncIAMOptionCounter( op, strings.ToLower(ro.Option.String()), ) diff --git a/pkg/sql/sqltelemetry/iam.go b/pkg/sql/sqltelemetry/iam.go index 539714df1b28..76dec8721794 100644 --- a/pkg/sql/sqltelemetry/iam.go +++ b/pkg/sql/sqltelemetry/iam.go @@ -16,53 +16,51 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/telemetry" ) -// Role is used when the syntax used is the ROLE version (ie. CREATE ROLE). -const Role = "role" - -// User is used when the syntax used is the USER version (ie. CREATE USER). -const User = "user" - -// AlterRole is used when an ALTER ROLE / USER is the operation. -const AlterRole = "alter" - -// CreateRole is used when an CREATE ROLE / USER is the operation. -const CreateRole = "create" - -// OnDatabase is used when a GRANT/REVOKE is happening on a database. -const OnDatabase = "on_database" - -// OnTable is used when a GRANT/REVOKE is happening on a table. -const OnTable = "on_table" - -const iamRoles = "iam.roles" +const ( + // Role is used when the syntax used is the ROLE version (ie. CREATE ROLE). + Role = "role" + // User is used when the syntax used is the USER version (ie. CREATE USER). + User = "user" + + // AlterRole is used when an ALTER ROLE / USER is the operation. + AlterRole = "alter" + // CreateRole is used when an CREATE ROLE / USER is the operation. + CreateRole = "create" + // OnDatabase is used when a GRANT/REVOKE is happening on a database. + OnDatabase = "on_database" + // OnTable is used when a GRANT/REVOKE is happening on a table. + OnTable = "on_table" + + iamRoles = "iam.roles" +) -// IncIAMOption is to be incremented every time a CREATE/ALTER role +// IncIAMOptionCounter is to be incremented every time a CREATE/ALTER role // with an OPTION (ie. NOLOGIN) happens. -func IncIAMOption(opName string, option string) { +func IncIAMOptionCounter(opName string, option string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s", iamRoles, opName, option))) } -// IncIAMCreate is to be incremented every time a CREATE ROLE happens. -func IncIAMCreate(typ string) { +// IncIAMCreateCounter is to be incremented every time a CREATE ROLE happens. +func IncIAMCreateCounter(typ string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s", iamRoles, "create", typ))) } -// IAMAlter is to be incremented every time an ALTER ROLE happens. -func IAMAlter(typ string) { +// IncIAMAlterCounter is to be incremented every time an ALTER ROLE happens. +func IncIAMAlterCounter(typ string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s", iamRoles, "alter", typ))) } -// IncIAMDrop is to be incremented every time a DROP ROLE happens. -func IncIAMDrop(typ string) { +// IncIAMDropCounter is to be incremented every time a DROP ROLE happens. +func IncIAMDropCounter(typ string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s", iamRoles, "drop", typ))) } -// IncIAMGrant is to be incremented every time a GRANT ROLE happens. -func IncIAMGrant(withAdmin bool) { +// IncIAMGrantCounter is to be incremented every time a GRANT ROLE happens. +func IncIAMGrantCounter(withAdmin bool) { var s string if withAdmin { s = fmt.Sprintf("%s.%s.with_admin", iamRoles, "grant") @@ -72,8 +70,8 @@ func IncIAMGrant(withAdmin bool) { telemetry.Inc(telemetry.GetCounter(s)) } -// IncIAMRevoke is to be incremented every time a REVOKE ROLE happens. -func IncIAMRevoke(withAdmin bool) { +// IncIAMRevokeCounter is to be incremented every time a REVOKE ROLE happens. +func IncIAMRevokeCounter(withAdmin bool) { var s string if withAdmin { s = fmt.Sprintf("%s.%s.with_admin", iamRoles, "revoke") @@ -83,14 +81,14 @@ func IncIAMRevoke(withAdmin bool) { telemetry.Inc(telemetry.GetCounter(s)) } -// IncIAMGrantPrivileges is to be incremented every time a GRANT happens. -func IncIAMGrantPrivileges(on string) { +// IncIAMGrantPrivilegesCounter is to be incremented every time a GRANT happens. +func IncIAMGrantPrivilegesCounter(on string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s.%s", iamRoles, "grant", "privileges", on))) } -// IncIAMRevokePrivileges is to be incremented every time a REVOKE happens. -func IncIAMRevokePrivileges(on string) { +// IncIAMRevokePrivilegesCounter is to be incremented every time a REVOKE happens. +func IncIAMRevokePrivilegesCounter(on string) { telemetry.Inc(telemetry.GetCounter( fmt.Sprintf("%s.%s.%s.%s", iamRoles, "revoke", "privileges", on))) }