diff --git a/pkg/db/postgres.go b/pkg/db/postgres.go index 3a9baed..b33375a 100644 --- a/pkg/db/postgres.go +++ b/pkg/db/postgres.go @@ -312,13 +312,15 @@ func (m *Postgres) GetEnvCharts(env string, testsInTop int) (map[string]interfac LIMIT 1 ), temp AS ( SELECT TestName, + SUM(CASE WHEN Result = 'fail' AND TestTime > (SELECT Date FROM recentCutoff) THEN 1 ELSE 0 END) As FailedTestNum, + SUM(CASE WHEN TestTime > (SELECT Date FROM recentCutoff) THEN 1 ELSE 0 END) As TotalTestNum, ROUND(COALESCE(AVG(CASE WHEN TestTime > (SELECT Date FROM recentCutoff) THEN CASE WHEN Result = 'fail' THEN 1 ELSE 0 END END) * 100, 0), 2) AS RecentFlakePercentage, ROUND(COALESCE(AVG(CASE WHEN TestTime <= (SELECT Date FROM recentCutoff) AND TestTime > (SELECT Date FROM prevCutoff) THEN CASE WHEN Result = 'fail' THEN 1 ELSE 0 END END) * 100, 0), 2) AS PrevFlakePercentage FROM %s GROUP BY TestName ORDER BY RecentFlakePercentage DESC ) - SELECT TestName, RecentFlakePercentage, RecentFlakePercentage - PrevFlakePercentage AS GrowthRate + SELECT TestName, RecentFlakePercentage, RecentFlakePercentage - PrevFlakePercentage AS GrowthRate, FailedTestNum, TotalTestNum FROM temp ORDER BY RecentFlakePercentage DESC; `, viewName, viewName) diff --git a/pkg/handler/flake_chart.html b/pkg/handler/flake_chart.html index 5e6784c..bd3039b 100644 --- a/pkg/handler/flake_chart.html +++ b/pkg/handler/flake_chart.html @@ -132,13 +132,15 @@ for (let i = 0; i < recentFlakePercentTable.length; i++) { const { testName, + failedTestNum, + totalTestNum, recentFlakePercentage, growthRate } = recentFlakePercentTable[i]; const row = document.createElement("tr"); row.appendChild(createCell("td", "" + (i + 1))).style.textAlign = "center"; row.appendChild(createCell("td", `${testName}`)); - row.appendChild(createCell("td", recentFlakePercentage + "%")).style.textAlign = "right"; + row.appendChild(createCell("td", recentFlakePercentage + "% (" + failedTestNum + "/" + totalTestNum + ")")).style.textAlign = "right"; row.appendChild(createCell("td", ` 0 ? "red" : "green")}">${growthRate > 0 ? '+' + growthRate : growthRate}%`)); tableBody.appendChild(row); } diff --git a/pkg/models/models.go b/pkg/models/models.go index 9e051aa..1a1c723 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -61,6 +61,8 @@ type DBFlakeRow struct { TestName string `json:"testName"` RecentFlakePercentage float32 `json:"recentFlakePercentage"` GrowthRate float32 `json:"growthRate"` + FailedTestNum float32 `json:"failedTestNum"` + TotalTestNum float32 `json:"totalTestNum"` } // DBFlakeBy represents a "row" in the flake rate by _ of top 10 of recent test flakiness charts