Skip to content

Commit 0163245

Browse files
craig[bot]alyshanjahani-crl
andcommitted
Merge #153366
153366: serverccl, application_api: Fix some tests relying on statement_statistics r=alyshanjahani-crl a=alyshanjahani-crl This commit sets the SynchronousSQLStats testing knob on for TestTenantCannotSeeNonTenantStats. Additionally, it fixes a testing bug in TestTenantCannotSeeNonTenantStats, TestStatusAPIStatements, TestStatusAPICombinedStatementsWithFullScans, and TestStatusAPICombinedStatements. These tests involve executing a set of statements and verifying that the statement stats response contains the same set of statements. However, they filter out statements with a failure count > 0. This was a bug introduced by pull #120236 which changed the way failed statements were collected in the SQL stats system. Previously, a stmt with the same query that failed to execute would recieve a different fingerprint and thus be included as a different entry in the statements response. These existing tests filtered out statement entries that failed b/c they used to be an additional entry that would fail when comparing with the set of stmts executed. This filtering out from the tests should have been removed as part of pull #120236. Fixes: #152175 Release note: None Co-authored-by: Alyshan Jahani <[email protected]>
2 parents 9b2db4c + 0f44910 commit 0163245

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

pkg/ccl/serverccl/statusccl/tenant_status_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,16 @@ func TestTenantCannotSeeNonTenantStats(t *testing.T) {
402402
skip.UnderStressWithIssue(t, 113984)
403403

404404
ctx := context.Background()
405+
sqlStatsKnobs := sqlstats.CreateTestingKnobs()
406+
sqlStatsKnobs.SynchronousSQLStats = true
405407
testCluster := serverutils.StartCluster(t, 3 /* numNodes */, base.TestClusterArgs{
406408
ServerArgs: base.TestServerArgs{
407409
Knobs: base.TestingKnobs{
410+
SQLStatsKnobs: sqlStatsKnobs,
408411
SpanConfig: &spanconfig.TestingKnobs{
409412
ManagerDisableJobCreation: true, // TODO(irfansharif): #74919.
410-
}},
413+
},
414+
},
411415
DefaultTestTenant: base.TestControlsTenantsExplicitly,
412416
},
413417
})
@@ -418,7 +422,7 @@ func TestTenantCannotSeeNonTenantStats(t *testing.T) {
418422
tenant, sqlDB := serverutils.StartTenant(t, server, base.TestTenantArgs{
419423
TenantID: roachpb.MustMakeTenantID(10 /* id */),
420424
TestingKnobs: base.TestingKnobs{
421-
SQLStatsKnobs: sqlstats.CreateTestingKnobs(),
425+
SQLStatsKnobs: sqlStatsKnobs,
422426
},
423427
})
424428

@@ -478,7 +482,7 @@ func TestTenantCannotSeeNonTenantStats(t *testing.T) {
478482
}
479483

480484
conn = sqlutils.MakeSQLRunner(systemLayer.SQLConn(t))
481-
sqlstatstestutil.WaitForStatementEntriesAtLeast(t, conn, len(testCaseTenant), sqlstatstestutil.StatementFilter{
485+
sqlstatstestutil.WaitForStatementEntriesAtLeast(t, conn, len(testCaseNonTenant), sqlstatstestutil.StatementFilter{
482486
App: appName,
483487
})
484488

@@ -524,11 +528,6 @@ func TestTenantCannotSeeNonTenantStats(t *testing.T) {
524528

525529
var actualStatements []string
526530
for _, respStatement := range actual.Statements {
527-
if respStatement.Stats.FailureCount > 0 {
528-
// We ignore failed statements here as the INSERT statement can fail and
529-
// be automatically retried, confusing the test success check.
530-
continue
531-
}
532531
if respStatement.Key.KeyData.App != appName {
533532
continue
534533
}

pkg/server/application_api/sql_stats_test.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,6 @@ func TestStatusAPIStatements(t *testing.T) {
464464
// See if the statements returned are what we executed.
465465
var statementsInResponse []string
466466
for _, respStatement := range resp.Statements {
467-
if respStatement.Stats.FailureCount > 0 {
468-
// We ignore failed statements here as the INSERT statement can fail and
469-
// be automatically retried, confusing the test success check.
470-
continue
471-
}
472467
if respStatement.Key.KeyData.App != "test" {
473468
continue
474469
}
@@ -807,14 +802,7 @@ func TestStatusAPICombinedStatementsWithFullScans(t *testing.T) {
807802
// statement statistics received from the server response.
808803
actualResponseStatsMap := make(map[string]serverpb.StatementsResponse_CollectedStatementStatistics)
809804
for _, respStatement := range resp.Statements {
810-
// Skip failed statements: The test app may encounter transient 40001
811-
// errors that are automatically retried. Thus, we only consider
812-
// statements that were that were successfully executed by the test app
813-
// to avoid counting such failures. If a statement that we expect to be
814-
// successful is not found in the response, the test will fail later.
815-
if respStatement.Key.KeyData.App == testAppName && respStatement.Stats.FailureCount == 0 {
816-
actualResponseStatsMap[respStatement.Key.KeyData.Query] = respStatement
817-
}
805+
actualResponseStatsMap[respStatement.Key.KeyData.Query] = respStatement
818806
}
819807

820808
for respQuery, expectedData := range expectedStatementStatsMap {
@@ -927,11 +915,6 @@ func TestStatusAPICombinedStatements(t *testing.T) {
927915
var statementsInResponse []string
928916
expectedTxnFingerprints := map[appstatspb.TransactionFingerprintID]struct{}{}
929917
for _, respStatement := range resp.Statements {
930-
if respStatement.Stats.FailureCount > 0 {
931-
// We ignore failed statements here as the INSERT statement can fail and
932-
// be automatically retried, confusing the test success check.
933-
continue
934-
}
935918
if respStatement.Key.KeyData.App != "test" {
936919
// CombinedStatementStats should filter out internal queries.
937920
if strings.HasPrefix(respStatement.Key.KeyData.Query, catconstants.InternalAppNamePrefix) {

0 commit comments

Comments
 (0)