Skip to content

TRT-2737: Rewrite test analysis queries to use test_daily_summaries#3747

Open
mstaeble wants to merge 1 commit into
openshift:mainfrom
mstaeble:trt-2737-phase1-consumer-rewrite
Open

TRT-2737: Rewrite test analysis queries to use test_daily_summaries#3747
mstaeble wants to merge 1 commit into
openshift:mainfrom
mstaeble:trt-2737-phase1-consumer-rewrite

Conversation

@mstaeble

@mstaeble mstaeble commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rewrites all 4 test analysis consumers to query test_daily_summaries directly instead of test_analysis_by_job_by_dates, using variant_combination_id for efficient variant filtering through variant_combinations
  • Removes the prow_test_analysis_by_variant_14d_view (a regular view with a single consumer, inlined into Go code)
  • The test_analysis_by_job_by_dates table and its BQ loader are kept running for now and will be removed in a follow-up PR once the new queries are verified in production

Benchmark results (staging, warmed, release 4.19)

Consumer Before After
Overall (C1) 32ms 15ms
By Job (C2) 23ms 22ms
By Variant (C3) 41.5s 33ms
Pass Rate (C4) 20ms 11ms

The variant endpoint (/api/tests/analysis/variants) improves from 41.5s to 33ms because it now joins the small variant_combinations table via integer FK instead of scanning prow_jobs via a text-based join on job_name.

Behavioral changes

  1. Date boundary filtering shifts from a sliding timestamp window (NOW() - '14 days'::interval against a TIMESTAMP WITH TIME ZONE column) to calendar-day boundaries (summary_date >= ? against a DATE column). This means the 14-day lookback always includes full calendar days rather than depending on time-of-day. In practice, this may include one additional day of data at the boundary.

  2. Overall analysis now respects reportEnd. Previously, GetTestAnalysisOverallFromDB ignored the reportEnd parameter and always used time.Now(), causing the overall series to drift from the job/variant series on historical (pinned-date) reports. It now uses reportEnd consistently with the other two endpoints.

  3. Variant analysis window aligned to 14 days. The old variant view used a 15-day lookback while the other endpoints used 14 days. All three now use 14 days consistently.

Test plan

  • make lint passes (0 issues)
  • make test passes (Go + JS)
  • make e2e passes (108 tests, 0 failures)
  • go vet ./pkg/... clean
  • Benchmarked all 4 consumer queries on staging with and without variant filters
  • Deployed to sippy-staging, verified all API response times under 5 seconds
  • Independent isolated code review found no bugs

Summary by CodeRabbit

  • New Features

    • Test analysis now uses a unified data source for overall, job, and variant reporting, keeping results more consistent.
    • Variant-based analysis now supports clearer filtering for included and excluded variants.
  • Bug Fixes

    • Improved date-range handling for 14-day variant reports.
    • Updated current run and success totals to better match daily summary data.

@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 commented Jul 8, 2026

Copy link
Copy Markdown

@mstaeble: This pull request references TRT-2737 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Rewrites all 4 test analysis consumers to query test_daily_summaries directly instead of test_analysis_by_job_by_dates, using variant_combination_id for efficient variant filtering through variant_combinations
  • Removes the prow_test_analysis_by_variant_14d_view (a regular view with a single consumer, inlined into Go code)
  • The test_analysis_by_job_by_dates table and its BQ loader are kept running for now and will be removed in a follow-up PR once the new queries are verified in production

Benchmark results (staging, warmed, release 4.19)

Consumer Before After
Overall (C1) 32ms 15ms
By Job (C2) 23ms 22ms
By Variant (C3) 41.5s 33ms
Pass Rate (C4) 20ms 11ms

The variant endpoint (/api/tests/analysis/variants) improves from 41.5s to 33ms because it now joins the small variant_combinations table via integer FK instead of scanning prow_jobs via a text-based join on job_name.

