Plug "pprof" into the management listener.
diff --git a/handlers.go b/handlers.go index 8c69ec8..e54cd02 100644 --- a/handlers.go +++ b/handlers.go
@@ -4,6 +4,7 @@ "encoding/json" "errors" "net/http" + "net/http/pprof" ) /* @@ -49,6 +50,15 @@ s: s, mux: http.NewServeMux(), } + + // Manually register paths from "pprof" package because we are + // not using a standard HTTP handler here. + h.mux.HandleFunc("/debug/pprof/", pprof.Index) + h.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + h.mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + h.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + h.mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + if s.healthPath != "" { h.mux.HandleFunc(s.healthPath, s.handleHealth) }
diff --git a/httpstop.go b/httpstop.go deleted file mode 100644 index 49f014d..0000000 --- a/httpstop.go +++ /dev/null
@@ -1 +0,0 @@ -package goscaffold
diff --git a/scaffold.go b/scaffold.go index 629fcf8..55013d4 100644 --- a/scaffold.go +++ b/scaffold.go
@@ -453,7 +453,6 @@ go func() { for { - fmt.Printf("Listening for signals\n") sig := <-sigChan switch sig { case syscall.SIGINT, syscall.SIGTERM: @@ -468,7 +467,6 @@ } func dumpStack(out io.Writer) { - fmt.Printf("Got HUP\n") stackSize := 4096 stackBuf := make([]byte, stackSize) var w int
diff --git a/scaffold_test.go b/scaffold_test.go index 692602a..d3e3e98 100644 --- a/scaffold_test.go +++ b/scaffold_test.go
@@ -1,6 +1,7 @@ package goscaffold import ( + "bytes" "crypto/tls" "encoding/json" "errors" @@ -46,6 +47,7 @@ Expect(err).Should(Succeed()) resp.Body.Close() Expect(resp.StatusCode).Should(Equal(200)) + validatePprof(s.InsecureAddress()) shutdownErr := errors.New("Validate") s.Shutdown(shutdownErr) Eventually(stopChan).Should(Receive(Equal(shutdownErr))) @@ -79,6 +81,7 @@ Expect(err).Should(Succeed()) resp.Body.Close() Expect(resp.StatusCode).Should(Equal(404)) + validatePprof(s.ManagementAddress()) shutdownErr := errors.New("Validate") s.Shutdown(shutdownErr) Eventually(stopChan).Should(Receive(Equal(shutdownErr))) @@ -362,6 +365,12 @@ Eventually(stopChan).Should(Receive(Equal(shutdownErr))) }) + + It("Get stack trace", func() { + b := &bytes.Buffer{} + dumpStack(b) + Expect(b.Len()).ShouldNot(BeZero()) + }) }) func getText(url string) (int, string) { @@ -391,6 +400,14 @@ return resp.StatusCode, vals } +func validatePprof(addr string) { + code, _ := getText(fmt.Sprintf("http://%s/debug/pprof/", addr)) + Expect(code).Should(Equal(200)) + code, cmdline := getText(fmt.Sprintf("http://%s/debug/pprof/cmdline", addr)) + Expect(code).Should(Equal(200)) + Expect(cmdline).ShouldNot(BeEmpty()) +} + func testGet(s *HTTPScaffold, path string) bool { resp, err := http.Get(fmt.Sprintf("http://%s", s.InsecureAddress())) if err != nil {