diff --git a/syz-cluster/dashboard/handler.go b/syz-cluster/dashboard/handler.go index 2212bd959f38..42fad9bbe33d 100644 --- a/syz-cluster/dashboard/handler.go +++ b/syz-cluster/dashboard/handler.go @@ -218,6 +218,7 @@ func (h *dashboardHandler) statsPage(w http.ResponseWriter, r *http.Request) err type StatsPageData struct { Processed []*db.CountPerWeek Findings []*db.CountPerWeek + Reports []*db.CountPerWeek Delay []*db.DelayPerWeek Distribution []*db.StatusPerWeek } @@ -231,6 +232,10 @@ func (h *dashboardHandler) statsPage(w http.ResponseWriter, r *http.Request) err if err != nil { return fmt.Errorf("failed to query findings data: %w", err) } + data.Reports, err = h.statsRepo.ReportsPerWeek(r.Context()) + if err != nil { + return fmt.Errorf("failed to query reports data: %w", err) + } data.Delay, err = h.statsRepo.DelayPerWeek(r.Context()) if err != nil { return fmt.Errorf("failed to query delay data: %w", err) @@ -388,6 +393,9 @@ func errToStatus(f func(http.ResponseWriter, *http.Request) error) http.HandlerF } else if errors.Is(err, errBadRequest) { http.Error(w, err.Error(), http.StatusBadRequest) } else if err != nil { + // TODO: if the error happened in the template, likely we've already printed + // something to w. Unless we're in streamBlob(), it makes sense to first collect + // the output in some buffer and only dump it after the exit from the handler. http.Error(w, err.Error(), http.StatusInternalServerError) } } diff --git a/syz-cluster/dashboard/handler_test.go b/syz-cluster/dashboard/handler_test.go index a1200582edfa..8bdb5c318226 100644 --- a/syz-cluster/dashboard/handler_test.go +++ b/syz-cluster/dashboard/handler_test.go @@ -26,7 +26,11 @@ func TestURLs(t *testing.T) { handler, baseURL := testServer(t, env) urlGen := api.NewURLGenerator(baseURL) - urls := []string{urlGen.Series(ids.SeriesID)} + urls := []string{ + baseURL, + baseURL + "/stats", + urlGen.Series(ids.SeriesID), + } for _, buildID := range []string{ids.BaseBuildID, ids.PatchedBuildID} { urls = append(urls, urlGen.BuildConfig(buildID)) urls = append(urls, urlGen.BuildLog(buildID)) diff --git a/syz-cluster/dashboard/templates/graphs.html b/syz-cluster/dashboard/templates/graphs.html index e972b81caa84..c4da3289f28d 100644 --- a/syz-cluster/dashboard/templates/graphs.html +++ b/syz-cluster/dashboard/templates/graphs.html @@ -18,6 +18,15 @@

Findings (weekly)


+
+

Reports (weekly)

+

How many reports with findings have been published.

+
+

Click and drag to zoom into a time range. Right-click to reset.

+
+ +
+

Wait Time before Fuzzing (avg hours, weekly)

How many hours have passed since the moment the series was published and the moment we started fuzzing it.

@@ -67,9 +76,16 @@

Status Distribution (weekly)

{{end}} ]; + const reportsData = [ + {{range .Reports}} + [new Date({{.Date.Format "2006-01-02"}}), {{.Count}}], + {{end}} + ]; + function drawAllCharts() { drawChart('processed_chart_div', processedData, '#007bff'); drawChart('findings_chart_div', findingsData, '#dc3545'); + drawChart('reports_chart_div', reportsData, '#dc3545'); drawChart('avg_wait_chart_div', delayData, 'black'); drawDistributionChart(); } diff --git a/syz-cluster/pkg/db/stats_repo.go b/syz-cluster/pkg/db/stats_repo.go index 7604df15986e..588945b3b731 100644 --- a/syz-cluster/pkg/db/stats_repo.go +++ b/syz-cluster/pkg/db/stats_repo.go @@ -39,6 +39,20 @@ ORDER BY Date`, }) } +func (repo *StatsRepository) ReportsPerWeek(ctx context.Context) ( + []*CountPerWeek, error) { + return readEntities[CountPerWeek](ctx, repo.client.Single(), spanner.Statement{ + SQL: `SELECT + TIMESTAMP_TRUNC(SessionReports.ReportedAt, WEEK) as Date, + COUNT(*) as Count +FROM Findings +JOIN SessionReports ON SessionReports.SessionID = Findings.SessionID +WHERE SessionReports.Moderation = FALSE AND SessionReports.ReportedAt IS NOT NULL +GROUP BY Date +ORDER BY Date`, + }) +} + func (repo *StatsRepository) FindingsPerWeek(ctx context.Context) ( []*CountPerWeek, error) { return readEntities[CountPerWeek](ctx, repo.client.Single(), spanner.Statement{ diff --git a/syz-cluster/pkg/db/stats_repo_test.go b/syz-cluster/pkg/db/stats_repo_test.go index ce2b05ca92f7..18f774710c1c 100644 --- a/syz-cluster/pkg/db/stats_repo_test.go +++ b/syz-cluster/pkg/db/stats_repo_test.go @@ -25,6 +25,8 @@ func TestStatsSQLs(t *testing.T) { assert.NoError(t, err) _, err = statsRepo.DelayPerWeek(ctx) assert.NoError(t, err) + _, err = statsRepo.ReportsPerWeek(ctx) + assert.NoError(t, err) } dtd := &dummyTestData{t, ctx, client}