Skip to content

Commit

Permalink
dashboard/app: add coverage->subsystems heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
tarasmadan committed Jul 22, 2024
1 parent 0f4c05d commit fa1e22f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 60 deletions.
27 changes: 12 additions & 15 deletions dashboard/app/graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +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, "dir")
return handleHeatmap(c, w, r, cover.DoHeatMapStyleBodyJS)
}

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

func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, heatmapType string) error {
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 @@ -207,25 +210,19 @@ func handleHeatmap(c context.Context, w http.ResponseWriter, r *http.Request, he
dateTo := civil.DateOf(time.Now())
var style template.CSS
var body, js template.HTML
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 {
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
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
80 changes: 36 additions & 44 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,61 +173,65 @@ where
return res, nil
}

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

func DoSubsystemsHeatMap(w io.Writer, projectID, ns string, dateFrom, dateTo civil.Date) error {
return DoHeatMap(w, projectID, ns, dateFrom, dateTo, "subsystems")
// 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 DoHeatMapStyleBodyJS() %w", err)
}
return heatmapTemplate.Execute(w, &StyleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

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)
// 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 get heatMapStyleBodyJS() %w", err)
return fmt.Errorf("failed to DoSubsystemsHeatMapStyleBodyJS() %w", err)
}
return heatmapTemplate.Execute(w, struct {
Style template.CSS
Body template.HTML
JS template.HTML
}{
return heatmapTemplate.Execute(w, &StyleBodyJS{
Style: style,
Body: body,
JS: js,
})
}

func DoHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil.Date,
func stylesBodyJSTemplate(templData *templateHeatmap,
) (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)
}
templateData := filesCoverageToTemplateData(covAndDates)
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 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)
Expand All @@ -246,20 +250,8 @@ func DoSubsystemsHeatMapStyleBodyJS(projectID, ns string, dateFrom, dateTo civil
ssCovAndDates = append(ssCovAndDates, &newRecord)
}
}
templateData := filesCoverageToTemplateData(ssCovAndDates)
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
templData := filesCoverageToTemplateData(ssCovAndDates)
return stylesBodyJSTemplate(templData)
}

func approximateInstrumented(points int64) string {
Expand Down

0 comments on commit fa1e22f

Please sign in to comment.