Skip to content

Commit 89ed383

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 1d9b563 commit 89ed383

File tree

8 files changed

+166
-136
lines changed

8 files changed

+166
-136
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/ccl/telemetryccl/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ go_test(
2020
"//pkg/security/securityassets",
2121
"//pkg/security/securitytest",
2222
"//pkg/server",
23+
"//pkg/settings",
2324
"//pkg/sql",
2425
"//pkg/sql/sem/tree",
2526
"//pkg/sql/sqltestutils",

pkg/ccl/telemetryccl/telemetry_logging_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/http"
1414
"net/http/httptest"
1515
"regexp"
16+
"slices"
1617
"strings"
1718
"testing"
1819

@@ -21,6 +22,7 @@ import (
2122
"github.com/cockroachdb/cockroach/pkg/cloud/nodelocal"
2223
"github.com/cockroachdb/cockroach/pkg/jobs"
2324
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
25+
"github.com/cockroachdb/cockroach/pkg/settings"
2426
"github.com/cockroachdb/cockroach/pkg/sql"
2527
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2628
"github.com/cockroachdb/cockroach/pkg/testutils"
@@ -155,20 +157,29 @@ type expectedSampleQueryEvent struct {
155157
}
156158

157159
type telemetrySpy struct {
158-
t *testing.T
160+
t *testing.T
161+
sv *settings.Values
159162

160163
sampledQueries []eventpb.SampledQuery
161164
sampledQueriesRaw []logpb.Entry
162165
recoveryEvents []eventpb.RecoveryEvent
163166
}
164167

168+
func (l *telemetrySpy) channelsToIntercept() []log.Channel {
169+
if log.ShouldMigrateEvent(l.sv) {
170+
return []log.Channel{logpb.Channel_TELEMETRY, logpb.Channel_SQL_EXEC}
171+
}
172+
173+
return []log.Channel{logpb.Channel_TELEMETRY}
174+
}
175+
165176
func (l *telemetrySpy) Intercept(entry []byte) {
166177
var rawLog logpb.Entry
167178
if err := json.Unmarshal(entry, &rawLog); err != nil {
168179
l.t.Errorf("failed unmarshaling %s: %s", entry, err)
169180
}
170181

171-
if rawLog.Channel != logpb.Channel_TELEMETRY {
182+
if !slices.Contains(l.channelsToIntercept(), rawLog.Channel) {
172183
return
173184
}
174185

@@ -204,12 +215,6 @@ func TestBulkJobTelemetryLogging(t *testing.T) {
204215

205216
ctx := context.Background()
206217

207-
spy := &telemetrySpy{
208-
t: t,
209-
}
210-
cleanup := log.InterceptWith(ctx, spy)
211-
defer cleanup()
212-
213218
st := logtestutils.StubTime{}
214219
sqm := logtestutils.StubQueryStats{}
215220
sts := logtestutils.StubTracingStatus{}
@@ -229,6 +234,15 @@ func TestBulkJobTelemetryLogging(t *testing.T) {
229234
ExternalIODir: dir,
230235
},
231236
})
237+
238+
spy := &telemetrySpy{
239+
t: t,
240+
sv: &testCluster.Server(0).ClusterSettings().SV,
241+
}
242+
243+
cleanup := log.InterceptWith(ctx, spy)
244+
defer cleanup()
245+
232246
sqlDB := testCluster.ServerConn(0)
233247
defer func() {
234248
testCluster.Stopper().Stop(context.Background())

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.ShouldMigrateEvent(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.ShouldMigrateEvent(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)