From d608a2afc4289e56fe35af894ff9eb3f56f4fcb4 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 25 May 2023 13:14:16 +0200 Subject: dashboard: include label message into bug reports --- dashboard/app/mail_bug.txt | 4 ++++ dashboard/app/reporting.go | 14 ++++++++++-- dashboard/app/reporting_email.go | 7 +++++- dashboard/app/tree_test.go | 46 +++++++++++++++++++++++++++++++++++++--- dashboard/dashapi/dashapi.go | 3 ++- 5 files changed, 67 insertions(+), 7 deletions(-) (limited to 'dashboard') diff --git a/dashboard/app/mail_bug.txt b/dashboard/app/mail_bug.txt index ef9e5fab0..2cc951172 100644 --- a/dashboard/app/mail_bug.txt +++ b/dashboard/app/mail_bug.txt @@ -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}} --- diff --git a/dashboard/app/reporting.go b/dashboard/app/reporting.go index d0b61bbf1..f75b2d318 100644 --- a/dashboard/app/reporting.go +++ b/dashboard/app/reporting.go @@ -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 } @@ -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 } diff --git a/dashboard/app/reporting_email.go b/dashboard/app/reporting_email.go index 8e6337e78..35f104d71 100644 --- a/dashboard/app/reporting_email.go +++ b/dashboard/app/reporting_email.go @@ -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) @@ -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) diff --git a/dashboard/app/tree_test.go b/dashboard/app/tree_test.go index 03aeb1aae..d3524dec6 100644 --- a/dashboard/app/tree_test.go +++ b/dashboard/app/tree_test.go @@ -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" ) @@ -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`) @@ -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. @@ -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() @@ -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\./\?\=&]+)`) diff --git a/dashboard/dashapi/dashapi.go b/dashboard/dashapi/dashapi.go index 6227b6da9..6f6bc81c7 100644 --- a/dashboard/dashapi/dashapi.go +++ b/dashboard/dashapi/dashapi.go @@ -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 { @@ -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. -- cgit mrf-deployment