Skip to content

NO-JIRA: check for dynamic suites#3478

Open
neisw wants to merge 7 commits intoopenshift:mainfrom
neisw:dynamic-suites
Open

NO-JIRA: check for dynamic suites#3478
neisw wants to merge 7 commits intoopenshift:mainfrom
neisw:dynamic-suites

Conversation

@neisw
Copy link
Copy Markdown
Contributor

@neisw neisw commented Apr 28, 2026

Derivative work of #3456

Summary by CodeRabbit

  • New Features

    • Dynamic suite name resolution using configurable pattern matching to broaden accepted suite names.
  • Bug Fixes

    • Centralized suite ID lookup with improved caching and stricter handling of unknown or invalid suites for more consistent behavior.
  • Tests

    • Added unit tests validating dynamic suite pattern matching across multiple positive and negative cases.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Apr 28, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@neisw: This pull request explicitly references no jira issue.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Delegate suite name resolution to a new exported GetSuiteID that applies static list and regex pattern checks and centralize DB upsert in getOrCreateSuite; prow loader now caches and returns GetSuiteID results; add unit tests validating dynamic regex suite matching.

Changes

Cohort / File(s) Summary
Database suite logic
pkg/db/suites.go
Adds exported GetSuiteID(db *gorm.DB, name string) *uint; introduces getOrCreateSuite using FirstOrCreate with a First fallback; integrates regex-based testSuitePatterns matching; updates population flow to treat GetSuiteID returning nil as an error.
Prow loader integration
pkg/dataloader/prowloader/prow.go
findSuite now delegates suite ID lookup to db.GetSuiteID, caches and returns that result, and removes the prior inline models.Suite DB query and explicit nil cache logic.
Tests for dynamic patterns
pkg/db/suites_test.go
Adds TestDynamicSuitePatternMatching unit test that iterates suite-name cases against testSuitePatterns, asserting expected match results in-memory without DB access.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ProwLoader as Prow Loader
    participant DB as Database
    participant Pattern as Pattern Matcher

    Client->>ProwLoader: request suite by name
    ProwLoader->>ProwLoader: check cache
    alt cache hit
        ProwLoader-->>Client: return cached suite ID
    else cache miss
        ProwLoader->>DB: GetSuiteID(name)
        DB->>Pattern: evaluate name against static list + regex patterns
        alt pattern matches
            Pattern-->>DB: match found
            DB->>DB: getOrCreateSuite (FirstOrCreate / First fallback)
            DB-->>ProwLoader: suite ID (uint)
            ProwLoader->>ProwLoader: cache suite ID
            ProwLoader-->>Client: return suite ID
        else no match
            Pattern-->>DB: no match
            DB-->>ProwLoader: nil
            ProwLoader->>ProwLoader: cache nil result
            ProwLoader-->>Client: no suite found
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 16 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Coverage For New Features ⚠️ Warning New exported function GetSuiteID and pure helper function isSuiteImportable lack corresponding unit test coverage. Add TestIsSuiteImportable and TestGetSuiteID functions to pkg/db/suites_test.go to properly test the new functionality.
✅ Passed checks (16 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title refers to checking for dynamic suites, which aligns with the core refactoring of suite lookup logic and the new GetSuiteID API that validates suite names against testSuites and regex-based testSuitePatterns.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Go Error Handling ✅ Passed Go error handling patterns are properly implemented with correct nil checks, no ignored errors, and safe pointer dereferences.
Sql Injection Prevention ✅ Passed SQL injection vulnerability analysis: The modified code in pkg/db/suites.go uses parameterized queries with placeholders, preventing SQL injection. The findSuite function in prow.go accepts a suiteName parameter and passes it safely through the database layer via prepared statements.
Excessive Css In React Should Use Styles ✅ Passed The PR modifies Go backend files, not React components with inline CSS styles.
Single Responsibility And Clear Naming ✅ Passed Each function has a single, well-defined responsibility with clear, action-oriented names that explicitly communicate purpose.
Stable And Deterministic Test Names ✅ Passed This pull request does not use Ginkgo testing framework. The repository uses standard Go testing package with t.Run() subtests. The new test contains only static, descriptive subtest names with no dynamic content. Since the custom check addresses Ginkgo test names which are not present, the check is not applicable.
Test Structure And Quality ✅ Passed Test code uses standard Go testing package with table-driven pattern, not Ginkgo framework, so this Ginkgo-specific check does not apply.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests are present in this PR. The new test in pkg/db/suites_test.go is a standard Go unit test using the testing package that validates pattern matching logic without Kubernetes or OpenShift API interactions.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This pull request does not add any Ginkgo e2e tests; only a standard Go unit test for pattern matching logic in a backend data package.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only backend application code in Go database ORM and data loading logic with unit tests; no Kubernetes deployment manifests, operator code, or controllers are introduced.
Ote Binary Stdout Contract ✅ Passed All modified files are library packages with no process-level code, and no stdout writes were detected in the changes.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR adds only a standard Go unit test, not Ginkgo e2e tests. No IPv4 assumptions or external connectivity requirements detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot requested review from smg247 and sosiouxme April 28, 2026 22:26
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 28, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/dataloader/prowloader/prow.go`:
- Around line 1187-1191: The code is caching the result of
db.CheckForDynamicSuite into pl.suiteCache even when it returns nil, making
transient DB/create failures become permanent misses; update the loader to only
assign pl.suiteCache[name] = id when id != nil (i.e., after calling
CheckForDynamicSuite) so nil results aren't cached, or alternatively change
CheckForDynamicSuite to return a distinguishable outcome (e.g., (id, error) or a
sentinel) and only cache explicit "no-match" negatives while not caching on
creation/DB errors; adjust callers (the code around CheckForDynamicSuite and
pl.suiteCache usage) accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 86f2f674-058f-4540-87d0-075ce06b27d8

📥 Commits

Reviewing files that changed from the base of the PR and between b30049e and 3c24d9b.

📒 Files selected for processing (3)
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/suites.go
  • pkg/db/suites_test.go

Comment thread pkg/dataloader/prowloader/prow.go Outdated
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 28, 2026

@coderabbitai[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/dataloader/prowloader/prow.go`:
- Around line 1187-1191: The code is caching the result of
db.CheckForDynamicSuite into pl.suiteCache even when it returns nil, making
transient DB/create failures become permanent misses; update the loader to only
assign pl.suiteCache[name] = id when id != nil (i.e., after calling
CheckForDynamicSuite) so nil results aren't cached, or alternatively change
CheckForDynamicSuite to return a distinguishable outcome (e.g., (id, error) or a
sentinel) and only cache explicit "no-match" negatives while not caching on
creation/DB errors; adjust callers (the code around CheckForDynamicSuite and
pl.suiteCache usage) accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 86f2f674-058f-4540-87d0-075ce06b27d8

📥 Commits

Reviewing files that changed from the base of the PR and between b30049e and 3c24d9b.

📒 Files selected for processing (3)
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/suites.go
  • pkg/db/suites_test.go

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

Copy link
Copy Markdown

@etirta etirta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @neisw, I support moving forward with this PR, as I agree with exposing the API in pkg/db/suites.go to handle the search algorithm.

However, I have a few suggestions to reduce the footprint and ensure the entire search algorithm is fully encapsulated within the pkg/db/suites.go module.

Comment thread pkg/db/suites.go Outdated
Comment thread pkg/db/suites.go Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/db/suites.go`:
- Around line 122-129: getOrCreateSuite uses db.Where(...).FirstOrCreate(&suite)
which is race-prone and currently returns nil on any error; update the error
handling to detect unique-constraint/race errors, and on FirstOrCreate failure
perform a fallback SELECT (e.g., db.Where("name = ?", name).First(&suite)) to
retrieve the row created by the concurrent caller before giving up; ensure the
subsequent validation/logging that examines suite.ID (the logic after the
upsert) uses the suite loaded by the fallback SELECT and logs the actual error
only if the fallback also fails. Refer to getOrCreateSuite, models.Suite,
db.Where(...).FirstOrCreate, result.Error and the validation/logging block that
follows the upsert.
- Around line 85-100: GetSuiteID currently returns nil for both "not importable"
and DB errors causing callers like findSuite to cache false negatives; change
GetSuiteID signature to return (*uint, error), have it return (nil, nil) when
!isSuiteImportable(name) and propagate any DB error from getOrCreateSuite as
(nil, err), update getOrCreateSuite to return (*uint, error) if it doesn't
already, and adjust callers (e.g., findSuite and the loader caching logic) to
only cache a nil suite ID when err == nil and to retry/propagate on non-nil
errors so transient DB failures are not treated as deliberate filtering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ad722fed-d3d1-4c25-bd88-1d641ac961ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3c24d9b and e298a17.

📒 Files selected for processing (3)
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/suites.go
  • pkg/db/suites_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/db/suites_test.go
  • pkg/dataloader/prowloader/prow.go

Comment thread pkg/db/suites.go
Comment thread pkg/db/suites.go Outdated
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 29, 2026

@coderabbitai[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/db/suites.go`:
- Around line 122-129: getOrCreateSuite uses db.Where(...).FirstOrCreate(&suite)
which is race-prone and currently returns nil on any error; update the error
handling to detect unique-constraint/race errors, and on FirstOrCreate failure
perform a fallback SELECT (e.g., db.Where("name = ?", name).First(&suite)) to
retrieve the row created by the concurrent caller before giving up; ensure the
subsequent validation/logging that examines suite.ID (the logic after the
upsert) uses the suite loaded by the fallback SELECT and logs the actual error
only if the fallback also fails. Refer to getOrCreateSuite, models.Suite,
db.Where(...).FirstOrCreate, result.Error and the validation/logging block that
follows the upsert.
- Around line 85-100: GetSuiteID currently returns nil for both "not importable"
and DB errors causing callers like findSuite to cache false negatives; change
GetSuiteID signature to return (*uint, error), have it return (nil, nil) when
!isSuiteImportable(name) and propagate any DB error from getOrCreateSuite as
(nil, err), update getOrCreateSuite to return (*uint, error) if it doesn't
already, and adjust callers (e.g., findSuite and the loader caching logic) to
only cache a nil suite ID when err == nil and to retry/propagate on non-nil
errors so transient DB failures are not treated as deliberate filtering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: ad722fed-d3d1-4c25-bd88-1d641ac961ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3c24d9b and e298a17.

📒 Files selected for processing (3)
  • pkg/dataloader/prowloader/prow.go
  • pkg/db/suites.go
  • pkg/db/suites_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/db/suites_test.go
  • pkg/dataloader/prowloader/prow.go

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
pkg/db/suites.go (2)

122-141: ⚠️ Potential issue | 🟠 Major

FirstOrCreate handling is not concurrency-safe as written, and Line 139 log text is misleading.

Line 123 claims “thread-safe upsert behavior,” but FirstOrCreate can still hit concurrent insert races. Current error handling at Line 127-130 returns nil immediately instead of recovering via a fallback read. Also, at Line 139, RowsAffected > 0 corresponds to creation, not retrieval.

Suggested direction
-// getOrCreateSuite finds or creates a suite by name. Returns the suite ID on success, nil on error.
-// Uses FirstOrCreate for thread-safe upsert behavior.
-func getOrCreateSuite(db *gorm.DB, name string) *uint {
+// getOrCreateSuite finds or creates a suite by name.
+// Returns suite ID on success; returns an error on DB failures.
+func getOrCreateSuite(db *gorm.DB, name string) (*uint, error) {
 	suite := models.Suite{Name: name}
 	result := db.Where("name = ?", name).FirstOrCreate(&suite)
 	if result.Error != nil {
-		log.WithError(result.Error).Errorf("failed to get or create suite %q", name)
-		return nil
+		// Recover from concurrent creator race by re-reading.
+		if err := db.Where("name = ?", name).First(&suite).Error; err != nil {
+			log.WithError(result.Error).Errorf("failed to get or create suite %q", name)
+			return nil, errors.Wrapf(result.Error, "failed to get or create suite %q", name)
+		}
 	}
 
 	if suite.ID == 0 {
 		log.Errorf("suite %q has invalid ID 0", name)
-		return nil
+		return nil, errors.Errorf("suite %q has invalid ID 0", name)
 	}
 
-	if result.RowsAffected > 0 {
-		log.WithField("suite", name).Info("retrieved test suite")
+	if result.RowsAffected > 0 {
+		log.WithField("suite", name).Info("created test suite")
+	} else {
+		log.WithField("suite", name).Debug("retrieved test suite")
 	}
 
 	id := suite.ID
-	return &id
+	return &id, nil
}
For gorm.io/gorm v1.22.x, what are the documented semantics of FirstOrCreate and RowsAffected, and what is the recommended pattern to handle concurrent unique-key insert races?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/db/suites.go` around lines 122 - 141, getOrCreateSuite currently returns
nil on any FirstOrCreate error and misinterprets RowsAffected; change it to, on
result.Error, detect a unique-key/duplicate-insert race (e.g., inspect
result.Error for duplicate key or attempt a fallback query) and if so do a
fallback db.Where("name = ?", name).First(&suite) to load the existing row
before returning; only return nil if both FirstOrCreate and the fallback read
fail. Also fix the RowsAffected logging in getOrCreateSuite: treat RowsAffected
> 0 as "created test suite" and otherwise log "retrieved test suite", validate
suite.ID > 0 and return &suite.ID (not nil) on success. Ensure you reference the
getOrCreateSuite function, the db.Where(...).FirstOrCreate(&suite) call, and the
fallback db.Where(...).First(&suite) read when implementing this change.

85-100: ⚠️ Potential issue | 🟠 Major

Separate “not importable” from “DB failure” in GetSuiteID.

At Line 87 and Line 94-99, nil currently means both “filtered out” and “lookup/create failed.” With findSuite caching nil results in pkg/dataloader/prowloader/prow.go (Line 1170-1187 in provided context), transient DB failures get cached as permanent skips for that loader instance.

Suggested direction
-func GetSuiteID(db *gorm.DB, name string) *uint {
+func GetSuiteID(db *gorm.DB, name string) (*uint, error) {
 	if name == "" {
-		return nil
+		return nil, nil
 	}
 	if !isSuiteImportable(name) {
-		return nil
+		return nil, nil
 	}
-	return getOrCreateSuite(db, name)
+	return getOrCreateSuite(db, name)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/db/suites.go` around lines 85 - 100, GetSuiteID currently returns nil for
both "suite not importable" and "DB failure", causing transient DB errors to be
treated as permanent skips; change GetSuiteID(name string) to return a distinct
result and error (e.g., (*uint, error) or (uint, bool, error)) so "not
importable" is signaled without error and DB failures return a non-nil error;
keep the isSuiteImportable check first, have getOrCreateSuite propagate DB
errors instead of swallowing them, and update callers (notably findSuite /
pkg/dataloader/prowloader/prow.go) to treat a non-nil error as transient and
avoid caching the skip.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@pkg/db/suites.go`:
- Around line 122-141: getOrCreateSuite currently returns nil on any
FirstOrCreate error and misinterprets RowsAffected; change it to, on
result.Error, detect a unique-key/duplicate-insert race (e.g., inspect
result.Error for duplicate key or attempt a fallback query) and if so do a
fallback db.Where("name = ?", name).First(&suite) to load the existing row
before returning; only return nil if both FirstOrCreate and the fallback read
fail. Also fix the RowsAffected logging in getOrCreateSuite: treat RowsAffected
> 0 as "created test suite" and otherwise log "retrieved test suite", validate
suite.ID > 0 and return &suite.ID (not nil) on success. Ensure you reference the
getOrCreateSuite function, the db.Where(...).FirstOrCreate(&suite) call, and the
fallback db.Where(...).First(&suite) read when implementing this change.
- Around line 85-100: GetSuiteID currently returns nil for both "suite not
importable" and "DB failure", causing transient DB errors to be treated as
permanent skips; change GetSuiteID(name string) to return a distinct result and
error (e.g., (*uint, error) or (uint, bool, error)) so "not importable" is
signaled without error and DB failures return a non-nil error; keep the
isSuiteImportable check first, have getOrCreateSuite propagate DB errors instead
of swallowing them, and update callers (notably findSuite /
pkg/dataloader/prowloader/prow.go) to treat a non-nil error as transient and
avoid caching the skip.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: c66e491d-a537-46c9-8338-b21c2828707b

📥 Commits

Reviewing files that changed from the base of the PR and between e298a17 and fe7f247.

📒 Files selected for processing (1)
  • pkg/db/suites.go

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

Copy link
Copy Markdown

@etirta etirta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having another PR, let's define what we plan for all of our teams. Thx.

Comment thread pkg/db/suites.go Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/db/suites.go (1)

106-122: Consider using a set for O(1) lookup on testSuites.

The current linear scan through testSuites is fine for ~50 items, but if this list grows or isSuiteImportable is called frequently in hot paths, a map[string]struct{} initialized once would provide O(1) lookups.

♻️ Optional optimization
var testSuitesSet = func() map[string]struct{} {
	set := make(map[string]struct{}, len(testSuites))
	for _, s := range testSuites {
		set[s] = struct{}{}
	}
	return set
}()

func isSuiteImportable(name string) bool {
	if _, ok := testSuitesSet[name]; ok {
		return true
	}
	for _, re := range testSuitePatterns {
		if re.MatchString(name) {
			return true
		}
	}
	return false
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/db/suites.go` around lines 106 - 122, Replace the linear scan over
testSuites in isSuiteImportable with an O(1) lookup by creating a package-level
set (map[string]struct{}) initialized once from testSuites (e.g., testSuitesSet)
and then check membership via an existence check; keep the subsequent loop over
testSuitePatterns and return true on either match, otherwise false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/db/suites.go`:
- Around line 129-139: The fallback read branch after a failed FirstOrCreate
currently always logs the original error and returns nil even when the fallback
read succeeds; update the logic in pkg/db/suites.go (the block handling
result.Error from FirstOrCreate) so that if the fallback read (read :=
db.Where("name = ?", name).First(&suite)) has no error you validate/return the
found suite (or its ID) instead of falling through to the error return; only
call log.WithError(result.Error).Errorf(...) and return nil when read.Error !=
nil, otherwise proceed to return the successful suite (use the existing suite
variable and its ID/result as the normal success path).

---

Nitpick comments:
In `@pkg/db/suites.go`:
- Around line 106-122: Replace the linear scan over testSuites in
isSuiteImportable with an O(1) lookup by creating a package-level set
(map[string]struct{}) initialized once from testSuites (e.g., testSuitesSet) and
then check membership via an existence check; keep the subsequent loop over
testSuitePatterns and return true on either match, otherwise false.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 41385948-6309-4e3e-9669-d7ef47541501

📥 Commits

Reviewing files that changed from the base of the PR and between fe7f247 and 0a9e790.

📒 Files selected for processing (1)
  • pkg/db/suites.go

Comment thread pkg/db/suites.go
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 29, 2026

@coderabbitai[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/db/suites.go (1)

106-122: Consider using a set for O(1) lookup on testSuites.

The current linear scan through testSuites is fine for ~50 items, but if this list grows or isSuiteImportable is called frequently in hot paths, a map[string]struct{} initialized once would provide O(1) lookups.

♻️ Optional optimization
var testSuitesSet = func() map[string]struct{} {
  set := make(map[string]struct{}, len(testSuites))
  for _, s := range testSuites {
  	set[s] = struct{}{}
  }
  return set
}()

func isSuiteImportable(name string) bool {
  if _, ok := testSuitesSet[name]; ok {
  	return true
  }
  for _, re := range testSuitePatterns {
  	if re.MatchString(name) {
  		return true
  	}
  }
  return false
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/db/suites.go` around lines 106 - 122, Replace the linear scan over
testSuites in isSuiteImportable with an O(1) lookup by creating a package-level
set (map[string]struct{}) initialized once from testSuites (e.g., testSuitesSet)
and then check membership via an existence check; keep the subsequent loop over
testSuitePatterns and return true on either match, otherwise false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/db/suites.go`:
- Around line 129-139: The fallback read branch after a failed FirstOrCreate
currently always logs the original error and returns nil even when the fallback
read succeeds; update the logic in pkg/db/suites.go (the block handling
result.Error from FirstOrCreate) so that if the fallback read (read :=
db.Where("name = ?", name).First(&suite)) has no error you validate/return the
found suite (or its ID) instead of falling through to the error return; only
call log.WithError(result.Error).Errorf(...) and return nil when read.Error !=
nil, otherwise proceed to return the successful suite (use the existing suite
variable and its ID/result as the normal success path).

---

Nitpick comments:
In `@pkg/db/suites.go`:
- Around line 106-122: Replace the linear scan over testSuites in
isSuiteImportable with an O(1) lookup by creating a package-level set
(map[string]struct{}) initialized once from testSuites (e.g., testSuitesSet) and
then check membership via an existence check; keep the subsequent loop over
testSuitePatterns and return true on either match, otherwise false.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 41385948-6309-4e3e-9669-d7ef47541501

📥 Commits

Reviewing files that changed from the base of the PR and between fe7f247 and 0a9e790.

📒 Files selected for processing (1)
  • pkg/db/suites.go

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

Comment thread pkg/db/suites.go
Comment thread pkg/db/suites.go Outdated
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 1, 2026

@neisw: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label May 1, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 1, 2026

@coderabbitai[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 1, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: coderabbitai[bot], neisw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants