only look up rpchandler for node if we have nodeid

fix some comments and nomad monitor -h output
This commit is contained in:
Drew Bailey 2019-10-25 10:58:54 -04:00
parent 2533617888
commit f46fd5b3e1
No known key found for this signature in database
GPG Key ID: FBA61B9FB7CCE1A7
5 changed files with 20 additions and 13 deletions

View File

@ -192,13 +192,12 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (
} }
s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions) s.parse(resp, req, &args.QueryOptions.Region, &args.QueryOptions)
// Determine the handler to use
useLocalClient, useClientRPC, useServerRPC := s.rpcHandlerForNode(nodeID)
// Make the RPC // Make the RPC
var handler structs.StreamingRpcHandler var handler structs.StreamingRpcHandler
var handlerErr error var handlerErr error
if nodeID != "" { if nodeID != "" {
// Determine the handler to use
useLocalClient, useClientRPC, useServerRPC := s.rpcHandlerForNode(nodeID)
if useLocalClient { if useLocalClient {
handler, handlerErr = s.agent.Client().StreamingRpcHandler("Agent.Monitor") handler, handlerErr = s.agent.Client().StreamingRpcHandler("Agent.Monitor")
} else if useClientRPC { } else if useClientRPC {
@ -229,10 +228,10 @@ func (s *HTTPServer) AgentMonitor(resp http.ResponseWriter, req *http.Request) (
// Create an ouput that gets flushed on every write // Create an ouput that gets flushed on every write
output := ioutils.NewWriteFlusher(resp) output := ioutils.NewWriteFlusher(resp)
// Create a channel that decodes the results // create an error channel to handle errors
errCh := make(chan HTTPCodedError, 2) errCh := make(chan HTTPCodedError, 2)
// stream the response // stream response
go func() { go func() {
defer cancel() defer cancel()

View File

@ -279,8 +279,7 @@ func TestHTTP_AgentMonitor(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}() }()
// send the same log a few times until monitor sink is // send the same log until monitor sink is set up
// fully set up
maxLogAttempts := 10 maxLogAttempts := 10
tried := 0 tried := 0
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
@ -315,8 +314,7 @@ func TestHTTP_AgentMonitor(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}() }()
// send the same log a few times until monitor sink is // send the same log until monitor sink is set up
// fully set up
maxLogAttempts := 10 maxLogAttempts := 10
tried := 0 tried := 0
out := "" out := ""
@ -370,7 +368,6 @@ func TestHTTP_AgentForceLeave(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) { httpTest(t, nil, func(s *TestAgent) {
// Make the HTTP request // Make the HTTP request
req, err := http.NewRequest("PUT", "/v1/agent/force-leave?node=foo", nil) req, err := http.NewRequest("PUT", "/v1/agent/force-leave?node=foo", nil)
require.Nil(t, err)
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }

View File

@ -382,7 +382,6 @@ func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, io.Writer)
Writer: &cli.UiWriter{Ui: c.Ui}, Writer: &cli.UiWriter{Ui: c.Ui},
} }
// TODO can this be killed
c.logFilter = LevelFilter() c.logFilter = LevelFilter()
c.logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel)) c.logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel))
c.logFilter.Writer = logGate c.logFilter.Writer = logGate

View File

@ -206,7 +206,7 @@ RETRY:
func (a *TestAgent) start() (*Agent, error) { func (a *TestAgent) start() (*Agent, error) {
if a.LogOutput == nil { if a.LogOutput == nil {
a.LogOutput = io.MultiWriter(testlog.NewWriter(a.T)) a.LogOutput = testlog.NewWriter(a.T)
} }
inm := metrics.NewInmemSink(10*time.Second, time.Minute) inm := metrics.NewInmemSink(10*time.Second, time.Minute)

View File

@ -28,7 +28,19 @@ Usage: nomad monitor [options]
General Options: General Options:
` + generalOptionsUsage() ` + generalOptionsUsage() + `
Monitor Specific Options:
-log-level <level>
Sets the log level to monitor (default: INFO)
-node-id <node-id>
Sets the specific node to monitor
-log-json <true|false>
Sets log output to JSON format
`
return strings.TrimSpace(helpText) return strings.TrimSpace(helpText)
} }