Skip to content

Commit 5bb5e00

Browse files
craig[bot]kyle-a-wong
andcommitted
Merge #148330
148330: Revert "sql,log: add new txn_timestamp filed to CommonSqlEventDetails" r=yuzefovich a=kyle-a-wong This reverts commit d81d31a. --- This reverts #148007 which added a new field to sql structured events. This changed caused some tests to fail (#148307, #148313) because they output from the datadriven tests is not deterministic causing flakes. Fixes: #148307 Fixes: #148313 Epic: None Release note: None Co-authored-by: Kyle Wong <[email protected]>
2 parents f48b343 + faf33dd commit 5bb5e00

File tree

12 files changed

+135
-271
lines changed

12 files changed

+135
-271
lines changed

docs/generated/eventlog.md

Lines changed: 0 additions & 82 deletions
Large diffs are not rendered by default.

pkg/ccl/logictestccl/testdata/logic_test/multi_region

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ ALTER DATABASE drop_region_db DROP REGION IF EXISTS "us-east-1"
10971097

10981098
# Ensure that events are generated for dropping the region
10991099
query IT
1100-
SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' - 'TxnTimestamp'
1100+
SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID'
11011101
FROM system.eventlog
11021102
WHERE "eventType" = 'alter_database_drop_region'
11031103
----

