godev/cmd/worker: queue-task will generate charts based on 7 days
Change-Id: Id91fd3073f0a530a011fd356424ee6ffab3ba2a1
Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/600215
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/README.md b/godev/cmd/worker/README.md
index 556b6e2..9c9993b 100644
--- a/godev/cmd/worker/README.md
+++ b/godev/cmd/worker/README.md
@@ -26,6 +26,15 @@
Use this endpoint to generate an aggregate chart file containing data from the
provided date range (inclusive) from the merge bucket.
+### `/queue-tasks`
+
+The queue-tasks endpoint is responsible for task distribution. When invoked, it
+triggers the following actions:
+
+- call merge endpoint to merge uploaded reports for the past 7 days.
+- call chart endpoint to generate daily charts for the 7 days preceding today.
+- call chart endpoint to generate weekly charts for the past 8 days.
+
## Local Development
For local development, simply build and run. It serves on localhost:8082.
diff --git a/godev/cmd/worker/main.go b/godev/cmd/worker/main.go
index 4ad2861..e5dbb7e 100644
--- a/godev/cmd/worker/main.go
+++ b/godev/cmd/worker/main.go
@@ -74,9 +74,12 @@
// handleTasks will populate the task queue that processes report
// data. Cloud Scheduler will be instrumented to call this endpoint
-// daily to merge reports and generate chart data. The merge tasks
-// will merge the previous weeks reports and the chart tasks will do
-// the same minus one day.
+// daily to merge reports and generate chart data.
+// The merge tasks will merge the previous 7 days reports.
+// The chart tasks generate daily and weekly charts for the 7 days preceding
+// today.
+// - Daily chart: utilizes data exclusively from the specific date.
+// - Weekly chart: encompasses 7 days of data, concluding on the specified date.
// TODO(golang/go#62575): adjust the date range to align with report
// upload cutoff.
func handleTasks(cfg *config.Config) content.HandlerFunc {
@@ -89,12 +92,23 @@
return err
}
}
+ // TODO(hxjiang): have an endpoint to produce all the json instead of a hard
+ // coded one day delay.
for i := 8; i > 1; i-- {
+ // Daily chart: generate chart using one day's data.
date := now.AddDate(0, 0, -1*i).Format(time.DateOnly)
url := cfg.WorkerURL + "/chart/?date=" + date
if _, err := createHTTPTask(cfg, url); err != nil {
return err
}
+
+ // Weekly chart: generate chart using past 7 days' data.
+ end := now.AddDate(0, 0, -1*i)
+ start := end.AddDate(0, 0, -6)
+ url = cfg.WorkerURL + "/chart/?start=" + start.Format(time.DateOnly) + "&end=" + end.Format(time.DateOnly)
+ if _, err := createHTTPTask(cfg, url); err != nil {
+ return err
+ }
}
return nil
}