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

     1  // Copyright 2019 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  // SerialColumnNormalizationCounter is to be incremented every time
    20  // a SERIAL type is processed in a column definition.
    21  // It includes the normalization type, so we can
    22  // estimate usage of the various normalization strategies.
    23  func SerialColumnNormalizationCounter(inputType, normType string) telemetry.Counter {
    24  	return telemetry.GetCounter(fmt.Sprintf("sql.schema.serial.%s.%s", normType, inputType))
    25  }
    26  
    27  // SchemaNewTypeCounter is to be incremented every time a new data type
    28  // is used in a schema, i.e. by CREATE TABLE or ALTER TABLE ADD COLUMN.
    29  func SchemaNewTypeCounter(t string) telemetry.Counter {
    30  	return telemetry.GetCounter("sql.schema.new_column_type." + t)
    31  }
    32  
    33  var (
    34  	// CreateInterleavedTableCounter is to be incremented every time an
    35  	// interleaved table is being created.
    36  	CreateInterleavedTableCounter = telemetry.GetCounterOnce("sql.schema.create_interleaved_table")
    37  
    38  	// CreateTempTableCounter is to be incremented every time a TEMP TABLE
    39  	// has been created.
    40  	CreateTempTableCounter = telemetry.GetCounterOnce("sql.schema.create_temp_table")
    41  
    42  	// CreateTempSequenceCounter is to be incremented every time a TEMP SEQUENCE
    43  	// has been created.
    44  	CreateTempSequenceCounter = telemetry.GetCounterOnce("sql.schema.create_temp_sequence")
    45  
    46  	// CreateTempViewCounter is to be incremented every time a TEMP VIEW
    47  	// has been created.
    48  	CreateTempViewCounter = telemetry.GetCounterOnce("sql.schema.create_temp_view")
    49  )
    50  
    51  var (
    52  	// HashShardedIndexCounter is to be incremented every time a hash
    53  	// sharded index is created.
    54  	HashShardedIndexCounter = telemetry.GetCounterOnce("sql.schema.hash_sharded_index")
    55  
    56  	// InvertedIndexCounter is to be incremented every time an inverted
    57  	// index is created.
    58  	InvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.inverted_index")
    59  
    60  	// GeographyInvertedIndexCounter is to be incremented every time a
    61  	// geography inverted index is created. These are a subset of the
    62  	// indexes counted in InvertedIndexCounter.
    63  	GeographyInvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.geography_inverted_index")
    64  
    65  	// GeometryInvertedIndexCounter is to be incremented every time a
    66  	// geometry inverted index is created. These are a subset of the
    67  	// indexes counted in InvertedIndexCounter.
    68  	GeometryInvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.geometry_inverted_index")
    69  )
    70  
    71  var (
    72  	// TempObjectCleanerDeletionCounter is to be incremented every time a temporary schema
    73  	// has been deleted by the temporary object cleaner.
    74  	TempObjectCleanerDeletionCounter = telemetry.GetCounterOnce("sql.schema.temp_object_cleaner.num_cleaned")
    75  )
    76  
    77  // SchemaNewColumnTypeQualificationCounter is to be incremented every time
    78  // a new qualification is used for a newly created column.
    79  func SchemaNewColumnTypeQualificationCounter(qual string) telemetry.Counter {
    80  	return telemetry.GetCounter("sql.schema.new_column.qualification." + qual)
    81  }
    82  
    83  // SchemaChangeCreateCounter is to be incremented every time a CREATE
    84  // schema change was made.
    85  func SchemaChangeCreateCounter(typ string) telemetry.Counter {
    86  	return telemetry.GetCounter("sql.schema.create_" + typ)
    87  }
    88  
    89  // SchemaChangeDropCounter is to be incremented every time a DROP
    90  // schema change was made.
    91  func SchemaChangeDropCounter(typ string) telemetry.Counter {
    92  	return telemetry.GetCounter("sql.schema.drop_" + typ)
    93  }
    94  
    95  // SchemaSetZoneConfigCounter is to be incremented every time a ZoneConfig
    96  // argument is parsed.
    97  func SchemaSetZoneConfigCounter(configName, keyChange string) telemetry.Counter {
    98  	return telemetry.GetCounter(
    99  		fmt.Sprintf("sql.schema.zone_config.%s.%s", configName, keyChange),
   100  	)
   101  }
   102  
   103  // SchemaChangeAlterCounter behaves the same as SchemaChangeAlterCounterWithExtra
   104  // but with no extra metadata.
   105  func SchemaChangeAlterCounter(typ string) telemetry.Counter {
   106  	return SchemaChangeAlterCounterWithExtra(typ, "")
   107  }
   108  
   109  // SchemaChangeAlterCounterWithExtra is to be incremented for ALTER schema changes.
   110  // `typ` is for declaring which type was altered, e.g. TABLE, DATABASE.
   111  // `extra` can be used for extra trailing useful metadata.
   112  func SchemaChangeAlterCounterWithExtra(typ string, extra string) telemetry.Counter {
   113  	if extra != "" {
   114  		extra = "." + extra
   115  	}
   116  	return telemetry.GetCounter(fmt.Sprintf("sql.schema.alter_%s%s", typ, extra))
   117  }
   118  
   119  // SchemaSetAuditModeCounter is to be incremented every time an audit mode is set.
   120  func SchemaSetAuditModeCounter(mode string) telemetry.Counter {
   121  	return telemetry.GetCounter("sql.schema.set_audit_mode." + mode)
   122  }
   123  
   124  // SchemaJobControlCounter is to be incremented every time a job control action
   125  // is taken.
   126  func SchemaJobControlCounter(desiredStatus string) telemetry.Counter {
   127  	return telemetry.GetCounter("sql.schema.job.control." + desiredStatus)
   128  }
   129  
   130  // SchemaChangeInExplicitTxnCounter is to be incremented every time a schema change
   131  // is scheduled using an explicit transaction.
   132  var SchemaChangeInExplicitTxnCounter = telemetry.GetCounterOnce("sql.schema.change_in_explicit_txn")
   133  
   134  // SecondaryIndexColumnFamiliesCounter is a counter that is incremented every time
   135  // a secondary index that is separated into different column families is created.
   136  var SecondaryIndexColumnFamiliesCounter = telemetry.GetCounterOnce("sql.schema.secondary_index_column_families")