diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 8d19d3c2df9..56c3631b7d1 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -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 diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index 504fc16348b..572742fe0f1 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -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)