[perf] More timeouts for database Contexts.
Bug: b/306460710
Change-Id: I35ea173d788b9e3c15e50e638d9d0068f03e207b
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/768875
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
diff --git a/perf/go/frontend/frontend.go b/perf/go/frontend/frontend.go
index bc91294..c7ba764 100644
--- a/perf/go/frontend/frontend.go
+++ b/perf/go/frontend/frontend.go
@@ -1404,9 +1404,12 @@
}
func (f *Frontend) alertListHandler(w http.ResponseWriter, r *http.Request) {
+ ctx, cancel := context.WithTimeout(r.Context(), defaultDatabaseTimeout)
+ defer cancel()
w.Header().Set("Content-Type", "application/json")
show := chi.URLParam(r, "show")
- resp, err := f.alertStore.List(r.Context(), show == "true")
+
+ resp, err := f.alertStore.List(ctx, show == "true")
if err != nil {
httputils.ReportError(w, err, "Failed to retrieve alert configs.", http.StatusInternalServerError)
}
diff --git a/perf/go/ingest/process/process.go b/perf/go/ingest/process/process.go
index ebf2b27..b29d3ab 100644
--- a/perf/go/ingest/process/process.go
+++ b/perf/go/ingest/process/process.go
@@ -29,6 +29,10 @@
const writeRetries = 10
+// defaultDatabaseTimeout is the context timeout used when making a request that
+// involves the database. For more complex requests use config.QueryMaxRuntime.
+const defaultDatabaseTimeout = time.Minute
+
// sendPubSubEvent sends the unencoded params and paramset found in a single
// ingested file to the PubSub topic specified in the selected Perf instances
// configuration data.
@@ -115,7 +119,8 @@
// processSingleFile parses a single incoming file and write the data to the
// datastore.
func (w *workerInfo) processSingleFile(f file.File) error {
- ctx := context.Background()
+ ctx, cancel := context.WithTimeout(context.Background(), defaultDatabaseTimeout)
+ defer cancel()
ctx, span := trace.StartSpan(ctx, "ingest.parser.processSingleFile")
defer span.End()
diff --git a/perf/go/regression/detector.go b/perf/go/regression/detector.go
index 2f23603..8507cf0 100644
--- a/perf/go/regression/detector.go
+++ b/perf/go/regression/detector.go
@@ -279,10 +279,10 @@
}
// shortcutFromKeys stores a new shortcut for each regression based on its Keys.
-func (p *regressionDetectionProcess) shortcutFromKeys(summary *clustering2.ClusterSummaries) error {
+func (p *regressionDetectionProcess) shortcutFromKeys(ctx context.Context, summary *clustering2.ClusterSummaries) error {
var err error
for _, cs := range summary.Clusters {
- if cs.Shortcut, err = p.shortcutStore.InsertShortcut(context.Background(), &shortcut.Shortcut{Keys: cs.Keys}); err != nil {
+ if cs.Shortcut, err = p.shortcutStore.InsertShortcut(ctx, &shortcut.Shortcut{Keys: cs.Keys}); err != nil {
return err
}
}
@@ -344,7 +344,7 @@
if err != nil {
return p.reportError(err, "Invalid regression detection.")
}
- if err := p.shortcutFromKeys(summary); err != nil {
+ if err := p.shortcutFromKeys(ctx, summary); err != nil {
return p.reportError(err, "Failed to write shortcut for keys.")
}