internal: pass non-zero chunk size to UploadMany All calls to UploadMany were passing a zero chunk size, meaning that the request to BigQuery would immediately fail if there was too much data. Specify a positive chunk size, so UploadMany can retry the upload with less data. Change-Id: I9d545b6ecf4da2ca6dd90aeefb05d8691cd135ec Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/643435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
diff --git a/internal/bigquery/bigquery.go b/internal/bigquery/bigquery.go index 7f04c37..48d5a2b 100644 --- a/internal/bigquery/bigquery.go +++ b/internal/bigquery/bigquery.go
@@ -20,6 +20,7 @@ bq "cloud.google.com/go/bigquery" "cloud.google.com/go/civil" "golang.org/x/pkgsite-metrics/internal/derrors" + "golang.org/x/pkgsite-metrics/internal/log" "google.golang.org/api/googleapi" "google.golang.org/api/iterator" ) @@ -215,6 +216,7 @@ end = len(rows) } for { + log.Infof(ctx, "bigquery.UploadMany: uploading rows[%d:%d]", start, end) if err := ins.Put(ctx, rows[start:end]); err == nil { break } else if hasCode(err, http.StatusRequestEntityTooLarge) && end-start > 1 {
diff --git a/internal/vulndbreqs/bq.go b/internal/vulndbreqs/bq.go index 664d5fa..8ab8287 100644 --- a/internal/vulndbreqs/bq.go +++ b/internal/vulndbreqs/bq.go
@@ -61,13 +61,13 @@ if _, err := client.CreateOrUpdateTable(ctx, RequestCountTableName); err != nil { return err } - if err := bigquery.UploadMany(ctx, client, RequestCountTableName, rcs, 0); err != nil { + if err := bigquery.UploadMany(ctx, client, RequestCountTableName, rcs, 100); err != nil { return err } if _, err := client.CreateOrUpdateTable(ctx, IPRequestCountTableName); err != nil { return err } - return bigquery.UploadMany(ctx, client, IPRequestCountTableName, ircs, 0) + return bigquery.UploadMany(ctx, client, IPRequestCountTableName, ircs, 100) } // ReadRequestCountsFromBigQuery returns daily counts for requests to the vuln DB, most recent first.
diff --git a/internal/worker/scan.go b/internal/worker/scan.go index 4447121..da29a0d 100644 --- a/internal/worker/scan.go +++ b/internal/worker/scan.go
@@ -181,7 +181,7 @@ log.Infof(ctx, "bigquery disabled, not uploading") return nil } - return bigquery.UploadMany(ctx, client, table, rows, 0) + return bigquery.UploadMany(ctx, client, table, rows, 100) } func serveJSON(ctx context.Context, content interface{}, w http.ResponseWriter) error {