Behavioral changes

  1. Date boundary filtering shifts from a sliding timestamp window (NOW() - '14 days'::interval against a TIMESTAMP WITH TIME ZONE column) to calendar-day boundaries (summary_date >= ? against a DATE column). This means the 14-day lookback always includes full calendar days rather than depending on time-of-day. In practice, this may include one additional day of data at the boundary.

  2. Overall analysis now respects reportEnd. Previously, GetTestAnalysisOverallFromDB ignored the reportEnd parameter and always used time.Now(), causing the overall series to drift from the job/variant series on historical (pinned-date) reports. It now uses reportEnd consistently with the other two endpoints.

  3. Variant analysis window aligned to 14 days. The old variant view used a 15-day lookback while the other endpoints used 14 days. All three now use 14 days consistently.

Test plan

  • make lint passes (0 issues)
  • make test passes (Go + JS)
  • make e2e passes (108 tests, 0 failures)
  • go vet ./pkg/... clean
  • Benchmarked all 4 consumer queries on staging with and without variant filters
  • Deployed to sippy-staging, verified all API response times under 5 seconds
  • Independent isolated code review found no bugs

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.

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 8, 2026
@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@mstaeble, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 6cff3d77-6cd8-48a2-986e-3e3f2ab78543

📥 Commits

Reviewing files that changed from the base of the PR and between 66d90ba and 6db2dee.

📒 Files selected for processing (4)
  • pkg/api/test_analysis.go
  • pkg/api/test_analysis_test.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go

Walkthrough

Test analysis queries are refactored to source data from test_daily_summaries joined with tests and prow_jobs, replacing prior views (test_analysis_by_job_by_dates, prow_test_analysis_by_variant_14d_view). New helpers centralize variant-filter extraction and application via variant_combinations. The corresponding view registration and SQL constants are removed.

Changes

Test analysis query source refactor

Layer / File(s) Summary
Variant filter helpers and overall query
pkg/api/test_analysis.go
Adds extractVariantFilters and applyVariantCombinationFilters helpers, shared aggregate select columns and a base query, and rewrites GetTestAnalysisOverallFromDB to query test_daily_summaries joined with tests.
By-job query rewrite
pkg/api/test_analysis.go
Rewrites GetTestAnalysisByJobFromDB to build on the shared base query, join prow_jobs, and select/group by job fields including variants.
By-variant query rewrite
pkg/api/test_analysis.go
Rewrites GetTestAnalysisByVariantFromDB to derive rows via unnest(vc.variants) from variant_combinations, applying allowed/blocked filters and explicit 14-day date bounds.
Raw SQL query and view cleanup
pkg/db/query/test_queries.go, pkg/db/views.go
Updates QueryTestAnalysis to aggregate from test_daily_summaries/tests/prow_jobs, and removes the prow_test_analysis_by_variant_14d_view registration plus its SQL constant definitions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • openshift/sippy#3698: Both PRs modify the same variant filtering logic in GetTestAnalysisOverallFromDB/GetTestAnalysisByJobFromDB, resolving matches via variant_combinations.

Suggested reviewers: xueqzhan, smg247

