enable json formatting, use queryoptions

This commit is contained in:
Drew Bailey
2019-10-24 12:47:46 -04:00
parent 8095b4868a
commit e7589301ea
8 changed files with 56 additions and 28 deletions

View File

@@ -240,20 +240,13 @@ func (a *Agent) Health() (*AgentHealthResponse, error) {
// 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(loglevel string, nodeID string, stopCh <-chan struct{}, q *QueryOptions) (chan string, error) {
func (a *Agent) Monitor(stopCh <-chan struct{}, q *QueryOptions) (chan string, error) {
r, err := a.client.newRequest("GET", "/v1/agent/monitor")
if err != nil {
return nil, err
}
r.setQueryOptions(q)
if loglevel != "" {
r.params.Add("loglevel", loglevel)
}
if nodeID != "" {
r.params.Add("nodeID", nodeID)
}
_, resp, err := requireOK(a.client.doRequest(r))
if err != nil {
return nil, err
@@ -267,7 +260,6 @@ func (a *Agent) Monitor(loglevel string, nodeID string, stopCh <-chan struct{},
for {
select {
case <-stopCh:
close(logCh)
return
default:
}

View File

@@ -270,7 +270,12 @@ func TestAgent_MonitorServer(t *testing.T) {
agent := c.Agent()
doneCh := make(chan struct{})
logCh, err := agent.Monitor("debug", "", doneCh, nil)
q := &QueryOptions{
Params: map[string]string{
"log-level": "debug",
},
}
logCh, err := agent.Monitor(doneCh, q)
defer close(doneCh)
if err != nil {
t.Fatalf("err: %v", err)
@@ -301,9 +306,16 @@ func TestAgent_MonitorWithNode(t *testing.T) {
agent := c.Agent()
id, _ := uuid.GenerateUUID()
q := &QueryOptions{
Params: map[string]string{
"log-level": "debug",
"node-id": id,
},
}
doneCh := make(chan struct{})
// todo need to create or stub a nodeid?
logCh, err := agent.Monitor("debug", id, doneCh, nil)
logCh, err := agent.Monitor(doneCh, q)
defer close(doneCh)
if err != nil {
t.Fatalf("err: %v", err)