From 90962d603e2b0cc2eaf5ab095ce604e8bf383489 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Tue, 21 Apr 2026 20:52:57 +0300 Subject: [PATCH 1/2] Add support for using regex patterns in findSuite --- pkg/dataloader/prowloader/prow.go | 21 ++++++++++++---- pkg/db/suites.go | 40 +++++++++++++++++++++++++++++++ pkg/db/suites_test.go | 28 ++++++++++++++++++++++ 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 pkg/db/suites_test.go diff --git a/pkg/dataloader/prowloader/prow.go b/pkg/dataloader/prowloader/prow.go index 99f0365e26..7d0cd7f746 100644 --- a/pkg/dataloader/prowloader/prow.go +++ b/pkg/dataloader/prowloader/prow.go @@ -1167,12 +1167,23 @@ func (pl *ProwLoader) findSuite(name string) *uint { suite := &models.Suite{} pl.dbc.DB.Where("name = ?", name).Find(&suite) if suite.ID == 0 { - pl.suiteCache[name] = nil - } else { - id := suite.ID - pl.suiteCache[name] = &id + // No row - the exact suite name is not in the database (for example, by populateTestSuitesInDB) + if !db.IsTestSuiteImportable(name) { + pl.suiteCache[name] = nil + return nil + } + // If IsTestSuiteImportable() returns true (for example, pattern match), add the Suite row. + suite.Name = name + tx := pl.dbc.DB.Save(suite) + if tx.Error != nil { + log.WithError(tx.Error).Warningf("failed to create suite %q", name) + return nil + } + log.WithField("suite", name).Info("created new test suite") } - return pl.suiteCache[name] + id := suite.ID + pl.suiteCache[name] = &id + return &id } func (pl *ProwLoader) prowJobRunTestsFromGCS(ctx context.Context, pj *prow.ProwJob, id uint, path string, junitPaths []string) ([]*models.ProwJobRunTest, int, sippyprocessingv1.JobOverallResult, error) { diff --git a/pkg/db/suites.go b/pkg/db/suites.go index a1c3305473..49f1847590 100644 --- a/pkg/db/suites.go +++ b/pkg/db/suites.go @@ -1,6 +1,8 @@ package db import ( + "regexp" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -74,6 +76,44 @@ var testSuites = []string{ "tracing-uiplugin", } +// testSuitePatterns are regular expressions (MatchString) for suite names that should be imported +// without listing every literal name. Patterns are compiled in init(). +var testSuitePatterns = []string{ + // LP interop naming: `lp-interop---`. + `^lp-interop-`, + + +var compiledTestSuitePatterns []*regexp.Regexp + +// Invalid regexes panic at process start. +func init() { + compiledTestSuitePatterns = make([]*regexp.Regexp, len(testSuitePatterns)) + for i, p := range testSuitePatterns { + compiledTestSuitePatterns[i] = regexp.MustCompile(p) + } +} + +// Runs inside the prow loader on every unknown suite name +// Reports whether junit from this testsuite name should be imported: either an +// exact entry in testSuites or a match against testSuitePatterns. +func IsTestSuiteImportable(name string) bool { + if name == "" { + return false + } + for _, s := range testSuites { + if s == name { + return true + } + } + for _, re := range compiledTestSuitePatterns { + if re.MatchString(name) { + return true + } + } + return false +} + +// Runs when the DB is set up / migrated. func populateTestSuitesInDB(db *gorm.DB) error { for _, suiteName := range testSuites { s := models.Suite{} diff --git a/pkg/db/suites_test.go b/pkg/db/suites_test.go new file mode 100644 index 0000000000..31dd9df48f --- /dev/null +++ b/pkg/db/suites_test.go @@ -0,0 +1,28 @@ +package db + +import "testing" + +func TestIsTestSuiteImportable(t *testing.T) { + tests := []struct { + name string + want bool + }{ + {"", false}, + {"openshift-tests", true}, + {"CNV-lp-interop", true}, + {"ACS-lp-interop", true}, + {"lp-interop-ACS--my-tests", true}, + {"lp-interop-Foo", true}, + {"CNV-lp-interop-extra-suffix", false}, + {"random-suite", false}, + {"-lp-interop", false}, + {"lp-interop", false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsTestSuiteImportable(tt.name); got != tt.want { + t.Errorf("IsTestSuiteImportable(%q) = %v, want %v", tt.name, got, tt.want) + } + }) + } +} From 1255211c29307e18d7dc6ed4d97dd92a64fa4546 Mon Sep 17 00:00:00 2001 From: oharan2 Date: Tue, 21 Apr 2026 22:39:42 +0300 Subject: [PATCH 2/2] Update pkg/db/suites.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- pkg/db/suites.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/db/suites.go b/pkg/db/suites.go index 49f1847590..b666c009c2 100644 --- a/pkg/db/suites.go +++ b/pkg/db/suites.go @@ -81,7 +81,7 @@ var testSuites = []string{ var testSuitePatterns = []string{ // LP interop naming: `lp-interop---`. `^lp-interop-`, - +} var compiledTestSuitePatterns []*regexp.Regexp