pkg/sql/event_log.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ func logEventInternalForSQLStatements(
247247
) error {
248248
// Inject the common fields into the payload provided by the caller.
249249
injectCommonFields := func(event logpb.EventPayload) error {
250-
event.CommonDetails().Timestamp = timeutil.Now().UnixNano()
251-
250+
if txn == nil {
251+
// No txn is set (e.g. for COPY or BEGIN), so use now instead.
252+
event.CommonDetails().Timestamp = timeutil.Now().UnixNano()
253+
} else {
254+
event.CommonDetails().Timestamp = txn.KV().ReadTimestamp().WallTime
255+
}
252256
sqlCommon, ok := event.(eventpb.EventWithCommonSQLPayload)
253257
if !ok {
254258
return errors.AssertionFailedf("unknown event type: %T", event)
@@ -274,10 +278,6 @@ func logEventInternalForSQLStatements(
274278
// Overwrite with the common details.
275279
*m = commonSQLEventDetails
276280

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

pkg/sql/event_log_test.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb"
2525
"github.com/cockroachdb/cockroach/pkg/util/log/logconfig"
2626
"github.com/cockroachdb/cockroach/pkg/util/log/logpb"
27-
"github.com/cockroachdb/cockroach/pkg/util/log/logtestutils"
2827
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
2928
"github.com/cockroachdb/errors"
3029
"github.com/cockroachdb/redact"
@@ -116,46 +115,6 @@ func TestStructuredEventLogging(t *testing.T) {
116115
}
117116
}
118117

119-
func TestStructuredEventLogging_txnTimestamp(t *testing.T) {
120-
defer leaktest.AfterTest(t)()
121-
defer log.Scope(t).Close(t)
122-
123-
ctx := context.Background()
124-
appLogsSpy := logtestutils.NewStructuredLogSpy(
125-
t,
126-
[]logpb.Channel{logpb.Channel_SQL_SCHEMA},
127-
[]string{"create_table"},
128-
func(entry logpb.Entry) (eventpb.CreateTable, error) {
129-
var cte eventpb.CreateTable
130-
if err := json.Unmarshal([]byte(entry.Message[entry.StructuredStart:entry.StructuredEnd]), &cte); err != nil {
131-
return cte, err
132-
}
133-
return cte, nil
134-
},
135-
)
136-
137-
cleanup := log.InterceptWith(ctx, appLogsSpy)
138-
defer cleanup()
139-
140-
s, conn, _ := serverutils.StartServer(t, base.TestServerArgs{})
141-
defer s.Stopper().Stop(ctx)
142-
143-
runner := sqlutils.MakeSQLRunner(conn)
144-
runner.Exec(t, "CREATE TABLE test (id INT PRIMARY KEY)")
145-
runner.Exec(t, "BEGIN")
146-
runner.Exec(t, "SET autocommit_before_ddl = false")
147-
runner.Exec(t, "CREATE TABLE test1 (id INT PRIMARY KEY)")
148-
runner.Exec(t, "CREATE TABLE test2 (id INT PRIMARY KEY)")
149-
runner.Exec(t, "COMMIT")
150-
151-
createTables := appLogsSpy.GetLogs(logpb.Channel_SQL_SCHEMA)
152-
require.Len(t, createTables, 3)
153-
// Not created in the same transaction, so transaction timestamps are different
154-
require.NotEqual(t, createTables[0].TxnTimestamp, createTables[1].TxnTimestamp)
155-
// Created in the same transaction, so transaction timestamps are the same
156-
require.Equal(t, createTables[1].TxnTimestamp, createTables[2].TxnTimestamp)
157-
}
158-
159118
var execLogRe = regexp.MustCompile(`event_log.go`)
160119

161120
// Test the SQL_PERF and SQL_INTERNAL_PERF logging channels.
@@ -181,7 +140,7 @@ func TestPerfLogging(t *testing.T) {
181140
{
182141
query: `SELECT pg_sleep(0.256)`,
183142
errRe: ``,
184-
logRe: `"EventType":"slow_query","Statement":"SELECT pg_sleep\(‹0.256›\)","Tag":"SELECT","User":"root","TxnTimestamp":.*,"ExecMode":"exec","NumRows":1`,
143+
logRe: `"EventType":"slow_query","Statement":"SELECT pg_sleep\(‹0.256›\)","Tag":"SELECT","User":"root","ExecMode":"exec","NumRows":1`,
185144
logExpected: true,
186145
channel: channel.SQL_PERF,
187146
},
@@ -202,7 +161,7 @@ func TestPerfLogging(t *testing.T) {
202161
{
203162
query: `INSERT INTO t VALUES (2, pg_sleep(0.256), 'x')`,
204163
errRe: ``,
205-
logRe: `"EventType":"slow_query","Statement":"INSERT INTO .*\.t VALUES \(‹2›, pg_sleep\(‹0.256›\), ‹'x'›\)","Tag":"INSERT","User":"root","TxnTimestamp":.*,"ExecMode":"exec","NumRows":1`,
164+
logRe: `"EventType":"slow_query","Statement":"INSERT INTO .*\.t VALUES \(‹2›, pg_sleep\(‹0.256›\), ‹'x'›\)","Tag":"INSERT","User":"root","ExecMode":"exec","NumRows":1`,
206165
logExpected: true,
207166
channel: channel.SQL_PERF,
208167
},
@@ -216,7 +175,7 @@ func TestPerfLogging(t *testing.T) {
216175
{
217176
query: `INSERT INTO t VALUES (4, pg_sleep(0.256), repeat('x', 1024))`,
218177
errRe: ``,
219-
logRe: `"EventType":"slow_query","Statement":"INSERT INTO .*\.t VALUES \(‹4›, pg_sleep\(‹0.256›\), repeat\(‹'x'›, ‹1024›\)\)","Tag":"INSERT","User":"root","TxnTimestamp":.*,"ExecMode":"exec","NumRows":1`,
178+
logRe: `"EventType":"slow_query","Statement":"INSERT INTO .*\.t VALUES \(‹4›, pg_sleep\(‹0.256›\), repeat\(‹'x'›, ‹1024›\)\)","Tag":"INSERT","User":"root","ExecMode":"exec","NumRows":1`,
220179
logExpected: true,
221180
channel: channel.SQL_PERF,
222181
},
@@ -230,7 +189,7 @@ func TestPerfLogging(t *testing.T) {
230189
{
231190
query: `SELECT *, pg_sleep(0.064) FROM t`,
232191
errRe: ``,
233-
logRe: `"EventType":"slow_query","Statement":"SELECT \*, pg_sleep\(‹0.064›\) FROM .*\.t","Tag":"SELECT","User":"root","TxnTimestamp":.*,"ExecMode":"exec","NumRows":4`,
192+
logRe: `"EventType":"slow_query","Statement":"SELECT \*, pg_sleep\(‹0.064›\) FROM .*\.t","Tag":"SELECT","User":"root","ExecMode":"exec","NumRows":4`,
234193
logExpected: true,
235194
channel: channel.SQL_PERF,
236195
},

pkg/sql/logictest/testdata/logic_test/distsql_event_log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CREATE STATISTICS __auto__ FROM a
2525
# Check explicitly for table id 106. System tables could trigger autostats
2626
# collections at any time.
2727
query IT
28-
SELECT "reportingID", "info"::JSONB - 'Timestamp' - 'DescriptorID' - 'TxnTimestamp' - 'ApplicationName'
28+
SELECT "reportingID", "info"::JSONB - 'Timestamp' - 'DescriptorID' - 'ApplicationName'
2929
FROM system.eventlog
3030
WHERE "eventType" = 'create_statistics' AND ("info"::JSONB ->> 'DescriptorID')::INT = 106
3131
ORDER BY "timestamp", info

0 commit comments

Comments
 (0)