mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
enable json formatting, use queryoptions
This commit is contained in:
10
api/agent.go
10
api/agent.go
@@ -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:
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user