diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 584fb7ece..f7d272c2d 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -415,13 +415,11 @@ func (s *HTTPServer) agentPprofReq(reqType profile.ReqType, profile string, resp } if rpcErr != nil { + // TODO: rpcErr should return codedErr return nil, rpcErr } - // resp.Write(reply.Payload) - return reply.Payload, nil - // return string(reply.Payload), rpcErr } // AgentServersRequest is used to query the list of servers used by the Nomad diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index a9b0efcba..b7f1e9845 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -394,7 +394,7 @@ func TestAgent_PprofRequest(t *testing.T) { url string addNodeID bool addServerID bool - expectedErr error + expectedErr string expectedStatus int }{ { @@ -403,6 +403,31 @@ func TestAgent_PprofRequest(t *testing.T) { addNodeID: true, expectedStatus: 200, }, + { + desc: "cpu profile request", + url: "/v1/agent/pprof/profile", + addNodeID: true, + expectedStatus: 200, + }, + { + desc: "trace request", + url: "/v1/agent/pprof/trace", + addNodeID: true, + expectedStatus: 200, + }, + { + desc: "pprof lookup request", + url: "/v1/agent/pprof/goroutine", + addNodeID: true, + expectedStatus: 200, + }, + { + desc: "unknown pprof lookup request", + url: "/v1/agent/pprof/latency", + addNodeID: true, + expectedStatus: 404, + expectedErr: "Unknown profile: latency", + }, } for _, tc := range cases { @@ -423,7 +448,7 @@ func TestAgent_PprofRequest(t *testing.T) { resp, err := s.Server.AgentPprofRequest(respW, req) - if tc.expectedErr != nil { + if tc.expectedErr != "" { require.Error(t, err) } else { require.NoError(t, err)