From fd4747de6d11bca0d9cf837a7c6e78e30e66104d Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Thu, 11 Jul 2024 17:36:29 -0400 Subject: [PATCH] Risk Analysis: ensure Test ID is populated --- pkg/api/job_runs.go | 10 +++++++++- pkg/api/tests.go | 5 ++--- pkg/db/query/test_queries.go | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/api/job_runs.go b/pkg/api/job_runs.go index 77cd2eb72c..686ad46618 100644 --- a/pkg/api/job_runs.go +++ b/pkg/api/job_runs.go @@ -528,9 +528,17 @@ func runTestRunAnalysis(failedTest models.ProwJobRunTest, jobRun *models.ProwJob return apitype.ProwJobRunTestRiskAnalysis{}, errJobNames } + // one of our data sources should have the test ID + testID := failedTest.Test.ID + if testID == 0 && testResultsJobNames != nil { + testID = uint(testResultsJobNames.ID) + } + if testID == 0 && testResultsVariants != nil { + testID = uint(testResultsVariants.ID) + } analysis := apitype.ProwJobRunTestRiskAnalysis{ Name: failedTest.Test.Name, - TestID: failedTest.Test.ID, + TestID: testID, OpenBugs: failedTest.Test.Bugs, } // Watch out for tests that ran in previous period, but not current, no sense comparing to 0 runs: diff --git a/pkg/api/tests.go b/pkg/api/tests.go index 34e9cb3f5f..8f0d2c7050 100644 --- a/pkg/api/tests.go +++ b/pkg/api/tests.go @@ -195,7 +195,7 @@ func BuildTestsResults(dbc *db.DB, release, period string, collapse, includeOver // Collapse groups the test results together -- otherwise we return the test results per-variant combo (NURP+) variantSelect := "" if collapse { - rawQuery = rawQuery.Select(`name,watchlist,jira_component,jira_component_id,` + query.QueryTestSummer).Group("name,watchlist,jira_component,jira_component_id") + rawQuery = rawQuery.Select(`id,name,watchlist,jira_component,jira_component_id,` + query.QueryTestSummer).Group("id,name,watchlist,jira_component,jira_component_id") } else { rawQuery = query.TestsByNURPAndStandardDeviation(dbc, release, table) variantSelect = "suite_name, variants," + @@ -210,9 +210,8 @@ func BuildTestsResults(dbc *db.DB, release, period string, collapse, includeOver } testReports := make([]apitype.Test, 0) - // FIXME: Add test id to matview, for now generate with ROW_NUMBER OVER processedResults := dbc.DB.Table("(?) as results", rawQuery). - Select(`ROW_NUMBER() OVER() as id, watchlist, name, jira_component, jira_component_id,` + variantSelect + query.QueryTestSummarizer). + Select(`id, watchlist, name, jira_component, jira_component_id,` + variantSelect + query.QueryTestSummarizer). Where("current_runs > 0 or previous_runs > 0") finalResults := dbc.DB.Table("(?) as final_results", processedResults) diff --git a/pkg/db/query/test_queries.go b/pkg/db/query/test_queries.go index 9ccdc14ae8..e6c9f25a01 100644 --- a/pkg/db/query/test_queries.go +++ b/pkg/db/query/test_queries.go @@ -55,7 +55,7 @@ const ( QueryTestSummarizer = QueryTestFields + "," + QueryTestPercentages - QueryTestAnalysis = "select current_successes, current_runs, current_successes * 100.0 / NULLIF(current_runs, 0) AS current_pass_percentage from ( select sum(runs) as current_runs, sum(passes) as current_successes from prow_test_analysis_by_job_14d_matview where test_name = '%s' AND job_name in (%s))t" + QueryTestAnalysis = "select test_id as id, current_successes, current_runs, current_successes * 100.0 / NULLIF(current_runs, 0) AS current_pass_percentage from ( select test_id, sum(runs) as current_runs, sum(passes) as current_successes from prow_test_analysis_by_job_14d_matview where test_name = '%s' AND job_name in (%s) GROUP BY test_id)t" ) // TestReportsByVariant returns a test report for every test in the db matching the given substrings, separated by variant.