diff --git a/deployment/clouddeploy/gke-workers/base/gitter.yaml b/deployment/clouddeploy/gke-workers/base/gitter.yaml index eff38dee82e..1769ca05fe3 100644 --- a/deployment/clouddeploy/gke-workers/base/gitter.yaml +++ b/deployment/clouddeploy/gke-workers/base/gitter.yaml @@ -27,6 +27,7 @@ spec: imagePullPolicy: Always args: - "--port=8888" + - "--enable_profiling=true" - "--work_dir=/work/gitter" - "--fetch_timeout=1h" volumeMounts: diff --git a/deployment/clouddeploy/gke-workers/environments/oss-vdb-test/gitter.yaml b/deployment/clouddeploy/gke-workers/environments/oss-vdb-test/gitter.yaml index 2cd55fe137d..b9e30f0ebd9 100644 --- a/deployment/clouddeploy/gke-workers/environments/oss-vdb-test/gitter.yaml +++ b/deployment/clouddeploy/gke-workers/environments/oss-vdb-test/gitter.yaml @@ -9,6 +9,7 @@ spec: - name: gitter args: - "--port=8888" + - "--enable_profiling=true" - "--work_dir=/work/gitter" - "--fetch_timeout=1h" env: diff --git a/deployment/clouddeploy/gke-workers/environments/oss-vdb/gitter.yaml b/deployment/clouddeploy/gke-workers/environments/oss-vdb/gitter.yaml index 840f7eccc09..52be45d804d 100644 --- a/deployment/clouddeploy/gke-workers/environments/oss-vdb/gitter.yaml +++ b/deployment/clouddeploy/gke-workers/environments/oss-vdb/gitter.yaml @@ -9,6 +9,7 @@ spec: - name: gitter args: - "--port=8888" + - "--enable_profiling=true" - "--work_dir=/work/gitter" - "--fetch_timeout=1h" env: diff --git a/go/cmd/gitter/gitter.go b/go/cmd/gitter/gitter.go index 7434e74e4bb..746b1bfb1ae 100644 --- a/go/cmd/gitter/gitter.go +++ b/go/cmd/gitter/gitter.go @@ -23,6 +23,8 @@ import ( "syscall" "time" + "net/http/pprof" + "github.com/google/osv.dev/go/logger" "golang.org/x/sync/singleflight" ) @@ -197,6 +199,7 @@ func fetchBlob(ctx context.Context, url string, forceUpdate bool) ([]byte, error func main() { port := flag.Int("port", 8888, "Listen port") + enableProfiling := flag.Bool("enable_profiling", false, "Enable pprof profiling endpoints") workDir := flag.String("work_dir", defaultGitterWorkDir, "Work directory") flag.DurationVar(&fetchTimeout, "fetch_timeout", time.Hour, "Fetch timeout duration") flag.Parse() @@ -215,7 +218,16 @@ func main() { ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() - http.HandleFunc(getGitEndpoint, gitHandler) + mux := http.NewServeMux() + mux.HandleFunc(getGitEndpoint, gitHandler) + + if *enableProfiling { + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + } logger.Info("Gitter starting and listening", slog.Int("port", *port)) @@ -232,6 +244,7 @@ func main() { server := &http.Server{ Addr: fmt.Sprintf(":%d", *port), + Handler: mux, ReadHeaderTimeout: 3 * time.Second, BaseContext: func(_ net.Listener) context.Context { // Return the context tied to the termination signal. @@ -260,6 +273,7 @@ func main() { logger.Error("Server forced to shutdown", slog.Any("error", err)) } + saveMap() logger.Info("Server exiting") } diff --git a/go/cmd/gitter/gitter_test_bin b/go/cmd/gitter/gitter_test_bin new file mode 100755 index 00000000000..ed20dbd156d Binary files /dev/null and b/go/cmd/gitter/gitter_test_bin differ