Skip to content

Commit 3ad5418

Browse files
craig[bot]kyle-a-wong
andcommitted
Merge #151827
151827: sql: prep migration of sql_perf logging channels r=kyle-a-wong a=kyle-a-wong In v26.1, sql perf events will be moved from the SQL_PERF and SQL_INTERNAL_PERF logging channel to the SQL_EXEC logging channel. This commit gates this migration under the cluster setting: `log.channel_compatibility_mode.enabled` and will log these events to the SQL_EXEC channel if this setting is set to false. Users can set this setting to false in their clusters to validate, test, and identify potential downstream impacts to their logging setups and pipelines. Epic: [CRDB-53410](https://cockroachlabs.atlassian.net/browse/CRDB-53410) Part of: [CRDB-53412](https://cockroachlabs.atlassian.net/browse/CRDB-53412) Release note (ops change): sql perf events will be moved to the SQL_EXEC channel in 26.1. In order to test the impact of these changes, users can set the setting: `log.channel_compatibility_mode.enabled` to false. Note that this will cause these logs to start logging in the SQL_EXEC channel so this shouldn't be tested in a production environment. ---- Note: This is a stacked PR, only the last commit needs to be reviewed Co-authored-by: Kyle Wong <[email protected]>
2 parents 2eb84bc + 224abd1 commit 3ad5418

File tree

7 files changed

+116
-73
lines changed

7 files changed

+116
-73
lines changed

docs/generated/eventlog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,6 +2771,11 @@ Note: these events are not written to `system.eventlog`, even
27712771
when the cluster setting `system.eventlog.enabled` is set. They
27722772
are only emitted via external logging.
27732773

2774+
In version 26.1, these events will be moved to the `SQL_EXEC` channel.
2775+
To test compatability before this, set the cluster setting
2776+
`log.channel_compatibility_mode.enabled` to false. This will send the
2777+
events to `SQL_EXEC` instead of `SQL_PERF`.
2778+
27742779
Events in this category are logged to the `SQL_PERF` channel.
27752780

27762781

@@ -2901,6 +2906,11 @@ Note: these events are not written to `system.eventlog`, even
29012906
when the cluster setting `system.eventlog.enabled` is set. They
29022907
are only emitted via external logging.
29032908

2909+
In version 26.1, these events will be moved to the `SQL_EXEC` channel.
2910+
To test compatability before this, set the cluster setting
2911+
`log.channel_compatibility_mode.enabled` to false. This will send the
2912+
events to `SQL_EXEC` instead of `SQL_INTERNAL_PERF`.
2913+
29042914
Events in this category are logged to the `SQL_INTERNAL_PERF` channel.
29052915

29062916

pkg/sql/conn_executor_exec.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,10 @@ func (ex *connExecutor) handleTxnRowsGuardrails(
33453345
CommonTxnRowsLimitDetails: commonTxnRowsLimitDetails,
33463346
}
33473347
}
3348-
log.StructuredEvent(ctx, severity.INFO, event)
3348+
migrator := log.NewStructuredEventMigrator(func() bool {
3349+
return log.ShouldMigrateEvent(ex.planner.ExecCfg().SV())
3350+
}, logpb.Channel_SQL_EXEC)
3351+
migrator.StructuredEvent(ctx, severity.INFO, event)
33493352
logCounter.Inc(1)
33503353
}
33513354
}

