cmd/ejobs: fix unfortunate flag assignment typo and resulting discovered bug https://go.dev/cl/679355 introduced the notion of 'max importers;' however, it made an error in flag assignment. This error resulted in discovering: ``` 500 Internal Server Error: analysisServer.handleEnqueue: moduleSpecsFromDB: pq: value "9223372036854775807" is out of range for type integer ``` Change-Id: I0de650fb332f9877a37180206ba78a92bdd1e8c7 Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/680936 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/cmd/ejobs/main.go b/cmd/ejobs/main.go index d87b48f..cf3acd6 100644 --- a/cmd/ejobs/main.go +++ b/cmd/ejobs/main.go
@@ -70,10 +70,10 @@ "start a job", doStart, func(fs *flag.FlagSet) { - fs.IntVar(&maxImporters, "min", -1, + fs.IntVar(&minImporters, "min", -1, "run on modules with at least this many importers (<0: use server default of 10)") - fs.IntVar(&minImporters, "max", -1, - "run on modules with at most this many importers (<0: use server default of math.MaxInt)") + fs.IntVar(&maxImporters, "max", -1, + "run on modules with at most this many importers (<0: use server default of unlimited)") fs.StringVar(&moduleFile, "file", "", "file with modules to use: each line is MODULE_PATH VERSION NUM_IMPORTERS") fs.BoolVar(&noDeps, "nodeps", false, "do not download dependencies for modules")
diff --git a/internal/analysis/analysis.go b/internal/analysis/analysis.go index b4482c0..d67004e 100644 --- a/internal/analysis/analysis.go +++ b/internal/analysis/analysis.go
@@ -44,8 +44,8 @@ Binary string // name of analysis binary to run Args string // command-line arguments to binary; split on whitespace Insecure bool // if true, run outside sandbox - Min int // minimum import-by count for a module to be included - Max int // maximum import-by count for a module to be included + Min int32 // minimum import-by count for a module to be included + Max int32 // maximum import-by count for a module to be included File string // path to file containing modules; if missing, use DB Suffix string // appended to task queue IDs to generate unique tasks User string // user initiating enqueue
diff --git a/internal/govulncheck/govulncheck.go b/internal/govulncheck/govulncheck.go index 0be7352..4f5eee2 100644 --- a/internal/govulncheck/govulncheck.go +++ b/internal/govulncheck/govulncheck.go
@@ -48,7 +48,7 @@ type EnqueueQueryParams struct { Suffix string // appended to task queue IDs to generate unique tasks Mode string // type of analysis to run - Min int // minimum import-by count for a module to be included + Min int32 // minimum import-by count for a module to be included File string // path to file containing modules; if missing, use DB }
diff --git a/internal/pkgsitedb/db.go b/internal/pkgsitedb/db.go index c99df55..4d90f79 100644 --- a/internal/pkgsitedb/db.go +++ b/internal/pkgsitedb/db.go
@@ -52,7 +52,7 @@ // ModuleSpecs retrieves all modules that contain packages that are // imported by minImportedByCount or more packages. // It looks for the information in the search_documents table of the given pkgsite DB. -func ModuleSpecs(ctx context.Context, db *sql.DB, minImports, maxImports int) (specs []scan.ModuleSpec, err error) { +func ModuleSpecs(ctx context.Context, db *sql.DB, minImports, maxImports int32) (specs []scan.ModuleSpec, err error) { defer derrors.Wrap(&err, "moduleSpecsFromDB") query := ` SELECT module_path, version, max(imported_by_count)
diff --git a/internal/pkgsitedb/db_test.go b/internal/pkgsitedb/db_test.go index 029f3a5..e4005f9 100644 --- a/internal/pkgsitedb/db_test.go +++ b/internal/pkgsitedb/db_test.go
@@ -51,7 +51,7 @@ if err := db.PingContext(ctx); err != nil { t.Fatal(err) } - got, err := ModuleSpecs(ctx, db, 1000, math.MaxInt) + got, err := ModuleSpecs(ctx, db, 1000, math.MaxInt32) if err != nil { t.Fatal(err) }
diff --git a/internal/scan/parse.go b/internal/scan/parse.go index f21d545..619ff9f 100644 --- a/internal/scan/parse.go +++ b/internal/scan/parse.go
@@ -35,7 +35,7 @@ ImportedBy int } -func ParseCorpusFile(filename string, minImports, maxImports int) (ms []ModuleSpec, err error) { +func ParseCorpusFile(filename string, minImports, maxImports int32) (ms []ModuleSpec, err error) { defer derrors.Wrap(&err, "ParseCorpusFile(%q)", filename) lines, err := ReadFileLines(filename) if err != nil { @@ -56,12 +56,12 @@ default: return nil, fmt.Errorf("wrong number of fields on line %q", line) } - n, err := strconv.Atoi(imps) + n, err := strconv.ParseInt(imps, 10, 32) if err != nil { - return nil, fmt.Errorf("%v on line %q", err, line) + return nil, fmt.Errorf("number of imports: invalid integer %q", imps) } - if minImports <= n && n <= maxImports { - ms = append(ms, ModuleSpec{Path: path, Version: vers, ImportedBy: n}) + if minImports <= int32(n) && int32(n) <= maxImports { + ms = append(ms, ModuleSpec{Path: path, Version: vers, ImportedBy: int(n)}) } } return ms, nil
diff --git a/internal/scan/parse_test.go b/internal/scan/parse_test.go index cfbbc7e..2e88ae4 100644 --- a/internal/scan/parse_test.go +++ b/internal/scan/parse_test.go
@@ -101,7 +101,7 @@ func TestParseCorpusFile(t *testing.T) { const file = "testdata/modules.txt" - got, err := ParseCorpusFile(file, 1, math.MaxInt) + got, err := ParseCorpusFile(file, 1, math.MaxInt32) if err != nil { t.Fatal(err) } @@ -115,7 +115,7 @@ t.Errorf("\n got %v\nwant %v", got, want) } - got, err = ParseCorpusFile(file, 10, math.MaxInt) + got, err = ParseCorpusFile(file, 10, math.MaxInt32) if err != nil { t.Fatal(err) }
diff --git a/internal/worker/enqueue.go b/internal/worker/enqueue.go index 36fc211..599a880 100644 --- a/internal/worker/enqueue.go +++ b/internal/worker/enqueue.go
@@ -19,10 +19,10 @@ const ( defaultMinImportedByCount = 10 - defaultMaxImportedByCount = math.MaxInt + defaultMaxImportedByCount = math.MaxInt32 ) -func readModules(ctx context.Context, cfg *config.Config, file string, minImports, maxImports int) ([]scan.ModuleSpec, error) { +func readModules(ctx context.Context, cfg *config.Config, file string, minImports, maxImports int32) ([]scan.ModuleSpec, error) { if file != "" { log.Infof(ctx, "reading modules from file %s", file) return scan.ParseCorpusFile(file, minImports, maxImports) @@ -31,7 +31,7 @@ return readFromDB(ctx, cfg, minImports, maxImports) } -func readFromDB(ctx context.Context, cfg *config.Config, minImports, maxImports int) ([]scan.ModuleSpec, error) { +func readFromDB(ctx context.Context, cfg *config.Config, minImports, maxImports int32) ([]scan.ModuleSpec, error) { db, err := pkgsitedb.Open(ctx, cfg) if err != nil { return nil, err
diff --git a/internal/worker/govulncheck_enqueue.go b/internal/worker/govulncheck_enqueue.go index 0365f08..2410882 100644 --- a/internal/worker/govulncheck_enqueue.go +++ b/internal/worker/govulncheck_enqueue.go
@@ -81,7 +81,7 @@ ) for _, mode := range modes { if modspecs == nil { - modspecs, err = readModules(ctx, cfg, params.File, params.Min, math.MaxInt) + modspecs, err = readModules(ctx, cfg, params.File, params.Min, math.MaxInt32) if err != nil { return nil, err }