github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqltelemetry/iam.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package sqltelemetry
    12  
    13  import (
    14  	"fmt"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/server/telemetry"
    17  )
    18  
    19  const (
    20  	// Role is used when the syntax used is the ROLE version (ie. CREATE ROLE).
    21  	Role = "role"
    22  	// User is used when the syntax used is the USER version (ie. CREATE USER).
    23  	User = "user"
    24  
    25  	// AlterRole is used when an ALTER ROLE / USER is the operation.
    26  	AlterRole = "alter"
    27  	// CreateRole is used when an CREATE ROLE / USER is the operation.
    28  	CreateRole = "create"
    29  	// OnDatabase is used when a GRANT/REVOKE is happening on a database.
    30  	OnDatabase = "on_database"
    31  	// OnTable is used when a GRANT/REVOKE is happening on a table.
    32  	OnTable = "on_table"
    33  
    34  	iamRoles = "iam.roles"
    35  )
    36  
    37  // IncIAMOptionCounter is to be incremented every time a CREATE/ALTER role
    38  // with an OPTION (ie. NOLOGIN) happens.
    39  func IncIAMOptionCounter(opName string, option string) {
    40  	telemetry.Inc(telemetry.GetCounter(
    41  		fmt.Sprintf("%s.%s.%s", iamRoles, opName, option)))
    42  }
    43  
    44  // IncIAMCreateCounter is to be incremented every time a CREATE ROLE happens.
    45  func IncIAMCreateCounter(typ string) {
    46  	telemetry.Inc(telemetry.GetCounter(
    47  		fmt.Sprintf("%s.%s.%s", iamRoles, "create", typ)))
    48  }
    49  
    50  // IncIAMAlterCounter is to be incremented every time an ALTER ROLE happens.
    51  func IncIAMAlterCounter(typ string) {
    52  	telemetry.Inc(telemetry.GetCounter(
    53  		fmt.Sprintf("%s.%s.%s", iamRoles, "alter", typ)))
    54  }
    55  
    56  // IncIAMDropCounter is to be incremented every time a DROP ROLE happens.
    57  func IncIAMDropCounter(typ string) {
    58  	telemetry.Inc(telemetry.GetCounter(
    59  		fmt.Sprintf("%s.%s.%s", iamRoles, "drop", typ)))
    60  }
    61  
    62  // IncIAMGrantCounter is to be incremented every time a GRANT ROLE happens.
    63  func IncIAMGrantCounter(withAdmin bool) {
    64  	var s string
    65  	if withAdmin {
    66  		s = fmt.Sprintf("%s.%s.with_admin", iamRoles, "grant")
    67  	} else {
    68  		s = fmt.Sprintf("%s.%s", iamRoles, "grant")
    69  	}
    70  	telemetry.Inc(telemetry.GetCounter(s))
    71  }
    72  
    73  // IncIAMRevokeCounter is to be incremented every time a REVOKE ROLE happens.
    74  func IncIAMRevokeCounter(withAdmin bool) {
    75  	var s string
    76  	if withAdmin {
    77  		s = fmt.Sprintf("%s.%s.with_admin", iamRoles, "revoke")
    78  	} else {
    79  		s = fmt.Sprintf("%s.%s", iamRoles, "revoke")
    80  	}
    81  	telemetry.Inc(telemetry.GetCounter(s))
    82  }
    83  
    84  // IncIAMGrantPrivilegesCounter is to be incremented every time a GRANT <privileges> happens.
    85  func IncIAMGrantPrivilegesCounter(on string) {
    86  	telemetry.Inc(telemetry.GetCounter(
    87  		fmt.Sprintf("%s.%s.%s.%s", iamRoles, "grant", "privileges", on)))
    88  }
    89  
    90  // IncIAMRevokePrivilegesCounter is to be incremented every time a REVOKE <privileges> happens.
    91  func IncIAMRevokePrivilegesCounter(on string) {
    92  	telemetry.Inc(telemetry.GetCounter(
    93  		fmt.Sprintf("%s.%s.%s.%s", iamRoles, "revoke", "privileges", on)))
    94  }
    95  
    96  // TurnConnAuditingOnUseCounter counts how many time connection audit logs were enabled.
    97  var TurnConnAuditingOnUseCounter = telemetry.GetCounterOnce("auditing.connection.enabled")
    98  
    99  // TurnConnAuditingOffUseCounter counts how many time connection audit logs were disabled.
   100  var TurnConnAuditingOffUseCounter = telemetry.GetCounterOnce("auditing.connection.disabled")
   101  
   102  // TurnAuthAuditingOnUseCounter counts how many time connection audit logs were enabled.
   103  var TurnAuthAuditingOnUseCounter = telemetry.GetCounterOnce("auditing.authentication.enabled")
   104  
   105  // TurnAuthAuditingOffUseCounter counts how many time connection audit logs were disabled.
   106  var TurnAuthAuditingOffUseCounter = telemetry.GetCounterOnce("auditing.authentication.disabled")