pkg/sql/event_log.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ func (p *planner) getCommonSQLEventDetails() eventpb.CommonSQLEventDetails {
165165
User: p.SessionData().SessionUser().Normalized(),
166166
ApplicationName: p.SessionData().ApplicationName,
167167
}
168+
txn := p.InternalSQLTxn()
169+
if txn != nil {
170+
commonSQLEventDetails.TxnReadTimestamp = txn.KV().ReadTimestamp().WallTime
171+
}
172+
168173
if pls := p.extendedEvalCtx.Context.Placeholders.Values; len(pls) > 0 {
169174
commonSQLEventDetails.PlaceholderValues = make([]string, len(pls))
170175
for idx, val := range pls {
@@ -274,10 +279,6 @@ func logEventInternalForSQLStatements(
274279
// Overwrite with the common details.
275280
*m = commonSQLEventDetails
276281

277-
if txn != nil {
278-
m.TxnReadTimestamp = txn.KV().ReadTimestamp().WallTime
279-
}
280-
281282
// If the common details didn't have a descriptor ID, keep the
282283
// one that was in the event already.
283284
if m.DescriptorID == 0 {

pkg/sql/event_log_test.go

Lines changed: 59 additions & 64 deletions
Large diffs are not rendered by default.

pkg/sql/exec_log.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,27 @@ func (p *planner) maybeLogStatementInternal(
251251
(slowLogFullTableScans && (execDetails.FullTableScan || execDetails.FullIndexScan)) ||
252252
// Is the query actually slow?
253253
queryDuration > slowLogThreshold) {
254+
commonSQLEventDetails := p.getCommonSQLEventDetails()
255+
migrator := log.NewStructuredEventMigrator(func() bool {
256+
return !log.ChannelCompatibilityModeEnabled.Get(p.ExecCfg().SV())
257+
}, logpb.Channel_SQL_EXEC)
254258
switch {
255259
case execType == executorTypeExec:
256260
// Non-internal queries are always logged to the slow query log.
257-
p.logEventsOnlyExternally(ctx, &eventpb.SlowQuery{CommonSQLExecDetails: execDetails})
258-
261+
event := &eventpb.SlowQuery{
262+
CommonSQLEventDetails: commonSQLEventDetails,
263+
CommonSQLExecDetails: execDetails,
264+
}
265+
migrator.StructuredEvent(ctx, severity.INFO, event)
259266
case execType == executorTypeInternal && slowInternalQueryLogEnabled:
260267
// Internal queries that surpass the slow query log threshold should only
261268
// be logged to the slow-internal-only log if the cluster setting dictates.
262-
p.logEventsOnlyExternally(ctx, &eventpb.SlowQueryInternal{CommonSQLExecDetails: execDetails})
269+
event := &eventpb.SlowQueryInternal{
270+
CommonSQLEventDetails: commonSQLEventDetails,
271+
CommonSQLExecDetails: execDetails,
272+
}
273+
migrator.StructuredEvent(ctx, severity.INFO,
274+
event)
263275
}
264276
}
265277

pkg/sql/row/helper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type RowHelper struct {
113113
// Used to check row size.
114114
maxRowSizeLog, maxRowSizeErr uint32
115115
metrics *rowinfra.Metrics
116+
migrateLargeRowLog bool
116117
}
117118

118119
func NewRowHelper(
@@ -134,6 +135,7 @@ func NewRowHelper(
134135
Indexes: indexes,
135136
UniqueWithTombstoneIndexes: uniqueWithTombstoneIndexesSet,
136137
sd: sd,
138+
migrateLargeRowLog: log.ShouldMigrateEvent(sv),
137139
metrics: metrics,
138140
maxRowSizeLog: uint32(maxRowSizeLog.Get(sv)),
139141
maxRowSizeErr: uint32(maxRowSizeErr.Get(sv)),
@@ -473,7 +475,10 @@ func (rh *RowHelper) CheckRowSize(
473475
} else {
474476
event = &eventpb.LargeRow{CommonLargeRowDetails: details}
475477
}
476-
log.StructuredEvent(ctx, severity.INFO, event)
478+
migrator := log.NewStructuredEventMigrator(func() bool {
479+
return rh.migrateLargeRowLog
480+
}, logpb.Channel_SQL_EXEC)
481+
migrator.StructuredEvent(ctx, severity.INFO, event)
477482
}
478483
if shouldErr {
479484
if rh.metrics != nil {

pkg/util/log/eventpb/sql_audit_events.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ message RoleBasedAuditEvent {
8686
string role = 4 [(gogoproto.jsontag) = ",omitempty"];
8787
}
8888

89+
// TODO (#151948): Update channel from SQL_PERF to SQL_EXEC once the
90+
// `log.channel_compatibility_mode.enabled` cluster setting is set to false
91+
// by default and cluster setting is set for removal.
92+
8993
// Category: SQL Slow Query Log
9094
// Channel: SQL_PERF
9195
//
@@ -95,6 +99,10 @@ message RoleBasedAuditEvent {
9599
// when the cluster setting `system.eventlog.enabled` is set. They
96100
// are only emitted via external logging.
97101
//
102+
// In version 26.1, these events will be moved to the `SQL_EXEC` channel.
103+
// To test compatability before this, set the cluster setting
104+
// `log.channel_compatibility_mode.enabled` to false. This will send the
105+
// events to `SQL_EXEC` instead of `SQL_PERF`.
98106

99107
// SlowQuery is recorded when a query triggers the "slow query" condition.
100108
//
@@ -163,6 +171,10 @@ message TxnRowsReadLimit {
163171
CommonTxnRowsLimitDetails info = 3 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "", (gogoproto.embed) = true];
164172
}
165173

174+
// TODO (#151948): Update channel from SQL_INTERNAL_PERF to SQL_EXEC once the
175+
// `log.channel_compatibility_mode.enabled` cluster setting is set to false
176+
// by default and cluster setting is set for removal.
177+
166178
// Category: SQL Slow Query Log (Internal)
167179
// Channel: SQL_INTERNAL_PERF
168180
//
@@ -173,6 +185,11 @@ message TxnRowsReadLimit {
173185
// Note: these events are not written to `system.eventlog`, even
174186
// when the cluster setting `system.eventlog.enabled` is set. They
175187
// are only emitted via external logging.
188+
//
189+
// In version 26.1, these events will be moved to the `SQL_EXEC` channel.
190+
// To test compatability before this, set the cluster setting
191+
// `log.channel_compatibility_mode.enabled` to false. This will send the
192+
// events to `SQL_EXEC` instead of `SQL_INTERNAL_PERF`.
176193

177194
// SlowQueryInternal is recorded when a query triggers the "slow query" condition,
178195
// and the cluster setting `sql.log.slow_query.internal_queries.enabled` is

0 commit comments

Comments
 (0)