internal/worker: remove memory limit parsing logic

It doesn't appear to be used anywhere meaningfully.

Change-Id: If18a3c6171f78caefb655ff0f13f6007c8cf7d4f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/477181
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
diff --git a/internal/worker/govulncheck_scan.go b/internal/worker/govulncheck_scan.go
index ed4ba1d..0ebdab9 100644
--- a/internal/worker/govulncheck_scan.go
+++ b/internal/worker/govulncheck_scan.go
@@ -12,7 +12,6 @@
 	"os"
 	"os/exec"
 	"path/filepath"
-	"strconv"
 	"strings"
 	"syscall"
 	"time"
@@ -126,7 +125,6 @@
 	dbClient    vulnclient.Client
 	bqClient    *bigquery.Client
 	workVersion *govulncheck.WorkVersion
-	goMemLimit  uint64
 	gcsBucket   *storage.BucketHandle
 	insecure    bool
 	sbox        *sandbox.Sandbox
@@ -152,7 +150,6 @@
 		bqClient:    h.bqClient,
 		dbClient:    h.vulndbClient,
 		workVersion: workVersion,
-		goMemLimit:  parseGoMemLimit(os.Getenv("GOMEMLIMIT")),
 		gcsBucket:   bucket,
 		insecure:    h.cfg.Insecure,
 		sbox:        sbox,
@@ -473,33 +470,6 @@
 		strings.Contains(s, "connection")
 }
 
-// parseGoMemLimit parses the GOMEMLIMIT environment variable.
-// It returns 0 if the variable isn't set or its value is malformed.
-func parseGoMemLimit(s string) uint64 {
-	if len(s) < 2 {
-		return 0
-	}
-	m := uint64(1)
-	if s[len(s)-1] == 'i' {
-		switch s[len(s)-2] {
-		case 'K':
-			m = 1024
-		case 'M':
-			m = 1024 * 1024
-		case 'G':
-			m = 1024 * 1024 * 1024
-		default:
-			return 0
-		}
-		s = s[:len(s)-2]
-	}
-	v, err := strconv.ParseUint(s, 10, 64)
-	if err != nil {
-		return 0
-	}
-	return v * m
-}
-
 // fileExists checks if file path exists. Returns true
 // if the file exists or it cannot prove that it does
 // not exist. Otherwise, returns false.
diff --git a/internal/worker/govulncheck_scan_test.go b/internal/worker/govulncheck_scan_test.go
index db7feab..858f3a9 100644
--- a/internal/worker/govulncheck_scan_test.go
+++ b/internal/worker/govulncheck_scan_test.go
@@ -16,7 +16,6 @@
 	"cloud.google.com/go/storage"
 	"golang.org/x/pkgsite-metrics/internal/bigquery"
 	"golang.org/x/pkgsite-metrics/internal/config"
-	"golang.org/x/pkgsite-metrics/internal/derrors"
 	"golang.org/x/pkgsite-metrics/internal/govulncheck"
 	"golang.org/x/pkgsite-metrics/internal/proxy"
 	vulnclient "golang.org/x/vuln/client"
@@ -107,14 +106,6 @@
 			t.Errorf("scan memory not collected or negative: %v", got)
 		}
 	})
-	t.Run("memoryLimit", func(t *testing.T) {
-		s := &scanner{proxyClient: proxyClient, dbClient: dbClient, insecure: true, goMemLimit: 2000}
-		_, err := s.runScanModule(ctx, "golang.org/x/mod", "v0.5.1",
-			"", ModeGovulncheck, &scanStats{})
-		if !errors.Is(err, derrors.ScanModuleMemoryLimitExceeded) {
-			t.Errorf("got %v, want MemoryLimitExceeded", err)
-		}
-	})
 	t.Run("binary", func(t *testing.T) {
 		if !*integration { // needs GCS read permission, not available on kokoro
 			t.Skip("missing -integration")
@@ -162,22 +153,3 @@
 		}
 	})
 }
-
-func TestParseGoMemLimit(t *testing.T) {
-	for _, test := range []struct {
-		in   string
-		want uint64
-	}{
-		{"", 0},
-		{"foo", 0},
-		{"23", 23},
-		{"56Ki", 56 * 1024},
-		{"3Mi", 3 * 1024 * 1024},
-		{"8Gi", 8 * 1024 * 1024 * 1024},
-	} {
-		got := parseGoMemLimit(test.in)
-		if got != test.want {
-			t.Errorf("%q: got %d, want %d", test.in, got, test.want)
-		}
-	}
-}