internal/config: support disabling error reporting

We don't always want to get emails about errors (for instance, for our
dev environment). The product doesn't support selectively emailing by
service, so disable error reporting in the binary instead.

Change-Id: Ia5abc50a86dbdb22d14cddc36c0450d2e505ff1b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/262997
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/cmd/internal/cmdconfig/cmdconfig.go b/cmd/internal/cmdconfig/cmdconfig.go
index af9f406..25be2a8 100644
--- a/cmd/internal/cmdconfig/cmdconfig.go
+++ b/cmd/internal/cmdconfig/cmdconfig.go
@@ -33,7 +33,7 @@
 
 // ReportingClient configures an Error Reporting client.
 func ReportingClient(ctx context.Context, cfg *config.Config) *errorreporting.Client {
-	if !cfg.OnGCP() {
+	if !cfg.OnGCP() || cfg.DisableErrorReporting {
 		return nil
 	}
 	reporter, err := errorreporting.NewClient(ctx, cfg.ProjectID, errorreporting.Config{
diff --git a/internal/config/config.go b/internal/config/config.go
index c1ed6cf..bef0477 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -184,6 +184,9 @@
 	// ServeStats determines whether the server has an endpoint that serves statistics for
 	// benchmarking or other purposes.
 	ServeStats bool
+
+	// DisableErrorReporting disables sending errors to the GCP ErrorReporting system.
+	DisableErrorReporting bool
 }
 
 // AppVersionLabel returns the version label for the current instance.  This is
@@ -410,8 +413,9 @@
 			MaxTimeout:       time.Duration(GetEnvInt("GO_DISCOVERY_TEEPROXY_MAX_TIMEOUT_SECONDS", 240)) * time.Second,
 			SuccsToGreen:     GetEnvInt("GO_DISCOVERY_TEEPROXY_SUCCS_TO_GREEN", 20),
 		},
-		LogLevel:   os.Getenv("GO_DISCOVERY_LOG_LEVEL"),
-		ServeStats: os.Getenv("GO_DISCOVERY_SERVE_STATS") == "true",
+		LogLevel:              os.Getenv("GO_DISCOVERY_LOG_LEVEL"),
+		ServeStats:            os.Getenv("GO_DISCOVERY_SERVE_STATS") == "true",
+		DisableErrorReporting: os.Getenv("GO_DISCOVERY_DISABLE_ERROR_REPORTING") == "true",
 	}
 	bucket := os.Getenv("GO_DISCOVERY_CONFIG_BUCKET")
 	object := os.Getenv("GO_DISCOVERY_CONFIG_DYNAMIC")