Skip to content

Commit

Permalink
wireup plain=true|false query param
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Nov 5, 2019
1 parent 79411c5 commit 1585179
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
18 changes: 15 additions & 3 deletions command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,24 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (
logJSON = parsed
}

plainText := false
plainTextStr := req.URL.Query().Get("plain")
if plainTextStr != "" {
parsed, err := strconv.ParseBool(plainTextStr)
if err != nil {
return nil, CodedError(400, fmt.Sprintf("Unknown option for plain: %v", err))
}
plainText = parsed
}

// Build the request and parse the ACL token
args := cstructs.MonitorRequest{
NodeID: nodeID,
LogLevel: logLevel,
LogJSON: logJSON,
NodeID: nodeID,
LogLevel: logLevel,
LogJSON: logJSON,
PlainText: plainText,
}

s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions)

// Make the RPC
Expand Down
33 changes: 33 additions & 0 deletions command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,39 @@ func TestHTTP_AgentMonitor(t *testing.T) {
})
}

// plain param set to true
{
req, err := http.NewRequest("GET", "/v1/agent/monitor?log_level=debug&plain=true", nil)
require.Nil(t, err)
resp := newClosableRecorder()
defer resp.Close()

go func() {
_, err = s.Server.AgentMonitor(resp, req)
require.NoError(t, err)
}()

// send the same log until monitor sink is set up
maxLogAttempts := 10
tried := 0
testutil.WaitForResult(func() (bool, error) {
if tried < maxLogAttempts {
s.Server.logger.Debug("log that should be sent")
tried++
}

got := resp.Body.String()
want := `[DEBUG] http: log that should be sent`
if strings.Contains(got, want) {
return true, nil
}

return false, fmt.Errorf("missing expected log, got: %v, want: %v", got, want)
}, func(err error) {
require.Fail(t, err.Error())
})
}

// stream logs for a given node
{
req, err := http.NewRequest("GET", "/v1/agent/monitor?log_level=warn&node_id="+s.client.NodeID(), nil)
Expand Down

0 comments on commit 1585179

Please sign in to comment.