Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pprof endpoint #1148

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.2.1 [unreleased]

### Release Notes

### Features

### Bugfixes

- [#1147](https://github.com/influxdata/kapacitor/issues/1147): Fix pprof debug endpoint


## v1.2.0 [2017-01-23]

### Release Notes
50 changes: 50 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
@@ -70,6 +70,56 @@ func TestServer_Ping(t *testing.T) {
t.Fatal("unexpected version", version)
}
}

func TestServer_Pprof_Index(t *testing.T) {
s, _ := OpenDefaultServer()
defer s.Close()
testCases := []struct {
path string
code int
contentType string
}{
{
path: "/debug/pprof/",
code: http.StatusOK,
contentType: "text/html; charset=utf-8",
},
{
path: "/debug/pprof/block",
code: http.StatusOK,
contentType: "text/plain; charset=utf-8",
},
{
path: "/debug/pprof/goroutine",
code: http.StatusOK,
contentType: "text/plain; charset=utf-8",
},
{
path: "/debug/pprof/heap",
code: http.StatusOK,
contentType: "text/plain; charset=utf-8",
},
{
path: "/debug/pprof/threadcreate",
code: http.StatusOK,
contentType: "text/plain; charset=utf-8",
},
}
for _, tc := range testCases {
t.Run(tc.path, func(t *testing.T) {
r, err := http.Get(s.URL() + tc.path)
if err != nil {
t.Fatal(err)
}
if got, exp := r.StatusCode, tc.code; got != exp {
t.Errorf("unexpected status code got %d exp %d", got, exp)
}
if got, exp := r.Header.Get("Content-Type"), tc.contentType; got != exp {
t.Errorf("unexpected content type got %s exp %s", got, exp)
}
})
}
}
func TestServer_Authenticate_Fail(t *testing.T) {
conf := NewConfig()
conf.HTTP.AuthEnabled = true
9 changes: 8 additions & 1 deletion services/httpd/handler.go
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ func NewHandler(
{
Method: "GET",
Pattern: BasePath + "/debug/pprof/",
HandlerFunc: pprof.Index,
HandlerFunc: servePprof,
noJSON: true,
},
{
@@ -523,6 +523,13 @@ func MarshalJSON(v interface{}, pretty bool) []byte {
return b
}

func servePprof(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, BasePath)
r.URL.Path = p
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pprof.Index(w, r)
}

// serveExpvar serves registered expvar information over HTTP.
func serveExpvar(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "{\n")