Skip to content

Commit a80a35f

Browse files
committed
sql: prep migration for sampled_query and sampled_transaction events
In v26.1, sampled_query and sampled_transaction events will be moved from the TELEMETRY 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 Part of: CRDB-53412 Release note (ops change): sampled_query and sampled_transaction 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.
1 parent aca7ce4 commit a80a35f

File tree

6 files changed

+144
-128
lines changed

6 files changed

+144
-128
lines changed

docs/generated/eventlog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,11 @@ Fields in this struct should be updated in sync with apps_stats.proto.
33643364
An event of type `sampled_query` is the SQL query event logged to the telemetry channel. It
33653365
contains common SQL event/execution details.
33663366

3367+
Note: in version 26.1, these events will be moved to the `SQL_EXEC` channel.
3368+
To test compatability before this, set the cluster setting
3369+
`log.channel_compatibility_mode.enabled` to false. This will send the
3370+
events to `SQL_EXEC` instead of `TELEMETRY`.
3371+
33673372

33683373
| Field | Description | Sensitive |
33693374
|--|--|--|
@@ -3472,6 +3477,11 @@ contains common SQL event/execution details.
34723477

34733478
An event of type `sampled_transaction` is the event logged to telemetry at the end of transaction execution.
34743479

3480+
Note: in version 26.1, these events will be moved to the `SQL_EXEC` channel.
3481+
To test compatability before this, set the cluster setting
3482+
`log.channel_compatibility_mode.enabled` to false. This will send the
3483+
events to `SQL_EXEC` instead of `TELEMETRY`.
3484+
34753485

34763486
| Field | Description | Sensitive |
34773487
|--|--|--|

pkg/sql/exec_log.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func (p *planner) maybeLogStatementInternal(
358358

359359
*sampledQuery = eventpb.SampledQuery{
360360
CommonSQLExecDetails: execDetails,
361+
CommonSQLEventDetails: p.getCommonSQLEventDetails(),
361362
SkippedQueries: skippedQueries,
362363
CostEstimate: p.curPlan.instrumentation.costEstimate,
363364
Distribution: p.curPlan.instrumentation.distribution.String(),
@@ -436,7 +437,11 @@ func (p *planner) maybeLogStatementInternal(
436437
SchemaChangerMode: p.curPlan.instrumentation.schemaChangerMode.String(),
437438
}
438439

439-
p.logEventsOnlyExternally(ctx, sampledQuery)
440+
migrator := log.NewStructuredEventMigrator(func() bool {
441+
return !log.ChannelCompatibilityModeEnabled.Get(p.ExecCfg().SV())
442+
}, logpb.Channel_SQL_EXEC)
443+
444+
migrator.StructuredEvent(ctx, severity.INFO, sampledQuery)
440445
}
441446
}
442447

@@ -521,7 +526,11 @@ func (p *planner) logTransaction(
521526
}
522527
}
523528

524-
log.StructuredEvent(ctx, severity.INFO, sampledTxn)
529+
migrator := log.NewStructuredEventMigrator(func() bool {
530+
return !log.ChannelCompatibilityModeEnabled.Get(p.ExecCfg().SV())
531+
}, logpb.Channel_SQL_EXEC)
532+
533+
migrator.StructuredEvent(ctx, severity.INFO, sampledTxn)
525534
}
526535

527536
func (p *planner) logEventsOnlyExternally(ctx context.Context, entries ...logpb.EventPayload) {

pkg/sql/telemetry_datadriven_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ func TestTelemetryLoggingDataDriven(t *testing.T) {
6060

6161
sc := log.Scope(t)
6262
defer sc.Close(t)
63-
6463
appName := "telemetry-logging-datadriven"
6564
ignoredAppname := "telemetry-datadriven-ignored-appname"
6665
ctx := context.Background()
6766
stmtSpy := logtestutils.NewStructuredLogSpy(
6867
t,
69-
[]logpb.Channel{logpb.Channel_TELEMETRY},
68+
[]logpb.Channel{logpb.Channel_TELEMETRY, logpb.Channel_SQL_EXEC},
7069
[]string{"sampled_query"},
7170
logtestutils.FormatEntryAsJSON,
7271
func(_ logpb.Entry, logStr string) bool {
@@ -79,7 +78,7 @@ func TestTelemetryLoggingDataDriven(t *testing.T) {
7978

8079
txnsSpy := logtestutils.NewStructuredLogSpy(
8180
t,
82-
[]logpb.Channel{logpb.Channel_TELEMETRY},
81+
[]logpb.Channel{logpb.Channel_TELEMETRY, logpb.Channel_SQL_EXEC},
8382
[]string{"sampled_transaction"},
8483
logtestutils.FormatEntryAsJSON,
8584
func(_ logpb.Entry, logStr string) bool {
@@ -209,13 +208,13 @@ func TestTelemetryLoggingDataDriven(t *testing.T) {
209208
}
210209

211210
newStmtLogCount := stmtSpy.Count()
212-
sb.WriteString(strings.Join(stmtSpy.GetLastNLogs(logpb.Channel_TELEMETRY, newStmtLogCount-stmtLogCount), "\n"))
211+
sb.WriteString(strings.Join(stmtSpy.GetLastNLogs(getSampleQueryLoggingChannel(&s.ClusterSettings().SV), newStmtLogCount-stmtLogCount), "\n"))
213212
if newStmtLogCount > stmtLogCount {
214213
sb.WriteString("\n")
215214
}
216215

217216
newTxnLogCount := txnsSpy.Count()
218-
sb.WriteString(strings.Join(txnsSpy.GetLastNLogs(logpb.Channel_TELEMETRY, newTxnLogCount-txnLogCount), "\n"))
217+
sb.WriteString(strings.Join(txnsSpy.GetLastNLogs(getSampleQueryLoggingChannel(&s.ClusterSettings().SV), newTxnLogCount-txnLogCount), "\n"))
219218
return sb.String()
220219
case "reset-last-sampled":
221220
telemetryLogging.resetLastSampledTime()

0 commit comments

Comments
 (0)