diff --git a/api/agent.go b/api/agent.go index 936ac1e4c..fdd5ff891 100644 --- a/api/agent.go +++ b/api/agent.go @@ -244,7 +244,6 @@ type MonitorFrame struct { // Monitor returns a channel which will receive streaming logs from the agent // Providing a non-nil stopCh can be used to close the connection and stop log streaming func (a *Agent) Monitor(stopCh <-chan struct{}, q *QueryOptions) (<-chan *StreamFrame, <-chan error) { - errCh := make(chan error, 1) r, err := a.client.newRequest("GET", "/v1/agent/monitor") if err != nil { diff --git a/api/agent_test.go b/api/agent_test.go index 079ba44c1..d01cfdf27 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -1,7 +1,6 @@ package api import ( - "bytes" "fmt" "reflect" "sort" @@ -320,7 +319,6 @@ func TestAgent_MonitorWithNode(t *testing.T) { require.NoError(t, err) // Wait for a log message - var result bytes.Buffer OUTER: for { select { diff --git a/client/agent_endpoint.go b/client/agent_endpoint.go index e15e74da4..6ad62bae4 100644 --- a/client/agent_endpoint.go +++ b/client/agent_endpoint.go @@ -29,10 +29,6 @@ func NewAgentEndpoint(c *Client) *Agent { return m } -type monitorFrame struct { - Data []byte `json:",omitempty"` -} - func (m *Agent) monitor(conn io.ReadWriteCloser) { defer metrics.MeasureSince([]string{"client", "monitor", "monitor"}, time.Now()) defer conn.Close() diff --git a/command/agent/monitor/monitor_test.go b/command/agent/monitor/monitor_test.go index bb6cedaf2..be7deae2c 100644 --- a/command/agent/monitor/monitor_test.go +++ b/command/agent/monitor/monitor_test.go @@ -22,20 +22,23 @@ func TestMonitor_Start(t *testing.T) { }) closeCh := make(chan struct{}) - defer close(closeCh) logCh := m.Start(closeCh) + go func() { - for { - select { - case log := <-logCh: - require.Contains(t, string(log), "[DEBUG] test log") - case <-time.After(1 * time.Second): - t.Fatal("Expected to receive from log channel") - } - } + logger.Debug("test log") + time.Sleep(10 * time.Millisecond) }() - logger.Debug("test log") + + for { + select { + case log := <-logCh: + require.Contains(t, string(log), "[DEBUG] test log") + return + case <-time.After(3 * time.Second): + t.Fatal("Expected to receive from log channel") + } + } } // Ensure number of dropped messages are logged @@ -61,7 +64,6 @@ func TestMonitor_DroppedMessages(t *testing.T) { } received := "" - passed := make(chan struct{}) go func() { for { diff --git a/command/agent_monitor.go b/command/agent_monitor.go index ba5dbd0df..3fc86d48c 100644 --- a/command/agent_monitor.go +++ b/command/agent_monitor.go @@ -74,6 +74,13 @@ func (c *MonitorCommand) Run(args []string) int { return 1 } + args = flags.Args() + if l := len(args); l != 0 { + c.Ui.Error("This command takes no arguments") + c.Ui.Error(commandErrorText(c)) + return 1 + } + client, err := c.Meta.Client() if err != nil { c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))