Skip to content

ROX-40167: Use bounded probes for store existence checks - #24515

Open
dashrews78 wants to merge 2 commits into
masterfrom
dashrews/rox-40167-bounded-exists
Open

dashrews78 wants to merge 2 commits into
masterfrom
dashrews/rox-40167-bounded-exists

Conversation

@dashrews78

@dashrews78 dashrews78 commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds an EXISTS query type and RunExistsRequestForSchema so genericStore.Exists issues select exists(select 1 from ...), and adds a SELECT EXISTS-backed Exists(ctx) to the singleton store template. Singleton bindings are regenerated. This lets ROX-37929 switch callers without touching generated code.

Caveat: a single-ID count on a primary-key index is already cheap; the gain is architectural — no dependency on SEARCH's select/group-by/pagination machinery, a reusable existence primitive, and clearer SQL.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

  • go build and go vet pass on all affected packages.
  • go test ./pkg/search/postgres passes, including the new TestExistsQuery (asserts select exists(, no count(, no limit).
  • make go-generated-srcs produces no diff beyond the committed generated files.
  • Generated sql_integration tests compile; not executed locally (no Postgres).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Storage checks can now report whether notification schedules, configuration, delegated registry settings, installation details, and encryption settings are present.
  • Improvements
    • Search-based existence checks now use dedicated existence queries instead of counting matching results.
  • Bug Fixes
    • Existence checks return “not present” when access is restricted, and work with transaction-based operations.

PostgreSQL singleton stores and their generator template add an Exists method. PostgreSQL search adds an EXISTS query type and runner, and genericStore.Exists delegates to that runner instead of counting matches.

Changes: PostgreSQL existence checks

Layer / File(s) Summary
Singleton store existence methods
central/apitoken/.../schedulestore/postgres/store.go, central/apitoken/.../schedulestore/postgres/store_test.go, central/config/store/postgres/store.go, central/config/store/postgres/store_test.go, central/delegatedregistryconfig/store/postgres/store.go, central/delegatedregistryconfig/store/postgres/store_test.go, central/installation/store/postgres/store.go, central/installation/store/postgres/store_test.go, central/notifier/encconfig/datastore/store/postgres/store.go, central/notifier/encconfig/datastore/store/postgres/store_test.go, tools/generate-helpers/pg-table-bindings/singleton.go.tpl, tools/generate-helpers/pg-table-bindings/singleton_test.go.tpl
The stores and generator template add Exists(ctx) (bool, error) methods. The implementations check read access and retry existence queries. Tests cover empty and populated stores, deletion, denied access, and transaction contexts.
Search existence query support
pkg/search/postgres/common.go, pkg/search/postgres/querytype_string.go, pkg/search/postgres/store.go, pkg/search/postgres/common_test.go
The search package adds an EXISTS query type and RunExistsRequestForSchema. SQL generation uses select exists(...) without ordering or pagination for existence checks. genericStore.Exists delegates to the runner instead of counting matches.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant genericStore
  participant RunExistsRequestForSchema
  participant PostgreSQL
  genericStore->>RunExistsRequestForSchema: Run existence request
  RunExistsRequestForSchema->>PostgreSQL: Execute EXISTS query
  PostgreSQL-->>RunExistsRequestForSchema: Return boolean result
  RunExistsRequestForSchema-->>genericStore: Return result or error
Loading

Suggested reviewers: ajheflin, alexvulaj

Merge Risk: Minimal · previous review 4fe02

This change makes existence checks cheaper by using a bounded EXISTS query, and it adds Exists to the singleton stores. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the ticket and the main change: store existence checks now use bounded probes. The changeset replaces the count-based generic store Exists with a bounded EXISTS query path and adds Exi…
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.
Description check Passed The description covers the main change: an EXISTS query type, RunExistsRequestForSchema, and a SELECT EXISTS-backed Exists(ctx) on the singleton store template, with a stated rationale. It also gives …
Full details: Title check

Explanation

The title names the ticket and the main change: store existence checks now use bounded probes. The changeset replaces the count-based generic store Exists with a bounded EXISTS query path and adds Exists to singleton stores. The title is specific and matches the primary change, though it uses a ticket prefix and the term 'bounded probes' is somewhat jargon-heavy.

Full details: Description check

Explanation

The description covers the main change: an EXISTS query type, RunExistsRequestForSchema, and a SELECT EXISTS-backed Exists(ctx) on the singleton store template, with a stated rationale. It also gives validation steps (go build, go vet, go test for pkg/search/postgres, make go-generated-srcs) and notes that the sql_integration tests were compiled but not run. Gaps: the Description section does not summarize the change in the template's detail, and the 'Automated testing' and 'How I validated' sections mention TestExistsQuery, which asserts 'select exists(' with no 'count(' or 'limit', but the author did not tick 'CI results are inspected'. The CHANGELOG and documentation checkboxes are both ticked, but no CHANGELOG link or documentation PR is given. The 'modified existing tests' box is ticked and matches the test changes in the summary. The description does not mention that the singleton store test changes were not executed against Postgres. The PR objectives describe the change as a bounded limit-1 search for generic stores, and the description does not match that: it says genericStore.Exists now issues select exists, which the raw summary confirms. The objectives also name TestExistsQueryIsBounded, while the description and summary name TestExistsQuery, so the test name is inconsistent between the two. The description is mostly complete, so this check passes, but the author should fix the test name mismatch and the unticked CI box.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 298207d9-484d-45a0-9556-e036dd4cb806
Commits

Reviewing files that changed from the base of the PR and between d4af8d8 and 4fe0284.

Files selected for processing: 4

  • pkg/search/postgres/common.go
  • pkg/search/postgres/common_test.go
  • pkg/search/postgres/querytype_string.go
  • pkg/search/postgres/store.go

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit 13ea1f4. To use with deploy scripts:

export MAIN_IMAGE_TAG=5.1.x-783-g13ea1f4bfb

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.88889% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.51%. Comparing base (4760653) to head (13ea1f4).

Files with missing lines Patch % Lines
pkg/search/postgres/common.go 62.50% 5 Missing and 4 partials ⚠️
...datastore/internal/schedulestore/postgres/store.go 84.61% 1 Missing and 1 partial ⚠️
central/config/store/postgres/store.go 84.61% 1 Missing and 1 partial ⚠️
...al/delegatedregistryconfig/store/postgres/store.go 84.61% 1 Missing and 1 partial ⚠️
central/installation/store/postgres/store.go 84.61% 1 Missing and 1 partial ⚠️
...tifier/encconfig/datastore/store/postgres/store.go 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #24515      +/-   ##
==========================================
- Coverage   53.54%   53.51%   -0.03%     
==========================================
  Files        2700     2700              
  Lines      173382   173470      +88     
==========================================
+ Hits        92833    92836       +3     
- Misses      72603    72657      +54     
- Partials     7946     7977      +31     
Flag Coverage Δ
go-unit-tests 53.51% <78.88%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dashrews78 and others added 2 commits December 4, 2026 13:13
Replaces the count-based genericStore.Exists with a limit-1 primary-key search and adds a SELECT EXISTS-backed Exists to the singleton store template, regenerating the bindings. Partially generated by AI; prompted by "I don't want the generation stuff in 37929. So we should probably do 40167 first".

Co-Authored-By: Claude Code <noreply@anthropic.com>
Adds an EXISTS query type and RunExistsRequestForSchema so genericStore.Exists issues select exists(...) instead of a search or count. Partially generated by AI; prompted by "I would rather do it once, so lets do that in this PR".

Co-Authored-By: Claude Code <noreply@anthropic.com>
@dashrews78
dashrews78 force-pushed the dashrews/rox-40167-bounded-exists branch from 4fe0284 to 13ea1f4 Compare December 4, 2026 18:14
@openshift-ci

openshift-ci Bot commented Dec 4, 2026

Copy link
Copy Markdown

@dashrews78: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-operator-e2e-tests 13ea1f4 link false /test gke-operator-e2e-tests
ci/prow/gke-qa-e2e-tests 13ea1f4 link false /test gke-qa-e2e-tests
ci/prow/gke-ui-e2e-tests 13ea1f4 link true /test gke-ui-e2e-tests
ci/prow/ocp-4-22-qa-e2e-tests 13ea1f4 link false /test ocp-4-22-qa-e2e-tests
ci/prow/ocp-4-22-operator-e2e-tests 13ea1f4 link false /test ocp-4-22-operator-e2e-tests
ci/prow/ocp-4-22-nongroovy-e2e-tests 13ea1f4 link false /test ocp-4-22-nongroovy-e2e-tests
ci/prow/ocp-next-candidate-qa-e2e-tests 13ea1f4 link false /test ocp-next-candidate-qa-e2e-tests
ci/prow/ocp-next-candidate-operator-e2e-tests 13ea1f4 link false /test ocp-next-candidate-operator-e2e-tests
ci/prow/ocp-next-candidate-nongroovy-e2e-tests 13ea1f4 link false /test ocp-next-candidate-nongroovy-e2e-tests

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.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant