From c3fd2409e5f1eb8cbd311ab43c503fd00b2d6809 Mon Sep 17 00:00:00 2001 From: Tomas Nozicka Date: Wed, 11 Oct 2023 15:50:37 +0200 Subject: [PATCH 1/2] Remove debug endpoint from gcsweb --- gcsweb/cmd/gcsweb/gcsweb.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gcsweb/cmd/gcsweb/gcsweb.go b/gcsweb/cmd/gcsweb/gcsweb.go index dfc9ce5dcf16..a055839d1c29 100644 --- a/gcsweb/cmd/gcsweb/gcsweb.go +++ b/gcsweb/cmd/gcsweb/gcsweb.go @@ -192,17 +192,19 @@ func main() { logrus.Info("Starting GCSWeb") + mux := http.NewServeMux() + // Canonicalize allowed buckets. for i := range o.allowedBuckets { bucket := joinPath(gcsPath, o.allowedBuckets[i]) logrus.WithField("bucket", bucket).Info("allowing bucket") - http.HandleFunc(bucket+"/", s.gcsRequest) - http.HandleFunc(bucket, func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc(bucket+"/", s.gcsRequest) + mux.HandleFunc(bucket, func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, bucket+"/", http.StatusPermanentRedirect) }) } // Handle unknown buckets. - http.HandleFunc("/gcs/", unknownBucketRequest) + mux.HandleFunc("/gcs/", unknownBucketRequest) // Serve icons and styles. longCacheServer := func(h http.Handler) http.HandlerFunc { @@ -217,25 +219,25 @@ func main() { } if o.flIcons != "" { // If user specifies custom icons path then read it at runtime - http.Handle("/icons/", longCacheServer(http.StripPrefix("/icons/", http.FileServer(http.Dir(o.flIcons))))) + mux.Handle("/icons/", longCacheServer(http.StripPrefix("/icons/", http.FileServer(http.Dir(o.flIcons))))) } else { - http.Handle("/icons/", longCacheServer(http.FileServer(http.FS(embededStatic)))) + mux.Handle("/icons/", longCacheServer(http.FileServer(http.FS(embededStatic)))) } if o.flStyles != "" { // If user specifies custom styles path then read it at runtime - http.Handle("/styles/", longCacheServer(http.StripPrefix("/styles/", http.FileServer(http.Dir(o.flStyles))))) + mux.Handle("/styles/", longCacheServer(http.StripPrefix("/styles/", http.FileServer(http.Dir(o.flStyles))))) } else { - http.Handle("/styles/", longCacheServer(http.FileServer(http.FS(embededStatic)))) + mux.Handle("/styles/", longCacheServer(http.FileServer(http.FS(embededStatic)))) } // Serve HTTP. - http.HandleFunc("/robots.txt", robotsRequest) - http.HandleFunc("/", otherRequest) + mux.HandleFunc("/robots.txt", robotsRequest) + mux.HandleFunc("/", otherRequest) health := pjutil.NewHealthOnPort(o.instrumentationOptions.HealthPort) health.ServeReady() logrus.Infof("serving on port %d", o.flPort) - if err := http.ListenAndServe(fmt.Sprintf(":%d", o.flPort), nil); err != nil { + if err := http.ListenAndServe(fmt.Sprintf(":%d", o.flPort), mux); err != nil { logrus.WithError(err).Fatal("couldn't start the http server") } } From 008d3d420123e7e92daec10c3fa81459947459ef Mon Sep 17 00:00:00 2001 From: Tomas Nozicka Date: Wed, 11 Oct 2023 15:51:22 +0200 Subject: [PATCH 2/2] Remove debug endpoint from ml --- experiment/ml/analyze/http.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/experiment/ml/analyze/http.go b/experiment/ml/analyze/http.go index ed1f1417f525..49e9875c07c0 100644 --- a/experiment/ml/analyze/http.go +++ b/experiment/ml/analyze/http.go @@ -35,8 +35,9 @@ import ( ) func serveOnPort(ctx context.Context, storageClient *storage.Client, predictor *predictionClient, port int, timeout time.Duration) error { + mux := http.NewServeMux() - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() status, body, err := processRequest(ctx, storageClient, predictor, r) @@ -53,12 +54,12 @@ func serveOnPort(ctx context.Context, storageClient *storage.Client, predictor * } }) - http.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { + mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) }) log.Println("Listening for connections on port", port) - return http.ListenAndServe(":"+strconv.Itoa(port), nil) + return http.ListenAndServe(":"+strconv.Itoa(port), mux) } func processRequest(ctx context.Context, storageClient *storage.Client, predictor *predictionClient, r *http.Request) (int, string, error) {