From 8600e0929b39fbb88bedfb564c30fe4998a6a53e Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Wed, 17 Jul 2024 18:42:46 +0200 Subject: dashboard/app: linkify subsystems coverage --- dashboard/app/graphs.go | 16 +++++++++++++++- dashboard/app/main.go | 1 + pkg/cover/heatmap.go | 42 +++++++++++++++++++++++++++++++++++------- tools/syz-cover/syz-cover.go | 2 +- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/dashboard/app/graphs.go b/dashboard/app/graphs.go index 7922d91ca..4b64829ed 100644 --- a/dashboard/app/graphs.go +++ b/dashboard/app/graphs.go @@ -191,6 +191,14 @@ func handleFoundBugsGraph(c context.Context, w http.ResponseWriter, r *http.Requ } func handleCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error { + return handleHeatmap(c, w, r, "dir") +} + +func handleSubsystemsCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error { + return handleHeatmap(c, w, r, "subsystems") +} + +func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, heatmapType string) error { hdr, err := commonHeader(c, r, w, "") if err != nil { return err @@ -199,7 +207,13 @@ func handleCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Req dateTo := civil.DateOf(time.Now()) var style template.CSS var body, js template.HTML - if style, body, js, err = cover.DoHeatMapStyleBodyJS("syzkaller", hdr.Namespace, dateFrom, dateTo); err != nil { + f := cover.DoHeatMapStyleBodyJS + switch heatmapType { + case "dir": + case "subsystems": + f = cover.DoSubsystemsHeatMapStyleBodyJS + } + if style, body, js, err = f("syzkaller", hdr.Namespace, dateFrom, dateTo); err != nil { return fmt.Errorf("failed to generate heatmap: %w", err) } return serveTemplate(w, "custom_content.html", struct { diff --git a/dashboard/app/main.go b/dashboard/app/main.go index b3b8a4d8e..21530c67c 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -67,6 +67,7 @@ func initHTTPHandlers() { if nsConfig.Coverage != nil { http.Handle("/"+ns+"/graph/coverage", handlerWrapper(handleCoverageGraph)) http.Handle("/"+ns+"/graph/coverage_heatmap", handlerWrapper(handleCoverageHeatmap)) + http.Handle("/"+ns+"/graph/coverage_subsystems_heatmap", handlerWrapper(handleSubsystemsCoverageHeatmap)) } http.Handle("/"+ns+"/repos", handlerWrapper(handleRepos)) http.Handle("/"+ns+"/bug-summaries", handlerWrapper(handleBugSummaries)) diff --git a/pkg/cover/heatmap.go b/pkg/cover/heatmap.go index 9a38a0ef8..b6c21295d 100644 --- a/pkg/cover/heatmap.go +++ b/pkg/cover/heatmap.go @@ -10,7 +10,6 @@ import ( "fmt" "html/template" "io" - "log" "sort" "strings" @@ -174,12 +173,28 @@ where return res, nil } -func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error { - style, body, js, err := DoHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo) +func DoDirHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error { + return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "dir") +} + +func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error { + return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "subsystems") +} + +func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date, hmType string) error { + var style template.CSS + var body, js template.HTML + var err error + f := DoHeatMapStyleBodyJS + switch hmType { + case "dir": + case "subsystems": + f = DoSubsystemsHeatMapStyleBodyJS + } + style, body, js, err = f(projectID, ns, dateFrom, dateTo) if err != nil { - return fmt.Errorf("failed to DoHeatMapStyleAndBody() %w", err) + return fmt.Errorf("failed to get heatMapStyleBodyJS() %w", err) } - log.Printf("%s", js) return heatmapTemplate.Execute(w, struct { Style template.CSS Body template.HTML @@ -213,7 +228,8 @@ func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date, template.HTML(js.Bytes()), nil } -func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error { +func DoSubsystemsHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date, +) (template.CSS, template.HTML, template.HTML, error) { covWithDetails, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo) if err != nil { panic(err) @@ -231,7 +247,19 @@ func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civ } } templateData := filesCoverageToTemplateData(ssCovAndDates) - return heatmapTemplate.Execute(w, templateData) + var styles, body, js bytes.Buffer + if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templateData); err != nil { + return "", "", "", fmt.Errorf("failed to get styles: %w", err) + } + if err := heatmapTemplate.ExecuteTemplate(&body, "body", templateData); err != nil { + return "", "", "", fmt.Errorf("failed to get body: %w", err) + } + if err := heatmapTemplate.ExecuteTemplate(&js, "js", templateData); err != nil { + return "", "", "", fmt.Errorf("failed to get js: %w", err) + } + return template.CSS(styles.String()), + template.HTML(body.String()), + template.HTML(js.Bytes()), nil } func approximateInstrumented(points int64) string { diff --git a/tools/syz-cover/syz-cover.go b/tools/syz-cover/syz-cover.go index 1f0550238..ce08edef9 100644 --- a/tools/syz-cover/syz-cover.go +++ b/tools/syz-cover/syz-cover.go @@ -68,7 +68,7 @@ func toolBuildNsHeatmap() { } switch *flagNsHeatmapGroupBy { case "dir": - if err = cover.DoHeatMap(buf, *flagProjectID, *flagNsHeatmap, dateFrom, dateTo); err != nil { + if err = cover.DoDirHeatMap(buf, *flagProjectID, *flagNsHeatmap, dateFrom, dateTo); err != nil { tool.Fail(err) } case "subsystem": -- cgit mrf-deployment