Skip to content

Commit ad86438

Browse files
committed
adds qc param, address pr feedback
1 parent 2826508 commit ad86438

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

api/agent.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (a *Agent) Trace(serverID, nodeID string, seconds int, q *QueryOptions) ([]
376376
//
377377
// The call blocks until the profile finishes, and returns the raw bytes of the
378378
// profile.
379-
func (a *Agent) Profile(serverID, nodeID, profile string, debug int, q *QueryOptions) ([]byte, error) {
379+
func (a *Agent) Profile(serverID, nodeID, profile string, debug, gc int, q *QueryOptions) ([]byte, error) {
380380
if q == nil {
381381
q = &QueryOptions{}
382382
}
@@ -385,6 +385,7 @@ func (a *Agent) Profile(serverID, nodeID, profile string, debug int, q *QueryOpt
385385
}
386386

387387
q.Params["debug"] = strconv.Itoa(debug)
388+
q.Params["qc"] = strconv.Itoa(debug)
388389
q.Params["node_id"] = nodeID
389390
q.Params["server_id"] = serverID
390391

api/agent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,14 @@ func TestAgentProfile(t *testing.T) {
436436
}
437437

438438
{
439-
resp, err := agent.Profile("", "", "goroutine", 0, q)
439+
resp, err := agent.Profile("", "", "heap", 0, 1, q)
440440
require.NoError(t, err)
441441
require.NotNil(t, resp)
442442
}
443443

444444
// unknown profile
445445
{
446-
resp, err := agent.Profile("", "", "invalid", 1, q)
446+
resp, err := agent.Profile("", "", "invalid", 1, 1, q)
447447
require.Error(t, err)
448448
require.Contains(t, err.Error(), "Unexpected response code: 404")
449449
require.Nil(t, resp)

command/agent/http.go

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
363363
// wrapNonJSON is used to wrap functions returning non JSON
364364
// serializeable data to make them more convenient. It is primarily
365365
// responsible for setting nomad headers and logging.
366+
// Handler functions are responsible for setting Content-Type Header
366367
func (s *HTTPServer) wrapNonJSON(handler func(resp http.ResponseWriter, req *http.Request) ([]byte, error)) func(resp http.ResponseWriter, req *http.Request) {
367368
f := func(resp http.ResponseWriter, req *http.Request) {
368369
setHeaders(resp, s.agent.config.HTTPAPIResponseHeaders)

nomad/client_agent_endpoint.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func (a *Agent) register() {
2929
}
3030

3131
func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPprofResponse) error {
32+
// Check ACL for agent write
33+
aclObj, err := a.srv.ResolveToken(args.AuthToken)
34+
if err != nil {
35+
return err
36+
} else if aclObj != nil && !aclObj.AllowAgentWrite() {
37+
return structs.ErrPermissionDenied
38+
}
39+
3240
// Forward to different region if necessary
3341
// this would typically be done in a.srv.forward() but since
3442
// we are targeting a specific server, not just the leader
@@ -60,19 +68,9 @@ func (a *Agent) Profile(args *structs.AgentPprofRequest, reply *structs.AgentPpr
6068
}
6169
}
6270

63-
// Check ACL for agent write
64-
aclObj, err := a.srv.ResolveToken(args.AuthToken)
65-
if err != nil {
66-
return err
67-
} else if aclObj != nil && !aclObj.AllowAgentWrite() {
68-
return structs.ErrPermissionDenied
69-
}
70-
7171
// If ACLs are disabled, EnableDebug must be enabled
72-
if aclObj == nil {
73-
if !a.srv.config.EnableDebug {
74-
return structs.ErrPermissionDenied
75-
}
72+
if aclObj == nil && !a.srv.config.EnableDebug {
73+
return structs.ErrPermissionDenied
7674
}
7775

7876
// Process the request on this server

nomad/structs/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func IsErrUnknownMethod(err error) bool {
7979
}
8080

8181
func IsErrRPCCoded(err error) bool {
82-
return err != nil && strings.Contains(err.Error(), errRPCCodedErrorPrefix)
82+
return err != nil && strings.HasPrefix(err.Error(), errRPCCodedErrorPrefix)
8383
}
8484

8585
// NewErrUnknownAllocation returns a new error caused by the allocation being

0 commit comments

Comments
 (0)