Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add coverage->sybsystems_coverage menu #5066

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions dashboard/app/graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,18 @@ func handleFoundBugsGraph(c context.Context, w http.ResponseWriter, r *http.Requ
return serveTemplate(w, "graph_histogram.html", data)
}

type funcStyleBodyJS func(projectID string, ns string, dateFrom civil.Date, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error)

func handleCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error {
return handleHeatmap(c, w, r, cover.DoHeatMapStyleBodyJS)
}

func handleSubsystemsCoverageHeatmap(c context.Context, w http.ResponseWriter, r *http.Request) error {
return handleHeatmap(c, w, r, cover.DoSubsystemsHeatMapStyleBodyJS)
}

func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, f funcStyleBodyJS) error {
hdr, err := commonHeader(c, r, w, "")
if err != nil {
return err
Expand All @@ -199,19 +210,19 @@ 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 {
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 {
Header *uiHeader
Style template.CSS
Body template.HTML
JS template.HTML
*cover.StyleBodyJS
}{
Header: hdr,
Style: style,
Body: body,
JS: js,
StyleBodyJS: &cover.StyleBodyJS{
Style: style,
Body: body,
JS: js,
},
})
}

Expand Down
1 change: 1 addition & 0 deletions dashboard/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion dashboard/app/templates/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ <h1><a href="/{{$.Namespace}}">syzbot</a></h1>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage">Total</a>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage_heatmap" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage_heatmap">Heatmap</a>
href="/{{$.Namespace}}/graph/coverage_heatmap">Repo Heatmap</a>
<a class="navigation_tab{{if eq .URLPath (printf "/%v/graph/coverage_subsystems_heatmap" $.Namespace)}}_selected{{end}}"
href="/{{$.Namespace}}/graph/coverage_subsystems_heatmap">Subsystems Heatmap</a>
</div>
</div>
{{end}}
Expand Down
62 changes: 41 additions & 21 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"html/template"
"io"
"log"
"sort"
"strings"

Expand Down Expand Up @@ -174,46 +173,67 @@ where
return res, nil
}

func DoHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
type StyleBodyJS struct {
Style template.CSS
Body template.HTML
JS template.HTML
}

// nolint: dupl
func DoDirHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
style, body, js, err := DoHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return fmt.Errorf("failed to DoHeatMapStyleAndBody() %w", err)
}
log.Printf("%s", js)
return heatmapTemplate.Execute(w, struct {
Style template.CSS
Body template.HTML
JS template.HTML
}{
return fmt.Errorf("failed to DoHeatMapStyleBodyJS() %w", err)
}
return heatmapTemplate.Execute(w, &StyleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error) {
covAndDates, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo)
// nolint: dupl
func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
style, body, js, err := DoSubsystemsHeatMapStyleBodyJS(projectID, ns, dateFrom, dateTo)
if err != nil {
return "", "", "", fmt.Errorf("failed to filesCoverageWithDetails: %w", err)
return fmt.Errorf("failed to DoSubsystemsHeatMapStyleBodyJS() %w", err)
}
templateData := filesCoverageToTemplateData(covAndDates)
return heatmapTemplate.Execute(w, &StyleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

func stylesBodyJSTemplate(templData *templateHeatmap,
) (template.CSS, template.HTML, template.HTML, error) {
var styles, body, js bytes.Buffer
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&styles, "style", templData); err != nil {
return "", "", "", fmt.Errorf("failed to get styles: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&body, "body", templData); err != nil {
return "", "", "", fmt.Errorf("failed to get body: %w", err)
}
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templateData); err != nil {
if err := heatmapTemplate.ExecuteTemplate(&js, "js", templData); 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 DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
) (template.CSS, template.HTML, template.HTML, error) {
covAndDates, err := filesCoverageWithDetails(context.Background(), projectID, ns, dateFrom, dateTo)
if err != nil {
return "", "", "", fmt.Errorf("failed to filesCoverageWithDetails: %w", err)
}
templData := filesCoverageToTemplateData(covAndDates)
return stylesBodyJSTemplate(templData)
}

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)
Expand All @@ -230,8 +250,8 @@ func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civ
ssCovAndDates = append(ssCovAndDates, &newRecord)
}
}
templateData := filesCoverageToTemplateData(ssCovAndDates)
return heatmapTemplate.Execute(w, templateData)
templData := filesCoverageToTemplateData(ssCovAndDates)
return stylesBodyJSTemplate(templData)
}

func approximateInstrumented(points int64) string {
Expand Down
2 changes: 1 addition & 1 deletion tools/syz-cover/syz-cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Loading