Skip to content

Commit

Permalink
agent Profile req nil check s.agent.Server()
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Feb 3, 2020
1 parent 1262f44 commit 0adbe4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,12 @@ func (s *HTTPServer) agentPprof(reqType pprof.ReqType, resp http.ResponseWriter,
rpcErr = s.agent.Server().RPC("Agent.Profile", &args, &reply)
}
} else {
// No node id target server
rpcErr = s.agent.Server().RPC("Agent.Profile", &args, &reply)
// No NodeID, profile current server/client
if srv := s.agent.Server(); srv != nil {
rpcErr = srv.RPC("Agent.Profile", &args, &reply)
} else {
rpcErr = s.agent.Client().RPC("Agent.Profile", &args, &reply)
}
}

if rpcErr != nil {
Expand Down
12 changes: 11 additions & 1 deletion command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,17 @@ func TestAgent_PprofRequest(t *testing.T) {
addNodeID bool
addServerID bool
expectedErr string
nilServer bool
}{
{
desc: "cmdline local request",
desc: "cmdline local server request",
url: "/v1/agent/pprof/cmdline",
},
{
desc: "cmdline local node request",
url: "/v1/agent/pprof/cmdline",
nilServer: true,
},
{
desc: "cmdline node request",
url: "/v1/agent/pprof/cmdline",
Expand Down Expand Up @@ -577,6 +583,10 @@ func TestAgent_PprofRequest(t *testing.T) {
url = url + "?server_id=" + s.server.LocalMember().Name
}

if tc.nilServer {
s.Agent.server = nil
}

req, err := http.NewRequest("GET", url, nil)
require.Nil(t, err)
respW := httptest.NewRecorder()
Expand Down

0 comments on commit 0adbe4c

Please sign in to comment.