cmd/coordinator: add logging around module proxy errors

Trying to track down where the 401s like these are coming from:

https://build.golang.org/log/4f9d520650841688b416ade5c205cd10b487f319

Updates golang/go#30749

Change-Id: I2f3e73882619b90a5238040f4d1134d678a058bd
Reviewed-on: https://go-review.googlesource.com/c/build/+/170620
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/coordinator/modproxy.go b/cmd/coordinator/modproxy.go
index 35f8f89..077df12 100644
--- a/cmd/coordinator/modproxy.go
+++ b/cmd/coordinator/modproxy.go
@@ -43,6 +43,7 @@
 	}
 	if !strings.Contains(builder, "-") || builderKey(builder) != pass {
 		http.Error(w, "bad username or password", http.StatusUnauthorized)
+		log.Printf("modproxy: sending 401 Unauthorized due to invalid key for builder %q", builder)
 		return
 	}
 
@@ -60,6 +61,12 @@
 	}
 	// TODO: maybe only create this once early. But probably doesn't matter.
 	rp := httputil.NewSingleHostReverseProxy(backend)
+	rp.ModifyResponse = func(res *http.Response) error {
+		if res.StatusCode/100 != 2 {
+			log.Printf("modproxy: proxying HTTP %s response from backend for builder %s, %s %s", res.Status, builder, r.Method, r.RequestURI)
+		}
+		return nil
+	}
 	r.Header.Del("Authorization")
 	r.Header.Del("X-Proxy-Service")
 	rp.ServeHTTP(w, r)