Commit ffd46d3a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add optional Golang profiler

The profiler is disabled by default. It will allow us to better
understand the behavior of gitlab-git-http-server in production.
parent c08b8fae
Pipeline #524 failed with stage
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
_ "net/http/pprof"
"os" "os"
"syscall" "syscall"
) )
...@@ -32,6 +33,7 @@ func main() { ...@@ -32,6 +33,7 @@ func main() {
listenNetwork := flag.String("listenNetwork", "tcp", "Listen 'network' (tcp, tcp4, tcp6, unix)") listenNetwork := flag.String("listenNetwork", "tcp", "Listen 'network' (tcp, tcp4, tcp6, unix)")
listenUmask := flag.Int("listenUmask", 022, "Umask for Unix socket, default: 022") listenUmask := flag.Int("listenUmask", 022, "Umask for Unix socket, default: 022")
authBackend := flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend") authBackend := flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend")
pprofListenAddr := flag.String("pprofListenAddr", "", "pprof listening address, e.g. 'localhost:6060'")
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\n %s [OPTIONS] REPO_ROOT\n\nOptions:\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\n %s [OPTIONS] REPO_ROOT\n\nOptions:\n", os.Args[0])
...@@ -66,6 +68,19 @@ func main() { ...@@ -66,6 +68,19 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
http.Handle("/", newGitHandler(repoRoot, *authBackend)) // The profiler will only be activated by HTTP requests. HTTP
log.Fatal(http.Serve(listener, nil)) // requests can only reach the profiler if we start a listener. So by
// having no profiler HTTP listener by default, the profiler is
// effectively disabled by default.
if *pprofListenAddr != "" {
go func() {
log.Print(http.ListenAndServe(*pprofListenAddr, nil))
}()
}
// Because net/http/pprof installs itself in the DefaultServeMux
// we create a fresh one for the Git server.
serveMux := http.NewServeMux()
serveMux.Handle("/", newGitHandler(repoRoot, *authBackend))
log.Fatal(http.Serve(listener, serveMux))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment