diff --git a/pkg/cmd/roachtest/main.go b/pkg/cmd/roachtest/main.go index e0a666e3034f..85f4222dc2dd 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 @@ -310,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 @@ -377,13 +382,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, + allTests, err := testselector.CategoriseTests(ctx, selectorLogger, 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") } // successfulTests are the tests considered by snowflake to not run, but, part of the testSpecs. @@ -436,6 +448,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 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..8f612d20fc3b 100644 --- a/pkg/cmd/roachtest/testselector/selector.go +++ b/pkg/cmd/roachtest/testselector/selector.go @@ -17,6 +17,7 @@ import ( "strconv" "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec" + "github.com/cockroachdb/cockroach/pkg/roachprod/logger" sf "github.com/snowflakedb/gosnowflake" ) @@ -91,7 +92,27 @@ 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) { + 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 @@ -103,10 +124,10 @@ func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails, } 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), @@ -115,6 +136,11 @@ 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 {