Skip to content

Commit

Permalink
adds qc param, address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Dec 20, 2019
1 parent 9bef9e0 commit 7c30f10
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (a *Agent) Trace(serverID, nodeID string, seconds int, q *QueryOptions) ([]
//
// The call blocks until the profile finishes, and returns the raw bytes of the
// profile.
func (a *Agent) Profile(serverID, nodeID, profile string, debug int, q *QueryOptions) ([]byte, error) {
func (a *Agent) Profile(serverID, nodeID, profile string, debug, gc int, q *QueryOptions) ([]byte, error) {
if q == nil {
q = &QueryOptions{}
}
Expand All @@ -385,6 +385,7 @@ func (a *Agent) Profile(serverID, nodeID, profile string, debug int, q *QueryOpt
}

q.Params["debug"] = strconv.Itoa(debug)
q.Params["qc"] = strconv.Itoa(debug)
q.Params["node_id"] = nodeID
q.Params["server_id"] = serverID

Expand Down
4 changes: 2 additions & 2 deletions api/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,14 @@ func TestAgentProfile(t *testing.T) {
}

{
resp, err := agent.Profile("", "", "goroutine", 0, q)
resp, err := agent.Profile("", "", "heap", 0, 1, q)
require.NoError(t, err)
require.NotNil(t, resp)
}

// unknown profile
{
resp, err := agent.Profile("", "", "invalid", 1, q)
resp, err := agent.Profile("", "", "invalid", 1, 1, q)
require.Error(t, err)
require.Contains(t, err.Error(), "Unexpected response code: 404")
require.Nil(t, resp)
Expand Down
1 change: 1 addition & 0 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
// wrapNonJSON is used to wrap functions returning non JSON
// serializeable data to make them more convenient. It is primarily
// responsible for setting nomad headers and logging.
// Handler functions are responsible for setting Content-Type Header
func (s *HTTPServer) wrapNonJSON(handler func(resp http.ResponseWriter, req *http.Request) ([]byte, error)) func(resp http.ResponseWriter, req *http.Request) {
f := func(resp http.ResponseWriter, req *http.Request) {
setHeaders(resp, s.agent.config.HTTPAPIResponseHeaders)
Expand Down
22 changes: 10 additions & 12 deletions nomad/client_agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func (a *Agent) register() {
}

func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPprofResponse) error {
// Check ACL for agent write
aclObj, err := a.srv.ResolveToken(args.AuthToken)
if err != nil {
return err
} else if aclObj != nil && !aclObj.AllowAgentWrite() {
return structs.ErrPermissionDenied
}

// Forward to different region if necessary
// this would typically be done in a.srv.forward() but since
// we are targeting a specific server, not just the leader
Expand Down Expand Up @@ -60,19 +68,9 @@ func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPpr
}
}

// Check ACL for agent write
aclObj, err := a.srv.ResolveToken(args.AuthToken)
if err != nil {
return err
} else if aclObj != nil && !aclObj.AllowAgentWrite() {
return structs.ErrPermissionDenied
}

// If ACLs are disabled, EnableDebug must be enabled
if aclObj == nil {
if !a.srv.config.EnableDebug {
return structs.ErrPermissionDenied
}
if aclObj == nil && !a.srv.config.EnableDebug {
return structs.ErrPermissionDenied
}

// Process the request on this server
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func IsErrUnknownMethod(err error) bool {
}

func IsErrRPCCoded(err error) bool {
return err != nil && strings.Contains(err.Error(), errRPCCodedErrorPrefix)
return err != nil && strings.HasPrefix(err.Error(), errRPCCodedErrorPrefix)
}

// NewErrUnknownAllocation returns a new error caused by the allocation being
Expand Down

0 comments on commit 7c30f10

Please sign in to comment.