godev/cmd/worker: fix missing charts in /chart output json
Now that /chart accepts a date range as input, data.partition must
keep going when encountering a week with no counter data, returning
a nil chart only if all aggregated weeks have no data
Change-Id: Ic7814f28cfc69b3ccc6b57eb61edb54ccba3c595
Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/599135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/godev/cmd/worker/main.go b/godev/cmd/worker/main.go
index 1c1187b..4ad2861 100644
--- a/godev/cmd/worker/main.go
+++ b/godev/cmd/worker/main.go
@@ -370,7 +370,7 @@
// TODO: when should this be number of reports?
// total := len(xs)
if total := len(d[wk][pk][gk][counterName(gk)]); total == 0 {
- return nil
+ continue
}
// We group versions into major minor buckets, we must skip
// major minor versions we've already added to the dataset.
@@ -391,6 +391,10 @@
}
}
+ if len(counts) == 0 {
+ return nil
+ }
+
// datum.Week always points to the end date
for k, v := range counts {
d := &datum{
diff --git a/godev/cmd/worker/main_test.go b/godev/cmd/worker/main_test.go
index b85f2c3..c081d36 100644
--- a/godev/cmd/worker/main_test.go
+++ b/godev/cmd/worker/main_test.go
@@ -426,6 +426,70 @@
},
},
},
+ {
+ name: "two days data, missing GOOS in first day",
+ data: data{
+ "2999-01-01": {"example.com/mod/pkg": {"Version": {
+ "Version": {0.1: 2},
+ "Version:v1.2": {0.1: 2},
+ },
+ }},
+ "2999-01-02": {"example.com/mod/pkg": {"GOOS": {
+ "GOOS": {0.3: 4},
+ "GOOS:darwin": {0.3: 2},
+ "GOOS:linux": {0.3: 2},
+ },
+ }},
+ },
+ args: args{
+ program: "example.com/mod/pkg",
+ name: "GOOS",
+ buckets: []string{"darwin", "linux"},
+ },
+ want: &chart{
+ ID: "charts:example.com/mod/pkg:GOOS",
+ Name: "GOOS",
+ Type: "partition",
+ Data: []*datum{
+ {
+ Week: "2999-01-02",
+ Key: "darwin",
+ Value: 1,
+ },
+ {
+ Week: "2999-01-02",
+ Key: "linux",
+ Value: 1,
+ },
+ },
+ },
+ },
+ {
+ name: "three days, missing version data all days",
+ data: data{
+ "2999-01-01": {"example.com/mod/pkg": {"GOOS": {
+ "GOOS": {0.1: 2},
+ "GOOS:darwin": {0.1: 2},
+ },
+ }},
+ "2999-01-02": {"example.com/mod/pkg": {"GOOS": {
+ "GOOS": {0.6: 5},
+ "GOOS:linux": {0.6: 5},
+ },
+ }},
+ "2999-01-03": {"example.com/mod/pkg": {"GOOS": {
+ "GOOS": {0.6: 3},
+ "GOOS:darwin": {0.6: 3},
+ },
+ }},
+ },
+ args: args{
+ program: "example.com/mod/pkg",
+ name: "Version",
+ buckets: []string{"v1.2.3", "v2.3.4"},
+ },
+ want: nil,
+ },
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {