mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Add nomad monitor export command (#26178)
* Add MonitorExport command and handlers * Implement autocomplete * Require nomad in serviceName * Fix race in StreamReader.Read * Add and use framer.Flush() to coordinate function exit * Add LogFile to client/Server config and read NomadLogPath in rpcHandler instead of HTTPServer * Parameterize StreamFixed stream size
This commit is contained in:
14
api/agent.go
14
api/agent.go
@@ -302,8 +302,20 @@ func (a *Agent) Host(serverID, nodeID string, q *QueryOptions) (*HostDataRespons
|
||||
// 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) {
|
||||
frames, errCh := a.monitorHelper(stopCh, q, "/v1/agent/monitor")
|
||||
return frames, errCh
|
||||
}
|
||||
|
||||
// MonitorExport 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) MonitorExport(stopCh <-chan struct{}, q *QueryOptions) (<-chan *StreamFrame, <-chan error) {
|
||||
frames, errCh := a.monitorHelper(stopCh, q, "/v1/agent/monitor/export")
|
||||
return frames, errCh
|
||||
}
|
||||
|
||||
func (a *Agent) monitorHelper(stopCh <-chan struct{}, q *QueryOptions, path string) (chan *StreamFrame, chan error) {
|
||||
errCh := make(chan error, 1)
|
||||
r, err := a.client.newRequest("GET", "/v1/agent/monitor")
|
||||
r, err := a.client.newRequest("GET", path)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return nil, errCh
|
||||
|
||||
15
api/fs.go
15
api/fs.go
@@ -389,12 +389,23 @@ func (f *FrameReader) Read(p []byte) (n int, err error) {
|
||||
case <-unblock:
|
||||
return 0, nil
|
||||
case err := <-f.errCh:
|
||||
return 0, err
|
||||
// check for race with f.frames before returning error
|
||||
select {
|
||||
case frame, ok := <-f.frames:
|
||||
if !ok {
|
||||
return 0, io.EOF
|
||||
}
|
||||
f.frame = frame
|
||||
|
||||
// Store the total offset into the file
|
||||
f.byteOffset = int(f.frame.Offset)
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
case <-f.cancelCh:
|
||||
return 0, io.EOF
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the data out of the frame and update our offset
|
||||
n = copy(p, f.frame.Data[f.frameOffset:])
|
||||
f.frameOffset += n
|
||||
|
||||
Reference in New Issue
Block a user