@@ -53,6 +53,7 @@ func TestRegistry(t *testing.T) {
53
53
},
54
54
stmts : []* sqlstats.RecordedStmtStats {
55
55
{
56
+ SessionID : session .ID ,
56
57
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
57
58
FingerprintID : appstatspb .StmtFingerprintID (100 ),
58
59
ServiceLatencySec : 2 ,
@@ -72,7 +73,7 @@ func TestRegistry(t *testing.T) {
72
73
store := newStore (st )
73
74
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
74
75
75
- registry .ObserveStatement (session . ID , txns [0 ].stmts [0 ])
76
+ registry .ObserveStatement (txns [0 ].stmts [0 ])
76
77
registry .ObserveTransaction (session .ID , txns [0 ].txn )
77
78
78
79
expected := []* Insight {{
@@ -97,6 +98,7 @@ func TestRegistry(t *testing.T) {
97
98
// when the transaction does not have this information.
98
99
txn := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : false }
99
100
stmt := & sqlstats.RecordedStmtStats {
101
+ SessionID : session .ID ,
100
102
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
101
103
FingerprintID : appstatspb .StmtFingerprintID (100 ),
102
104
ServiceLatencySec : 2 ,
@@ -123,7 +125,7 @@ func TestRegistry(t *testing.T) {
123
125
LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
124
126
store := newStore (st )
125
127
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
126
- registry .ObserveStatement (session . ID , stmt )
128
+ registry .ObserveStatement (stmt )
127
129
// Transaction status is set during transaction stats recorded based on
128
130
// if the transaction committed. We'll inject the failure here to align
129
131
// it with the test. The insights integration tests will verify that this
@@ -152,6 +154,7 @@ func TestRegistry(t *testing.T) {
152
154
t .Run ("disabled" , func (t * testing.T ) {
153
155
transaction := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : true }
154
156
statement := & sqlstats.RecordedStmtStats {
157
+ SessionID : session .ID ,
155
158
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
156
159
FingerprintID : appstatspb .StmtFingerprintID (100 ),
157
160
ServiceLatencySec : 2 ,
@@ -160,7 +163,7 @@ func TestRegistry(t *testing.T) {
160
163
LatencyThreshold .Override (ctx , & st .SV , 0 )
161
164
store := newStore (st )
162
165
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
163
- registry .ObserveStatement (session . ID , statement )
166
+ registry .ObserveStatement (statement )
164
167
registry .ObserveTransaction (session .ID , transaction )
165
168
166
169
var actual []* Insight
@@ -178,13 +181,14 @@ func TestRegistry(t *testing.T) {
178
181
st := cluster .MakeTestingClusterSettings ()
179
182
LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
180
183
stmt := & sqlstats.RecordedStmtStats {
184
+ SessionID : session .ID ,
181
185
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
182
186
FingerprintID : appstatspb .StmtFingerprintID (100 ),
183
187
ServiceLatencySec : 0.5 ,
184
188
}
185
189
store := newStore (st )
186
190
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
187
- registry .ObserveStatement (session . ID , stmt )
191
+ registry .ObserveStatement (stmt )
188
192
registry .ObserveTransaction (session .ID , transaction )
189
193
190
194
var actual []* Insight
@@ -210,6 +214,7 @@ func TestRegistry(t *testing.T) {
210
214
},
211
215
stmts : []* sqlstats.RecordedStmtStats {
212
216
{
217
+ SessionID : session .ID ,
213
218
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
214
219
FingerprintID : appstatspb .StmtFingerprintID (100 ),
215
220
ServiceLatencySec : 2 ,
@@ -224,6 +229,7 @@ func TestRegistry(t *testing.T) {
224
229
},
225
230
stmts : []* sqlstats.RecordedStmtStats {
226
231
{
232
+ SessionID : otherSession .ID ,
227
233
StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
228
234
FingerprintID : appstatspb .StmtFingerprintID (101 ),
229
235
ServiceLatencySec : 3 ,
@@ -265,7 +271,7 @@ func TestRegistry(t *testing.T) {
265
271
266
272
for _ , txn := range txns {
267
273
for _ , stmt := range txn .stmts {
268
- registry .ObserveStatement (txn . sessionID , stmt )
274
+ registry .ObserveStatement (stmt )
269
275
}
270
276
registry .ObserveTransaction (txn .sessionID , txn .txn )
271
277
}
@@ -289,11 +295,13 @@ func TestRegistry(t *testing.T) {
289
295
t .Run ("sibling statements without problems" , func (t * testing.T ) {
290
296
transaction := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : true }
291
297
statement := & sqlstats.RecordedStmtStats {
298
+ SessionID : session .ID ,
292
299
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
293
300
FingerprintID : appstatspb .StmtFingerprintID (100 ),
294
301
ServiceLatencySec : 2 ,
295
302
}
296
303
siblingStatement := & sqlstats.RecordedStmtStats {
304
+ SessionID : session .ID ,
297
305
StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
298
306
FingerprintID : appstatspb .StmtFingerprintID (101 ),
299
307
}
@@ -322,8 +330,8 @@ func TestRegistry(t *testing.T) {
322
330
LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
323
331
store := newStore (st )
324
332
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
325
- registry .ObserveStatement (session . ID , statement )
326
- registry .ObserveStatement (session . ID , siblingStatement )
333
+ registry .ObserveStatement (statement )
334
+ registry .ObserveStatement (siblingStatement )
327
335
registry .ObserveTransaction (session .ID , transaction )
328
336
329
337
var actual []* Insight
@@ -350,6 +358,7 @@ func TestRegistry(t *testing.T) {
350
358
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
351
359
contentionDuration := 10 * time .Second
352
360
statement := & sqlstats.RecordedStmtStats {
361
+ SessionID : session .ID ,
353
362
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
354
363
FingerprintID : appstatspb .StmtFingerprintID (100 ),
355
364
ServiceLatencySec : 0.00001 ,
@@ -362,7 +371,7 @@ func TestRegistry(t *testing.T) {
362
371
},
363
372
}
364
373
365
- registry .ObserveStatement (session . ID , statement )
374
+ registry .ObserveStatement (statement )
366
375
registry .ObserveTransaction (session .ID , txnHighContention )
367
376
368
377
expected := []* Insight {
@@ -398,18 +407,21 @@ func TestRegistry(t *testing.T) {
398
407
stmts := []* sqlstats.RecordedStmtStats {
399
408
// copy the statement objects below:
400
409
{
410
+ SessionID : session .ID ,
401
411
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
402
412
FingerprintID : appstatspb .StmtFingerprintID (100 ),
403
413
ServiceLatencySec : 2 ,
404
414
Query : "SELECT * FROM users" ,
405
415
},
406
416
{
417
+ SessionID : session .ID ,
407
418
StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
408
419
FingerprintID : appstatspb .StmtFingerprintID (101 ),
409
420
ServiceLatencySec : 2 ,
410
421
Query : "SET vectorize = '_'" ,
411
422
},
412
423
{
424
+ SessionID : session .ID ,
413
425
StatementID : clusterunique .IDFromBytes ([]byte ("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" )),
414
426
FingerprintID : appstatspb .StmtFingerprintID (102 ),
415
427
ServiceLatencySec : 2 ,
@@ -442,7 +454,7 @@ func TestRegistry(t *testing.T) {
442
454
store := newStore (st )
443
455
registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
444
456
for _ , s := range stmts {
445
- registry .ObserveStatement (session . ID , s )
457
+ registry .ObserveStatement (s )
446
458
}
447
459
registry .ObserveTransaction (session .ID , transaction )
448
460
@@ -481,14 +493,21 @@ func TestInsightsRegistry_Clear(t *testing.T) {
481
493
// Create some test data.
482
494
sessionA := Session {ID : clusterunique .IDFromBytes ([]byte ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))}
483
495
sessionB := Session {ID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ))}
484
- statement := & sqlstats.RecordedStmtStats {
496
+ statementA := & sqlstats.RecordedStmtStats {
497
+ SessionID : sessionA .ID ,
498
+ StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
499
+ FingerprintID : appstatspb .StmtFingerprintID (100 ),
500
+ ServiceLatencySec : 2 ,
501
+ }
502
+ statementB := & sqlstats.RecordedStmtStats {
503
+ SessionID : sessionB .ID ,
485
504
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
486
505
FingerprintID : appstatspb .StmtFingerprintID (100 ),
487
506
ServiceLatencySec : 2 ,
488
507
}
489
508
// Record the test data, assert it's cached.
490
- registry .ObserveStatement (sessionA . ID , statement )
491
- registry .ObserveStatement (sessionB . ID , statement )
509
+ registry .ObserveStatement (statementA )
510
+ registry .ObserveStatement (statementB )
492
511
expLenStmts := 2
493
512
// No need to acquire the lock here, as the registry is not attached to anything.
494
513
require .Len (t , registry .statements , expLenStmts )
@@ -510,16 +529,24 @@ func TestInsightsRegistry_ClearSession(t *testing.T) {
510
529
// Create some test data.
511
530
sessionA := Session {ID : clusterunique .IDFromBytes ([]byte ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))}
512
531
sessionB := Session {ID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ))}
513
- statement := & sqlstats.RecordedStmtStats {
532
+ statementA := & sqlstats.RecordedStmtStats {
533
+ Failed : false ,
534
+ SessionID : sessionA .ID ,
535
+ StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
536
+ FingerprintID : appstatspb .StmtFingerprintID (100 ),
537
+ ServiceLatencySec : 2 ,
538
+ }
539
+ statementB := & sqlstats.RecordedStmtStats {
514
540
Failed : false ,
541
+ SessionID : sessionB .ID ,
515
542
StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
516
543
FingerprintID : appstatspb .StmtFingerprintID (100 ),
517
544
ServiceLatencySec : 2 ,
518
545
}
519
546
520
547
// Record the test data, assert it's cached.
521
- registry .ObserveStatement (sessionA . ID , statement )
522
- registry .ObserveStatement (sessionB . ID , statement )
548
+ registry .ObserveStatement (statementA )
549
+ registry .ObserveStatement (statementB )
523
550
// No need to acquire the lock here, as the registry is not attached to anything.
524
551
require .Len (t , registry .statements , 2 )
525
552
0 commit comments