Skip to content

Commit

Permalink
dashboard: include label message into bug reports
Browse files Browse the repository at this point in the history
  • Loading branch information
a-nogikh committed May 25, 2023
1 parent 6b7e906 commit d608a2a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
4 changes: 4 additions & 0 deletions dashboard/app/mail_bug.txt
Expand Up @@ -40,6 +40,10 @@ bisection log: {{.BisectCause.LogLink}}
Reported-by: {{.CreditEmail}}
{{if .BisectCause}}{{if .BisectCause.Commit}}Fixes: {{formatTagHash .BisectCause.Commit.Hash}} ("{{.BisectCause.Commit.Title}}")
{{end}}{{end}}
{{- range $label, $text := .LabelMessages}}
{{$text}}

{{end}}
{{printf "%s" .Report}}

---
Expand Down
14 changes: 12 additions & 2 deletions dashboard/app/reporting.go
Expand Up @@ -547,6 +547,16 @@ func crashBugReport(c context.Context, bug *Bug, crash *Crash, crashKey *db.Key,
rep.Maintainers = append(rep.Maintainers, mgr.CC.BuildMaintainers...)
}
}
for _, label := range bug.Labels {
text, ok := reporting.Labels[label.String()]
if !ok {
continue
}
if rep.LabelMessages == nil {
rep.LabelMessages = map[string]string{}
}
rep.LabelMessages[label.String()] = text
}
if err := fillBugReport(c, rep, bug, bugReporting, build); err != nil {
return nil, err
}
Expand Down Expand Up @@ -1071,8 +1081,8 @@ func incomingCommandCmd(c context.Context, now time.Time, cmd *dashapi.BugUpdate
if cmd.StatusReason != "" {
bug.StatusReason = cmd.StatusReason
}
if cmd.Label != "" {
bugReporting.AddLabel(cmd.Label)
for _, label := range cmd.Labels {
bugReporting.AddLabel(label)
}
return true, "", nil
}
Expand Down
7 changes: 6 additions & 1 deletion dashboard/app/reporting_email.go
Expand Up @@ -165,6 +165,9 @@ func emailSendBugReport(c context.Context, rep *dashapi.BugReport) error {
} else if len(rep.ReproSyz) != 0 {
cmd.ReproLevel = dashapi.ReproLevelSyz
}
for label := range rep.LabelMessages {
cmd.Labels = append(cmd.Labels, label)
}
ok, reason, err := incomingCommand(c, cmd)
if !ok || err != nil {
return fmt.Errorf("failed to update reported bug: ok=%v reason=%v err=%v", ok, reason, err)
Expand Down Expand Up @@ -253,9 +256,11 @@ func emailSendBugNotif(c context.Context, notif *dashapi.BugNotification) error
ID: notif.ID,
Status: status,
StatusReason: statusReason,
Label: notif.Label,
Notification: true,
}
if notif.Label != "" {
cmd.Labels = []string{notif.Label}
}
ok, reason, err := incomingCommand(c, cmd)
if !ok || err != nil {
return fmt.Errorf("notif update failed: ok=%v reason=%v err=%v", ok, reason, err)
Expand Down
46 changes: 43 additions & 3 deletions dashboard/app/tree_test.go
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/syzkaller/dashboard/dashapi"
"github.com/stretchr/testify/assert"
db "google.golang.org/appengine/v2/datastore"
aemail "google.golang.org/appengine/v2/mail"
)
Expand All @@ -38,6 +39,7 @@ func TestTreeOriginDownstream(t *testing.T) {
results: []treeTestEntryPeriod{{fromDay: 0, result: treeTestOK}},
},
}
ctx.reportToEmail()
ctx.jobTestDays = []int{10}
ctx.moveToDay(10)
ctx.ensureLabels(`origin:downstream`)
Expand All @@ -49,7 +51,6 @@ func TestTreeOriginDownstream(t *testing.T) {
_, err := c.GET(ctx.bugLink())
c.expectEQ(err, nil)
// Test that we receive a notification.
ctx.reportToEmail()
msg := ctx.emailWithoutURLs()
c.expectEQ(msg.Body, `Bug presence analysis results: the bug reproduces only on the downstream tree.
Expand All @@ -71,6 +72,45 @@ More details can be found at:
`)
}

func TestTreeOriginDownstreamEmail(t *testing.T) {
c := NewCtx(t)
defer c.Close()

ctx := setUpTreeTest(c, downstreamUpstreamRepos)
ctx.uploadBug(`https://downstream.repo/repo`, `master`, dashapi.ReproLevelC)
ctx.entries = []treeTestEntry{
{
alias: `downstream`,
results: []treeTestEntryPeriod{{fromDay: 0, result: treeTestCrash}},
},
{
alias: `lts`,
mergeAlias: `downstream`,
results: []treeTestEntryPeriod{{fromDay: 0, result: treeTestOK}},
},
{
alias: `upstream`,
results: []treeTestEntryPeriod{{fromDay: 0, result: treeTestOK}},
},
}
ctx.jobTestDays = []int{10}
ctx.moveToDay(10)

// The report must contain the string.
msg := ctx.reportToEmail()
assert.Contains(t, msg.Body, `@testapp.appspotmail.com
Bug presence analysis results: the bug reproduces only on the downstream tree.
report1
---
This report is generated by a bot. It may contain errors.`)
// No notification must be sent.
c.client.pollNotifs(0)
}

func TestTreeOriginLts(t *testing.T) {
c := NewCtx(t)
defer c.Close()
Expand Down Expand Up @@ -764,9 +804,9 @@ func (ctx *treeTestCtx) bugLink() string {
return fmt.Sprintf("/bug?id=%v", ctx.bug.key(ctx.ctx.ctx).StringID())
}

func (ctx *treeTestCtx) reportToEmail() {
func (ctx *treeTestCtx) reportToEmail() *aemail.Message {
ctx.client.updateBug(ctx.bugReport.ID, dashapi.BugStatusUpstream, "")
ctx.ctx.pollEmailBug() // skip the report
return ctx.ctx.pollEmailBug()
}

var urlRe = regexp.MustCompile(`(https?://[\w\./\?\=&]+)`)
Expand Down
3 changes: 2 additions & 1 deletion dashboard/dashapi/dashapi.go
Expand Up @@ -439,6 +439,7 @@ type BugReport struct {
Assets []Asset
Subsystems []BugSubsystem
ReportElements *ReportElements
LabelMessages map[string]string // notification messages for bug labels
}

type ReportElements struct {
Expand Down Expand Up @@ -530,7 +531,7 @@ type BugUpdate struct {
Link string
Status BugStatus
StatusReason BugStatusReason
Label string // the reported label, if BugNotifLabel
Labels []string // the reported labels
ReproLevel ReproLevel
DupOf string
OnHold bool // If set for open bugs, don't upstream this bug.
Expand Down

0 comments on commit d608a2a

Please sign in to comment.