@@ -53,6 +53,7 @@ func TestRegistry(t *testing.T) {
5353 },
5454 stmts : []* sqlstats.RecordedStmtStats {
5555 {
56+ SessionID : session .ID ,
5657 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
5758 FingerprintID : appstatspb .StmtFingerprintID (100 ),
5859 ServiceLatencySec : 2 ,
@@ -72,7 +73,7 @@ func TestRegistry(t *testing.T) {
7273 store := newStore (st )
7374 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
7475
75- registry .ObserveStatement (session . ID , txns [0 ].stmts [0 ])
76+ registry .ObserveStatement (txns [0 ].stmts [0 ])
7677 registry .ObserveTransaction (session .ID , txns [0 ].txn )
7778
7879 expected := []* Insight {{
@@ -97,6 +98,7 @@ func TestRegistry(t *testing.T) {
9798 // when the transaction does not have this information.
9899 txn := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : false }
99100 stmt := & sqlstats.RecordedStmtStats {
101+ SessionID : session .ID ,
100102 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
101103 FingerprintID : appstatspb .StmtFingerprintID (100 ),
102104 ServiceLatencySec : 2 ,
@@ -123,7 +125,7 @@ func TestRegistry(t *testing.T) {
123125 LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
124126 store := newStore (st )
125127 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
126- registry .ObserveStatement (session . ID , stmt )
128+ registry .ObserveStatement (stmt )
127129 // Transaction status is set during transaction stats recorded based on
128130 // if the transaction committed. We'll inject the failure here to align
129131 // it with the test. The insights integration tests will verify that this
@@ -152,6 +154,7 @@ func TestRegistry(t *testing.T) {
152154 t .Run ("disabled" , func (t * testing.T ) {
153155 transaction := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : true }
154156 statement := & sqlstats.RecordedStmtStats {
157+ SessionID : session .ID ,
155158 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
156159 FingerprintID : appstatspb .StmtFingerprintID (100 ),
157160 ServiceLatencySec : 2 ,
@@ -160,7 +163,7 @@ func TestRegistry(t *testing.T) {
160163 LatencyThreshold .Override (ctx , & st .SV , 0 )
161164 store := newStore (st )
162165 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
163- registry .ObserveStatement (session . ID , statement )
166+ registry .ObserveStatement (statement )
164167 registry .ObserveTransaction (session .ID , transaction )
165168
166169 var actual []* Insight
@@ -178,13 +181,14 @@ func TestRegistry(t *testing.T) {
178181 st := cluster .MakeTestingClusterSettings ()
179182 LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
180183 stmt := & sqlstats.RecordedStmtStats {
184+ SessionID : session .ID ,
181185 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
182186 FingerprintID : appstatspb .StmtFingerprintID (100 ),
183187 ServiceLatencySec : 0.5 ,
184188 }
185189 store := newStore (st )
186190 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
187- registry .ObserveStatement (session . ID , stmt )
191+ registry .ObserveStatement (stmt )
188192 registry .ObserveTransaction (session .ID , transaction )
189193
190194 var actual []* Insight
@@ -210,6 +214,7 @@ func TestRegistry(t *testing.T) {
210214 },
211215 stmts : []* sqlstats.RecordedStmtStats {
212216 {
217+ SessionID : session .ID ,
213218 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
214219 FingerprintID : appstatspb .StmtFingerprintID (100 ),
215220 ServiceLatencySec : 2 ,
@@ -224,6 +229,7 @@ func TestRegistry(t *testing.T) {
224229 },
225230 stmts : []* sqlstats.RecordedStmtStats {
226231 {
232+ SessionID : otherSession .ID ,
227233 StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
228234 FingerprintID : appstatspb .StmtFingerprintID (101 ),
229235 ServiceLatencySec : 3 ,
@@ -265,7 +271,7 @@ func TestRegistry(t *testing.T) {
265271
266272 for _ , txn := range txns {
267273 for _ , stmt := range txn .stmts {
268- registry .ObserveStatement (txn . sessionID , stmt )
274+ registry .ObserveStatement (stmt )
269275 }
270276 registry .ObserveTransaction (txn .sessionID , txn .txn )
271277 }
@@ -289,11 +295,13 @@ func TestRegistry(t *testing.T) {
289295 t .Run ("sibling statements without problems" , func (t * testing.T ) {
290296 transaction := & sqlstats.RecordedTxnStats {TransactionID : uuid .MakeV4 (), Committed : true }
291297 statement := & sqlstats.RecordedStmtStats {
298+ SessionID : session .ID ,
292299 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
293300 FingerprintID : appstatspb .StmtFingerprintID (100 ),
294301 ServiceLatencySec : 2 ,
295302 }
296303 siblingStatement := & sqlstats.RecordedStmtStats {
304+ SessionID : session .ID ,
297305 StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
298306 FingerprintID : appstatspb .StmtFingerprintID (101 ),
299307 }
@@ -322,8 +330,8 @@ func TestRegistry(t *testing.T) {
322330 LatencyThreshold .Override (ctx , & st .SV , 1 * time .Second )
323331 store := newStore (st )
324332 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 )
327335 registry .ObserveTransaction (session .ID , transaction )
328336
329337 var actual []* Insight
@@ -350,6 +358,7 @@ func TestRegistry(t *testing.T) {
350358 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
351359 contentionDuration := 10 * time .Second
352360 statement := & sqlstats.RecordedStmtStats {
361+ SessionID : session .ID ,
353362 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
354363 FingerprintID : appstatspb .StmtFingerprintID (100 ),
355364 ServiceLatencySec : 0.00001 ,
@@ -362,7 +371,7 @@ func TestRegistry(t *testing.T) {
362371 },
363372 }
364373
365- registry .ObserveStatement (session . ID , statement )
374+ registry .ObserveStatement (statement )
366375 registry .ObserveTransaction (session .ID , txnHighContention )
367376
368377 expected := []* Insight {
@@ -398,18 +407,21 @@ func TestRegistry(t *testing.T) {
398407 stmts := []* sqlstats.RecordedStmtStats {
399408 // copy the statement objects below:
400409 {
410+ SessionID : session .ID ,
401411 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
402412 FingerprintID : appstatspb .StmtFingerprintID (100 ),
403413 ServiceLatencySec : 2 ,
404414 Query : "SELECT * FROM users" ,
405415 },
406416 {
417+ SessionID : session .ID ,
407418 StatementID : clusterunique .IDFromBytes ([]byte ("dddddddddddddddddddddddddddddddd" )),
408419 FingerprintID : appstatspb .StmtFingerprintID (101 ),
409420 ServiceLatencySec : 2 ,
410421 Query : "SET vectorize = '_'" ,
411422 },
412423 {
424+ SessionID : session .ID ,
413425 StatementID : clusterunique .IDFromBytes ([]byte ("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" )),
414426 FingerprintID : appstatspb .StmtFingerprintID (102 ),
415427 ServiceLatencySec : 2 ,
@@ -442,7 +454,7 @@ func TestRegistry(t *testing.T) {
442454 store := newStore (st )
443455 registry := newRegistry (st , & latencyThresholdDetector {st : st }, store , nil )
444456 for _ , s := range stmts {
445- registry .ObserveStatement (session . ID , s )
457+ registry .ObserveStatement (s )
446458 }
447459 registry .ObserveTransaction (session .ID , transaction )
448460
@@ -481,14 +493,21 @@ func TestInsightsRegistry_Clear(t *testing.T) {
481493 // Create some test data.
482494 sessionA := Session {ID : clusterunique .IDFromBytes ([]byte ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))}
483495 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 ,
485504 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
486505 FingerprintID : appstatspb .StmtFingerprintID (100 ),
487506 ServiceLatencySec : 2 ,
488507 }
489508 // 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 )
492511 expLenStmts := 2
493512 // No need to acquire the lock here, as the registry is not attached to anything.
494513 require .Len (t , registry .statements , expLenStmts )
@@ -510,16 +529,24 @@ func TestInsightsRegistry_ClearSession(t *testing.T) {
510529 // Create some test data.
511530 sessionA := Session {ID : clusterunique .IDFromBytes ([]byte ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))}
512531 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 {
514540 Failed : false ,
541+ SessionID : sessionB .ID ,
515542 StatementID : clusterunique .IDFromBytes ([]byte ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )),
516543 FingerprintID : appstatspb .StmtFingerprintID (100 ),
517544 ServiceLatencySec : 2 ,
518545 }
519546
520547 // 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 )
523550 // No need to acquire the lock here, as the registry is not attached to anything.
524551 require .Len (t , registry .statements , 2 )
525552
0 commit comments