Skip to content

Commit 2eee5ef

Browse files
committed
dashboard: extend bug's JSON representation
Add status, crash, fix, close and commit dates.
1 parent 0782d2d commit 2eee5ef

File tree

4 files changed

+73
-20
lines changed

4 files changed

+73
-20
lines changed

dashboard/api/api.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// All structures in this package are backwards compatible.
66
package api
77

8+
import "time"
9+
810
const Version = 1
911

1012
type BugGroup struct {
@@ -20,11 +22,16 @@ type BugSummary struct {
2022
}
2123

2224
type Bug struct {
23-
Version int `json:"version"`
24-
Title string `json:"title,omitempty"`
25-
ID string `json:"id"`
26-
FixCommits []Commit `json:"fix-commits,omitempty"`
27-
CauseCommit *Commit `json:"cause-commit,omitempty"`
25+
Version int `json:"version"`
26+
Title string `json:"title,omitempty"`
27+
ID string `json:"id"`
28+
Status string `json:"status"`
29+
FirstCrash time.Time `json:"first-crash"`
30+
LastCrash time.Time `json:"last-crash"`
31+
FixTime *time.Time `json:"fix-time,omitempty"`
32+
CloseTime *time.Time `json:"close-time,omitempty"`
33+
FixCommits []Commit `json:"fix-commits,omitempty"`
34+
CauseCommit *Commit `json:"cause-commit,omitempty"`
2835
// Links to the discussions.
2936
Discussions []string `json:"discussions,omitempty"`
3037
Crashes []Crash `json:"crashes,omitempty"`
@@ -45,9 +52,10 @@ type Crash struct {
4552
}
4653

4754
type Commit struct {
48-
Title string `json:"title"`
49-
Link string `json:"link,omitempty"`
50-
Hash string `json:"hash,omitempty"`
51-
Repo string `json:"repo,omitempty"`
52-
Branch string `json:"branch,omitempty"`
55+
Title string `json:"title"`
56+
Link string `json:"link,omitempty"`
57+
Hash string `json:"hash,omitempty"`
58+
Repo string `json:"repo,omitempty"`
59+
Branch string `json:"branch,omitempty"`
60+
Date *time.Time `json:"date,omitempty"`
5361
}

dashboard/app/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ type uiBug struct {
389389
FirstTime time.Time
390390
LastTime time.Time
391391
ReportedTime time.Time
392+
FixTime time.Time
392393
ClosedTime time.Time
393394
ReproLevel dashapi.ReproLevel
394395
ReportingIndex int
@@ -1967,6 +1968,7 @@ func createUIBug(c context.Context, bug *Bug, state *ReportingState, managers []
19671968
LastTime: bug.LastTime,
19681969
ReportedTime: reported,
19691970
ClosedTime: bug.Closed,
1971+
FixTime: bug.FixTime,
19701972
ReproLevel: bug.ReproLevel,
19711973
ReportingIndex: reportingIdx,
19721974
Status: status,

dashboard/app/public_json_api.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ import (
1818

1919
func getExtAPIDescrForBug(bug *uiBugDetails) *api.Bug {
2020
return &api.Bug{
21-
Version: api.Version,
22-
Title: bug.Title,
23-
ID: bug.ID,
21+
Version: api.Version,
22+
Title: bug.Title,
23+
ID: bug.ID,
24+
Status: bug.Status,
25+
FirstCrash: bug.FirstTime,
26+
LastCrash: bug.LastTime,
27+
FixTime: func() *time.Time {
28+
if bug.FixTime.IsZero() {
29+
return nil
30+
}
31+
return &bug.FixTime
32+
}(),
33+
CloseTime: func() *time.Time {
34+
if bug.ClosedTime.IsZero() {
35+
return nil
36+
}
37+
return &bug.ClosedTime
38+
}(),
2439
Discussions: func() []string {
2540
if bug.ExternalLink == "" {
2641
return nil
@@ -29,16 +44,21 @@ func getExtAPIDescrForBug(bug *uiBugDetails) *api.Bug {
2944
}(),
3045
FixCommits: getBugFixCommits(bug.uiBug),
3146
CauseCommit: func() *api.Commit {
32-
if bug.BisectCause == nil || bug.BisectCause.Commit == nil {
47+
bisectCause := bug.BisectCauseJob
48+
if bisectCause == nil || bisectCause.Commit == nil {
3349
return nil
3450
}
35-
bisectCause := bug.BisectCause
36-
return &api.Commit{
51+
commit := &api.Commit{
3752
Title: bisectCause.Commit.Title,
3853
Link: bisectCause.Commit.Link,
3954
Hash: bisectCause.Commit.Hash,
4055
Repo: bisectCause.KernelRepo,
41-
Branch: bisectCause.KernelBranch}
56+
Branch: bisectCause.KernelBranch,
57+
}
58+
if !bisectCause.Commit.Date.IsZero() {
59+
commit.Date = &bisectCause.Commit.Date
60+
}
61+
return commit
4262
}(),
4363
Crashes: func() []api.Crash {
4464
var res []api.Crash
@@ -65,13 +85,17 @@ func getExtAPIDescrForBug(bug *uiBugDetails) *api.Bug {
6585
func getBugFixCommits(bug *uiBug) []api.Commit {
6686
var res []api.Commit
6787
for _, commit := range bug.Commits {
68-
res = append(res, api.Commit{
88+
apiCommit := api.Commit{
6989
Title: commit.Title,
7090
Link: commit.Link,
7191
Hash: commit.Hash,
7292
Repo: commit.Repo,
7393
Branch: commit.Branch,
74-
})
94+
}
95+
if !commit.Date.IsZero() {
96+
apiCommit.Date = &commit.Date
97+
}
98+
res = append(res, apiCommit)
7599
}
76100
return res
77101
}

dashboard/app/public_json_api_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"testing"
11+
"time"
1112

1213
"github.com/google/syzkaller/dashboard/api"
1314
"github.com/google/syzkaller/dashboard/dashapi"
@@ -23,6 +24,9 @@ func TestJSONAPIIntegration(t *testing.T) {
2324
"version": 1,
2425
"title": "title1",
2526
"id": "cb1dbe55dc6daa7e739a0d09a0ae4d5e3e5a10c8",
27+
"status": "reporting1: reported on 2000/01/01 00:01",
28+
"first-crash": "2000-01-01T00:01:00Z",
29+
"last-crash": "2000-01-01T00:01:00Z",
2630
"crashes": [
2731
{
2832
"title": "title1",
@@ -40,6 +44,9 @@ func TestJSONAPIIntegration(t *testing.T) {
4044
"version": 1,
4145
"title": "title2",
4246
"id": "fc00fbc0cddd9a4ef2ae33e40cd21636081466ce",
47+
"status": "reporting1: reported C repro on 2000/01/01 00:01",
48+
"first-crash": "2000-01-01T00:01:00Z",
49+
"last-crash": "2000-01-01T00:01:00Z",
4350
"crashes": [
4451
{
4552
"title": "title2",
@@ -100,6 +107,7 @@ func TestJSONAPIIntegration(t *testing.T) {
100107
c.client.UploadBuild(build)
101108

102109
crash1 := testCrash(build, 1)
110+
c.advanceTime(time.Minute)
103111
c.client.ReportCrash(crash1)
104112
bugReport1 := c.client.pollBug()
105113
checkBugPageJSONIs(c, bugReport1.ID, sampleCrashDescr)
@@ -121,6 +129,7 @@ func TestJSONAPIIntegration(t *testing.T) {
121129
}
122130

123131
func checkBugPageJSONIs(c *Ctx, ID string, expectedContent []byte) {
132+
c.t.Helper()
124133
url := fmt.Sprintf("/bug?extid=%v&json=1", ID)
125134

126135
contentType, _ := c.client.ContentType(url)
@@ -131,6 +140,7 @@ func checkBugPageJSONIs(c *Ctx, ID string, expectedContent []byte) {
131140
}
132141

133142
func checkBugGroupPageJSONIs(c *Ctx, url string, expectedContent []byte) {
143+
c.t.Helper()
134144
contentType, _ := c.client.ContentType(url)
135145
c.expectEQ(contentType, "application/json")
136146

@@ -150,6 +160,7 @@ func TestJSONAPIFixCommits(t *testing.T) {
150160
rep1 := c.client.pollBug()
151161

152162
// Specify fixing commit for the bug.
163+
c.advanceTime(time.Hour)
153164
c.client.ReportingUpdate(&dashapi.BugUpdate{
154165
ID: rep1.ID,
155166
Status: dashapi.BugStatusOpen,
@@ -166,6 +177,10 @@ func TestJSONAPIFixCommits(t *testing.T) {
166177
"version": 1,
167178
"title": "title1",
168179
"id": "cb1dbe55dc6daa7e739a0d09a0ae4d5e3e5a10c8",
180+
"status": "reporting1: reported on 2000/01/01 00:00",
181+
"first-crash": "2000-01-01T00:00:00Z",
182+
"last-crash": "2000-01-01T00:00:00Z",
183+
"fix-time": "2000-01-01T01:00:00Z",
169184
"fix-commits": [
170185
{
171186
"title": "foo: fix1",
@@ -210,11 +225,15 @@ func TestJSONAPICauseBisection(t *testing.T) {
210225
"version": 1,
211226
"title": "title1",
212227
"id": "70ce63ecb151d563976728208edccc6879191f9f",
228+
"status": "reporting2: reported C repro on 2000/01/31 00:00",
229+
"first-crash": "2000-01-01T00:00:00Z",
230+
"last-crash": "2000-01-01T00:00:00Z",
213231
"cause-commit": {
214232
"title": "kernel: add a bug",
215233
"hash": "36e65cb4a0448942ec316b24d60446bbd5cc7827",
216234
"repo": "repo1",
217-
"branch": "branch1"
235+
"branch": "branch1",
236+
"date": "2000-02-09T04:05:06Z"
218237
},
219238
"crashes": [
220239
{

0 commit comments

Comments
 (0)