-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
schema.go
170 lines (140 loc) · 7.05 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2019 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 sqltelemetry
import (
"fmt"
"strings"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
)
// SerialColumnNormalizationCounter is to be incremented every time
// a SERIAL type is processed in a column definition.
// It includes the normalization type, so we can
// estimate usage of the various normalization strategies.
func SerialColumnNormalizationCounter(inputType, normType string) telemetry.Counter {
return telemetry.GetCounter(fmt.Sprintf("sql.schema.serial.%s.%s", normType, inputType))
}
// SchemaNewTypeCounter is to be incremented every time a new data type
// is used in a schema, i.e. by CREATE TABLE or ALTER TABLE ADD COLUMN.
func SchemaNewTypeCounter(t string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.new_column_type." + t)
}
var (
// CreateInterleavedTableCounter is to be incremented every time an
// interleaved table is being created.
CreateInterleavedTableCounter = telemetry.GetCounterOnce("sql.schema.create_interleaved_table")
// CreateTempTableCounter is to be incremented every time a TEMP TABLE
// has been created.
CreateTempTableCounter = telemetry.GetCounterOnce("sql.schema.create_temp_table")
// CreateTempSequenceCounter is to be incremented every time a TEMP SEQUENCE
// has been created.
CreateTempSequenceCounter = telemetry.GetCounterOnce("sql.schema.create_temp_sequence")
// CreateTempViewCounter is to be incremented every time a TEMP VIEW
// has been created.
CreateTempViewCounter = telemetry.GetCounterOnce("sql.schema.create_temp_view")
)
var (
// HashShardedIndexCounter is to be incremented every time a hash
// sharded index is created.
HashShardedIndexCounter = telemetry.GetCounterOnce("sql.schema.hash_sharded_index")
// InvertedIndexCounter is to be incremented every time an inverted
// index is created.
InvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.inverted_index")
// GeographyInvertedIndexCounter is to be incremented every time a
// geography inverted index is created. These are a subset of the
// indexes counted in InvertedIndexCounter.
GeographyInvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.geography_inverted_index")
// GeometryInvertedIndexCounter is to be incremented every time a
// geometry inverted index is created. These are a subset of the
// indexes counted in InvertedIndexCounter.
GeometryInvertedIndexCounter = telemetry.GetCounterOnce("sql.schema.geometry_inverted_index")
// PartialIndexCounter is to be incremented every time a partial index is
// created.
PartialIndexCounter = telemetry.GetCounterOnce("sql.schema.partial_index")
)
var (
// TempObjectCleanerDeletionCounter is to be incremented every time a temporary schema
// has been deleted by the temporary object cleaner.
TempObjectCleanerDeletionCounter = telemetry.GetCounterOnce("sql.schema.temp_object_cleaner.num_cleaned")
)
// SchemaNewColumnTypeQualificationCounter is to be incremented every time
// a new qualification is used for a newly created column.
func SchemaNewColumnTypeQualificationCounter(qual string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.new_column.qualification." + qual)
}
// SchemaChangeCreateCounter is to be incremented every time a CREATE
// schema change was made.
func SchemaChangeCreateCounter(typ string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.create_" + typ)
}
// SchemaChangeDropCounter is to be incremented every time a DROP
// schema change was made.
func SchemaChangeDropCounter(typ string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.drop_" + typ)
}
// SchemaSetZoneConfigCounter is to be incremented every time a ZoneConfig
// argument is parsed.
func SchemaSetZoneConfigCounter(configName, keyChange string) telemetry.Counter {
return telemetry.GetCounter(
fmt.Sprintf("sql.schema.zone_config.%s.%s", configName, keyChange),
)
}
// SchemaChangeAlterCounter behaves the same as SchemaChangeAlterCounterWithExtra
// but with no extra metadata.
func SchemaChangeAlterCounter(typ string) telemetry.Counter {
return SchemaChangeAlterCounterWithExtra(typ, "")
}
// SchemaChangeAlterCounterWithExtra is to be incremented for ALTER schema changes.
// `typ` is for declaring which type was altered, e.g. TABLE, DATABASE.
// `extra` can be used for extra trailing useful metadata.
func SchemaChangeAlterCounterWithExtra(typ string, extra string) telemetry.Counter {
if extra != "" {
extra = "." + extra
}
return telemetry.GetCounter(fmt.Sprintf("sql.schema.alter_%s%s", typ, extra))
}
// SchemaSetAuditModeCounter is to be incremented every time an audit mode is set.
func SchemaSetAuditModeCounter(mode string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.set_audit_mode." + mode)
}
// SchemaJobControlCounter is to be incremented every time a job control action
// is taken.
func SchemaJobControlCounter(desiredStatus string) telemetry.Counter {
return telemetry.GetCounter("sql.schema.job.control." + desiredStatus)
}
// SchemaChangeInExplicitTxnCounter is to be incremented every time a schema change
// is scheduled using an explicit transaction.
var SchemaChangeInExplicitTxnCounter = telemetry.GetCounterOnce("sql.schema.change_in_explicit_txn")
// SecondaryIndexColumnFamiliesCounter is a counter that is incremented every time
// a secondary index that is separated into different column families is created.
var SecondaryIndexColumnFamiliesCounter = telemetry.GetCounterOnce("sql.schema.secondary_index_column_families")
// CreateUnloggedTableCounter is a counter that is incremented every time an unlogged
// table is created.
var CreateUnloggedTableCounter = telemetry.GetCounterOnce("sql.schema.create_unlogged_table")
// SchemaRefreshMaterializedView is to be incremented every time a materialized
// view is refreshed.
var SchemaRefreshMaterializedView = telemetry.GetCounterOnce("sql.schema.refresh_materialized_view")
// SchemaJobSuccessCounter gets the successful job completion counter
// for a given job type.
func SchemaJobSuccessCounter(jobName string) telemetry.Counter {
jobName = strings.ToLower(strings.Replace(jobName, " ", "_", -1))
return telemetry.GetCounter(fmt.Sprintf("sql.schema.job.%s.successful", jobName))
}
// SchemaJobFailedCounter gets the failed job completion counter
// for a given job type.
func SchemaJobFailedCounter(jobName string) telemetry.Counter {
jobName = strings.ToLower(strings.Replace(jobName, " ", "_", -1))
return telemetry.GetCounter(fmt.Sprintf("sql.schema.job.%s.failed", jobName))
}
// SchemaJobCanceledCounter gets the canceled job completion counter
// for a given job type.
func SchemaJobCanceledCounter(jobName string) telemetry.Counter {
jobName = strings.ToLower(strings.Replace(jobName, " ", "_", -1))
return telemetry.GetCounter(fmt.Sprintf("sql.schema.job.%s.canceled", jobName))
}