🚥 Pre-merge checks | ✅ 19 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Test Coverage For New Features ⚠️ Warning New pure helpers in pkg/api/test_analysis.go have no unit tests, and the query changes are only hit by benchmarks—not regression tests for the variant/query boundary fixes. Add focused unit tests for extractVariantFilters/selectColumns/testAnalysisBaseQuery and regression tests for overall/job/variant query behavior, including variant grouping and date bounds.
Feature Documentation ⚠️ Warning FAIL: The PR changes test analysis data source/window semantics, but docs/features has no corresponding update; the only feature doc is unrelated to symptoms. Add/update a docs/features page for test analysis to document direct test_daily_summaries queries, reportEnd semantics, and the 14-day calendar-day window.
✅ Passed checks (19 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: rewriting test analysis queries to use test_daily_summaries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 No ignored errors, panic, or nil-deref issues were introduced; the new code checks filters for nil and propagates DB errors normally.
Sql Injection Prevention ✅ Passed New/changed test-analysis queries use placeholders and named params for release, test, dates, and variants; only fixed SQL constants and internal timestamps are concatenated.
Excessive Css In React Should Use Styles ✅ Passed No React/JSX files changed; the PR only touches Go backend files, so the inline-CSS check is not applicable.
Single Responsibility And Clear Naming ✅ Passed The new helpers and endpoints stay focused on test-analysis concerns, and the added names are descriptive and context-specific.
Stable And Deterministic Test Names ✅ Passed The PR only changes production SQL/query/view files; no *_test.go files or Ginkgo title strings were added or modified.
Test Structure And Quality ✅ Passed No Ginkgo test files or test blocks were changed; the PR only touches API/DB query code, so the test-structure check is not applicable.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests were added; the PR only changes DB/query/view code, so MicroShift test compatibility is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests were added or modified; the PR only changes API/DB query code and removes a view registration.
Topology-Aware Scheduling Compatibility ✅ Passed Only DB query/view files changed; no deployment manifests, operators, or controllers were modified, so no topology-aware scheduling issue is introduced.
Ote Binary Stdout Contract ✅ Passed Changed files only add query/view helpers; no main/init/TestMain/suite setup or stdout-printing calls were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Diff touches only backend query/view code; no new Ginkgo e2e tests or IPv4/external-network patterns were added.
No-Weak-Crypto ✅ Passed No MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons appear in the changed files.
Container-Privileges ✅ Passed PASS: PR only changes Go query code; changed files are pkg/api/test_analysis.go, pkg/db/query/test_queries.go, and pkg/db/views.go, with no container/K8s manifest or privilege fields touched.
No-Sensitive-Data-In-Logs ✅ Passed No new logging of passwords, tokens, PII, session IDs, hostnames, or customer data was added in the changed files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mstaeble
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@mstaeble

mstaeble commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mstaeble

mstaeble commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 54 minutes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
pkg/api/test_analysis.go (3)

26-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a unit test for extractVariantFilters.

It's pure, branch-heavy logic (nil guard, Not vs allowed/blocked partitioning) that's trivially testable without touching storage. As per coding guidelines, new Go functions should include unit tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/test_analysis.go` around lines 26 - 40, Add unit tests for
extractVariantFilters to cover its pure branching behavior: nil input should
return nil slices, variants items with Not=false should populate allowed, and
variants items with Not=true should populate blocked while ignoring non-variants
fields. Place the tests alongside test_analysis.go and reference
extractVariantFilters and filter.Filter so the cases remain easy to locate if
the implementation changes.

Source: Coding guidelines


80-80: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the repeated 14-day window into a named constant.

reportEnd.Add(-24*14*time.Hour) is duplicated in three call sites; a const testAnalysisWindow = 14 * 24 * time.Hour (or reportEnd.AddDate(0, 0, -14)) is clearer and avoids drift if the window changes.

Also applies to: 113-113, 164-164

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/test_analysis.go` at line 80, The repeated 14-day lookback in the
test analysis query calls should be extracted into a shared named constant or
helper. Update the call sites in testAnalysisBaseQuery usage to reference a
single testAnalysisWindow definition (or use reportEnd.AddDate for the same
intent) so the window value is defined once and reused consistently across the
three locations.

62-64: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rename selectColumns and add a godoc; the name is ambiguous in package api.

selectColumns in a large package reads like a generic accessor, but it actually appends the shared aggregate columns to the supplied ones. A more specific name (e.g. withAggColumns) plus a one-line godoc would make the intent clear and reduce collision risk.

As per path instructions: "Name each function succinctly but accurately indicating its purpose relative to its package or receiver... include a brief godoc if the name alone would not make the purpose obvious."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/api/test_analysis.go` around lines 62 - 64, Rename selectColumns to a
more specific helper name that reflects its behavior of appending the shared
aggregate columns to caller-supplied columns, and add a one-line godoc for the
new name so its purpose is clear in package api; update any call sites in
testAnalysis helpers to use the new symbol.

Source: Path instructions

pkg/db/views.go (1)

89-89: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Orphaned view will persist on existing databases.

With PostgresViews now empty, syncPostgresViews no longer issues DROP VIEW IF EXISTS prow_test_analysis_by_variant_14d_view. Existing databases will retain the stale view, which could confuse direct queries or block future drops of test_analysis_by_job_by_dates. Consider adding a one-time migration to drop it before the follow-up PR removes the underlying table.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/db/views.go` at line 89, The empty PostgresViews slice means
syncPostgresViews will no longer drop the stale
prow_test_analysis_by_variant_14d_view, so existing databases can retain an
orphaned view. Add a one-time migration or startup cleanup that explicitly drops
this view before the underlying table removal, and keep the change localized
around PostgresViews and syncPostgresViews so the old object is removed safely.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/api/test_analysis.go`:
- Around line 152-167: The query built in test_analysis.go’s inner DB chain is
grouping on unnest(vc.variants), which PostgreSQL rejects. Move the variant
expansion into a LATERAL join in the same query builder path, then reference the
unnested alias in Select and Group instead of calling unnest() directly in
Group. Keep the change localized to the inner :=
dbc.DB.Table("test_daily_summaries tds") query and its Join/Group clauses so the
per-variant rows are produced correctly.

---

Nitpick comments:
In `@pkg/api/test_analysis.go`:
- Around line 26-40: Add unit tests for extractVariantFilters to cover its pure
branching behavior: nil input should return nil slices, variants items with
Not=false should populate allowed, and variants items with Not=true should
populate blocked while ignoring non-variants fields. Place the tests alongside
test_analysis.go and reference extractVariantFilters and filter.Filter so the
cases remain easy to locate if the implementation changes.
- Line 80: The repeated 14-day lookback in the test analysis query calls should
be extracted into a shared named constant or helper. Update the call sites in
testAnalysisBaseQuery usage to reference a single testAnalysisWindow definition
(or use reportEnd.AddDate for the same intent) so the window value is defined
once and reused consistently across the three locations.
- Around line 62-64: Rename selectColumns to a more specific helper name that
reflects its behavior of appending the shared aggregate columns to
caller-supplied columns, and add a one-line godoc for the new name so its
purpose is clear in package api; update any call sites in testAnalysis helpers
to use the new symbol.

In `@pkg/db/views.go`:
- Line 89: The empty PostgresViews slice means syncPostgresViews will no longer
drop the stale prow_test_analysis_by_variant_14d_view, so existing databases can
retain an orphaned view. Add a one-time migration or startup cleanup that
explicitly drops this view before the underlying table removal, and keep the
change localized around PostgresViews and syncPostgresViews so the old object is
removed safely.
🪄 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: 6bb75d8f-f170-4449-afb6-40fdec1ca2d3

📥 Commits

Reviewing files that changed from the base of the PR and between 26fa798 and 66d90ba.

📒 Files selected for processing (3)
  • pkg/api/test_analysis.go
  • pkg/db/query/test_queries.go
  • pkg/db/views.go

Comment thread pkg/api/test_analysis.go
Rewrite all 4 test analysis consumers to query test_daily_summaries
directly instead of test_analysis_by_job_by_dates, using
variant_combination_id for efficient variant filtering.

The variant endpoint (/api/tests/analysis/variants) improves from
41.5s to 33ms by joining the small variant_combinations table via
integer FK instead of scanning prow_jobs via text join. The
prow_test_analysis_by_variant_14d_view (a regular view with one
consumer) is removed in favor of an inline query.

Behavioral changes:
- Date filtering uses calendar-day boundaries (DATE column) instead
  of a sliding timestamp window, which may include one additional
  day at the boundary.
- GetTestAnalysisOverallFromDB now respects the reportEnd parameter
  instead of always using time.Now().
- Variant analysis window aligned from 15 days to 14 days,
  consistent with the other two endpoints.

The test_analysis_by_job_by_dates table and its BQ loader are kept
running for now. They will be removed in a follow-up PR once the
new queries are verified in production.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mstaeble mstaeble force-pushed the trt-2737-phase1-consumer-rewrite branch from 66d90ba to 6db2dee Compare July 8, 2026 03:17
@openshift-ci openshift-ci Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Jul 8, 2026
@mstaeble mstaeble marked this pull request as ready for review July 8, 2026 03:24
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2026
@openshift-ci openshift-ci Bot requested review from deads2k and sosiouxme July 8, 2026 03:25
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@mstaeble: 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.

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

Labels

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.

2 participants