From 5996740749a22e9594144bf5fa0d09b06cce0a77 Mon Sep 17 00:00:00 2001 From: William Choe Date: Mon, 29 Sep 2025 15:15:56 -0400 Subject: [PATCH 1/4] init commit adding test selector logger --- pkg/cmd/roachtest/main.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/roachtest/main.go b/pkg/cmd/roachtest/main.go index e0a666e3034f..5e7c70af3f15 100644 --- a/pkg/cmd/roachtest/main.go +++ b/pkg/cmd/roachtest/main.go @@ -13,6 +13,7 @@ import ( "math/rand" "os" "os/user" + "path/filepath" "regexp" "strings" "time" @@ -25,6 +26,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/testselector" "github.com/cockroachdb/cockroach/pkg/roachprod" "github.com/cockroachdb/cockroach/pkg/roachprod/config" + "github.com/cockroachdb/cockroach/pkg/roachprod/logger" "github.com/cockroachdb/cockroach/pkg/util/randutil" "github.com/cockroachdb/errors" _ "github.com/lib/pq" // register postgres driver @@ -377,13 +379,20 @@ func testsToRun( // 5. All tests that are marked "selected=true" are considered for the test run. func updateSpecForSelectiveTests( ctx context.Context, specs []registry.TestSpec, logFunc func(format string, args ...interface{}), -) { +) error { + logPath := filepath.Join(roachtestflags.ArtifactsDir, "selector.log") + selectorLogger, err := logger.RootLogger(logPath, logger.NoTee) + if err != nil { + return err + } + defer selectorLogger.Close() + selectorLogger.Printf("This is the test selector logger") + selectedTestsCount := 0 allTests, err := testselector.CategoriseTests(ctx, testselector.NewDefaultSelectTestsReq(roachtestflags.Cloud, roachtestflags.Suite)) if err != nil { - logFunc("running all tests! error selecting tests: %v\n", err) - return + return errors.Wrap(err, "running all tests! error selecting tests: %v") } // successfulTests are the tests considered by snowflake to not run, but, part of the testSpecs. @@ -436,6 +445,7 @@ func updateSpecForSelectiveTests( } } logFunc("%d out of %d tests selected for the run!\n", selectedTestsCount, len(specs)) + return nil } // testShouldBeSkipped decides whether a test should be skipped based on test details and suite From e2ec83cd66571509c0f6a6d3eb6e01b4b0b6bc44 Mon Sep 17 00:00:00 2001 From: William Choe Date: Tue, 7 Oct 2025 12:06:30 -0400 Subject: [PATCH 2/4] changes --- pkg/cmd/roachtest/main.go | 7 +++++-- pkg/cmd/roachtest/testselector/BUILD.bazel | 1 + pkg/cmd/roachtest/testselector/selector.go | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/roachtest/main.go b/pkg/cmd/roachtest/main.go index 5e7c70af3f15..38c54e3ed1a2 100644 --- a/pkg/cmd/roachtest/main.go +++ b/pkg/cmd/roachtest/main.go @@ -312,9 +312,12 @@ func testsToRun( // the test categorization must be complete in 30 seconds ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - updateSpecForSelectiveTests(ctx, specs, func(format string, args ...interface{}) { + err := updateSpecForSelectiveTests(ctx, specs, func(format string, args ...interface{}) { fmt.Fprintf(os.Stdout, format, args...) }) + if err != nil { + return nil, err + } } var notSkipped []registry.TestSpec @@ -389,7 +392,7 @@ func updateSpecForSelectiveTests( selectorLogger.Printf("This is the test selector logger") selectedTestsCount := 0 - allTests, err := testselector.CategoriseTests(ctx, + allTests, err := testselector.CategoriseTests(ctx, selectorLogger, testselector.NewDefaultSelectTestsReq(roachtestflags.Cloud, roachtestflags.Suite)) if err != nil { return errors.Wrap(err, "running all tests! error selecting tests: %v") diff --git a/pkg/cmd/roachtest/testselector/BUILD.bazel b/pkg/cmd/roachtest/testselector/BUILD.bazel index a6f90d799e76..dea18b40ceaf 100644 --- a/pkg/cmd/roachtest/testselector/BUILD.bazel +++ b/pkg/cmd/roachtest/testselector/BUILD.bazel @@ -8,6 +8,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/cmd/roachtest/spec", + "//pkg/roachprod/logger", "@com_github_snowflakedb_gosnowflake//:gosnowflake", ], ) diff --git a/pkg/cmd/roachtest/testselector/selector.go b/pkg/cmd/roachtest/testselector/selector.go index a73d8234c45c..9fb2ab3c2b1f 100644 --- a/pkg/cmd/roachtest/testselector/selector.go +++ b/pkg/cmd/roachtest/testselector/selector.go @@ -15,8 +15,10 @@ import ( "fmt" "os" "strconv" + "strings" "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec" + "github.com/cockroachdb/cockroach/pkg/roachprod/logger" sf "github.com/snowflakedb/gosnowflake" ) @@ -91,7 +93,9 @@ func NewDefaultSelectTestsReq(cloud spec.Cloud, suite string) *SelectTestsReq { // 3. the test has not been run for a while // It returns all the tests. The selected tests have the value TestDetails.Selected as true // The tests are sorted by the last run and is used for further test selection criteria. So, the order should not be modified. -func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails, error) { +func CategoriseTests( + ctx context.Context, logger *logger.Logger, req *SelectTestsReq, +) ([]*TestDetails, error) { db, err := getConnect(ctx) if err != nil { return nil, err @@ -115,6 +119,12 @@ func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails, return nil, err } defer func() { _ = rows.Close() }() + + debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v") + logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch, + fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), + req.FirstRunOn*-1, req.LastRunOn*-1) + // All the column headers colHeaders, err := rows.Columns() if err != nil { From 35d0453e7890a4d0fbcef7de8b3a8dec085615a9 Mon Sep 17 00:00:00 2001 From: William Choe Date: Tue, 7 Oct 2025 12:51:13 -0400 Subject: [PATCH 3/4] remove uneeded format in str --- pkg/cmd/roachtest/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/roachtest/main.go b/pkg/cmd/roachtest/main.go index 38c54e3ed1a2..85f4222dc2dd 100644 --- a/pkg/cmd/roachtest/main.go +++ b/pkg/cmd/roachtest/main.go @@ -395,7 +395,7 @@ func updateSpecForSelectiveTests( allTests, err := testselector.CategoriseTests(ctx, selectorLogger, testselector.NewDefaultSelectTestsReq(roachtestflags.Cloud, roachtestflags.Suite)) if err != nil { - return errors.Wrap(err, "running all tests! error selecting tests: %v") + return errors.Wrap(err, "running all tests! error selecting tests") } // successfulTests are the tests considered by snowflake to not run, but, part of the testSpecs. From d92c84644ee7c440e409648455b2684a3967a2a2 Mon Sep 17 00:00:00 2001 From: William Choe Date: Tue, 7 Oct 2025 13:48:52 -0400 Subject: [PATCH 4/4] debuging the debug --- pkg/cmd/roachtest/testselector/selector.go | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/roachtest/testselector/selector.go b/pkg/cmd/roachtest/testselector/selector.go index 9fb2ab3c2b1f..8f612d20fc3b 100644 --- a/pkg/cmd/roachtest/testselector/selector.go +++ b/pkg/cmd/roachtest/testselector/selector.go @@ -15,7 +15,6 @@ import ( "fmt" "os" "strconv" - "strings" "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec" "github.com/cockroachdb/cockroach/pkg/roachprod/logger" @@ -96,6 +95,24 @@ func NewDefaultSelectTestsReq(cloud spec.Cloud, suite string) *SelectTestsReq { func CategoriseTests( ctx context.Context, logger *logger.Logger, req *SelectTestsReq, ) ([]*TestDetails, error) { + currentBranch := os.Getenv("TC_BUILD_BRANCH") + if currentBranch == "" { + currentBranch = "master" + } + + // Can't do this because the literal `%V exists in the query bc `like `%VMs ....`` + //debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v") + //logger.Printf(debugQuery) + //logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch, + // fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), + // req.FirstRunOn*-1, req.LastRunOn*-1) + + // Print Query & Query Params + + logger.Printf("Query Params:\n%d\n%s\n%s\n%d\n%d", req.ForPastDays*-1, currentBranch, + fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), + req.FirstRunOn*-1, req.LastRunOn*-1) + db, err := getConnect(ctx) if err != nil { return nil, err @@ -107,10 +124,10 @@ func CategoriseTests( } defer func() { _ = statement.Close() }() // get the current branch from the teamcity environment - currentBranch := os.Getenv("TC_BUILD_BRANCH") - if currentBranch == "" { - currentBranch = "master" - } + //currentBranch := os.Getenv("TC_BUILD_BRANCH") + //if currentBranch == "" { + // currentBranch = "master" + //} // add the parameters in sequence rows, err := statement.QueryContext(ctx, req.ForPastDays*-1, currentBranch, fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), @@ -119,11 +136,10 @@ func CategoriseTests( return nil, err } defer func() { _ = rows.Close() }() - - debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v") - logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch, - fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), - req.FirstRunOn*-1, req.LastRunOn*-1) + //debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v") + //logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch, + // fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud), + // req.FirstRunOn*-1, req.LastRunOn*-1) // All the column headers colHeaders, err := rows.Columns()