Documentation ¶
Index ¶
- Variables
- type APILogger
- type CommandLogger
- func (cmdLgr *CommandLogger) Flush()
- func (cmdLgr *CommandLogger) GetSystemLogWriter(level slogger.Level) io.Writer
- func (cmdLgr *CommandLogger) GetTaskLogWriter(level slogger.Level) io.Writer
- func (cmdLgr *CommandLogger) LogExecution(level slogger.Level, messageFmt string, args ...interface{})
- func (cmdLgr *CommandLogger) LogLocal(level slogger.Level, messageFmt string, args ...interface{})
- func (cmdLgr *CommandLogger) LogSystem(level slogger.Level, messageFmt string, args ...interface{})
- func (cmdLgr *CommandLogger) LogTask(level slogger.Level, messageFmt string, args ...interface{})
- type HTTPCommunicator
- func (h *HTTPCommunicator) End(detail *apimodels.TaskEndDetail) (*apimodels.EndTaskResponse, error)
- func (h *HTTPCommunicator) FetchExpansionVars() (*apimodels.ExpansionVars, error)
- func (h *HTTPCommunicator) GetCurrentTaskId() string
- func (h *HTTPCommunicator) GetDistro() (*distro.Distro, error)
- func (h *HTTPCommunicator) GetNextTask() (*apimodels.NextTaskResponse, error)
- func (h *HTTPCommunicator) GetProjectRef() (*model.ProjectRef, error)
- func (h *HTTPCommunicator) GetTask() (*task.Task, error)
- func (h *HTTPCommunicator) GetVersion() (*version.Version, error)
- func (h *HTTPCommunicator) Heartbeat() (bool, error)
- func (h *HTTPCommunicator) Log(messages []model.LogMessage) error
- func (h *HTTPCommunicator) Reset(commSignal chan Signal, timeoutWatcher *TimeoutWatcher) (*APILogger, *StreamLogger, error)
- func (h *HTTPCommunicator) SetLogger(logger *slogger.Logger)
- func (h *HTTPCommunicator) SetSignalChan(communicatorChan chan Signal)
- func (h *HTTPCommunicator) SetTask(taskId, taskSecret string)
- func (h *HTTPCommunicator) Start() error
- func (h *HTTPCommunicator) TryGet(path string) (*http.Response, error)
- func (h *HTTPCommunicator) TryPostJSON(path string, data interface{}) (*http.Response, error)
- func (h *HTTPCommunicator) TryTaskGet(path string) (*http.Response, error)
- func (h *HTTPCommunicator) TryTaskPost(path string, data interface{}) (*http.Response, error)
- type Heartbeat
- type HeartbeatTicker
- type MockCommunicator
- func (mc *MockCommunicator) End(details *apimodels.TaskEndDetail) (*apimodels.EndTaskResponse, error)
- func (*MockCommunicator) FetchExpansionVars() (*apimodels.ExpansionVars, error)
- func (mc *MockCommunicator) GetCurrentTaskId() string
- func (*MockCommunicator) GetDistro() (*distro.Distro, error)
- func (*MockCommunicator) GetNextTask() (*apimodels.NextTaskResponse, error)
- func (*MockCommunicator) GetProjectRef() (*model.ProjectRef, error)
- func (*MockCommunicator) GetTask() (*task.Task, error)
- func (*MockCommunicator) GetVersion() (*version.Version, error)
- func (mc *MockCommunicator) Heartbeat() (bool, error)
- func (mc *MockCommunicator) Log(logMessages []model.LogMessage) error
- func (mc *MockCommunicator) Reset(commSignal chan Signal, timeoutWatcher *TimeoutWatcher) (*APILogger, *StreamLogger, error)
- func (m *MockCommunicator) SetLogger(*slogger.Logger)
- func (m *MockCommunicator) SetSignalChan(chan Signal)
- func (mc *MockCommunicator) SetTask(taskId, taskSecret string)
- func (mc *MockCommunicator) Start() error
- func (*MockCommunicator) TryGet(path string) (*http.Response, error)
- func (mc *MockCommunicator) TryPostJSON(path string, data interface{}) (*http.Response, error)
- func (*MockCommunicator) TryTaskGet(path string) (*http.Response, error)
- func (mc *MockCommunicator) TryTaskPost(path string, data interface{}) (*http.Response, error)
- type Signal
- type StreamLogger
- func (lgr *StreamLogger) Flush()
- func (lgr *StreamLogger) FlushAndWait() int
- func (lgr *StreamLogger) GetSystemLogWriter(level slogger.Level) io.Writer
- func (lgr *StreamLogger) GetTaskLogWriter(level slogger.Level) io.Writer
- func (lgr *StreamLogger) LogExecution(level slogger.Level, messageFmt string, args ...interface{})
- func (lgr *StreamLogger) LogLocal(level slogger.Level, messageFmt string, args ...interface{})
- func (lgr *StreamLogger) LogSystem(level slogger.Level, messageFmt string, args ...interface{})
- func (lgr *StreamLogger) LogTask(level slogger.Level, messageFmt string, args ...interface{})
- type TaskCommunicator
- type TaskJSONCommunicator
- func (t *TaskJSONCommunicator) PostTaskFiles(task_files []*artifact.File) error
- func (t *TaskJSONCommunicator) TaskGetJSON(endpoint string) (*http.Response, error)
- func (t *TaskJSONCommunicator) TaskPostJSON(endpoint string, data interface{}) (*http.Response, error)
- func (t *TaskJSONCommunicator) TaskPostResults(results *task.TestResults) error
- func (t *TaskJSONCommunicator) TaskPostTestLog(log *model.TestLog) (string, error)
- type TimeoutResetLogger
- type TimeoutWatcher
Constants ¶
This section is empty.
Variables ¶
var HTTPConflictError = errors.New("Conflict")
var HeartbeatTimeout = time.Minute
Functions ¶
This section is empty.
Types ¶
type APILogger ¶
type APILogger struct { // The number of log lines that the buffer must reach to trigger a flush SendAfterLines int // How long to wait without any flushes before triggering one automatically SendAfterDuration time.Duration // The mechanism for communicating with the remote endpoint. TaskCommunicator // contains filtered or unexported fields }
APILogger is a slogger.Appender which makes a call to the remote service's log endpoint after SendAfterLines messages have been received (or if set, after SendAfterDuration time has passed with no flush).
func NewAPILogger ¶
func NewAPILogger(tc TaskCommunicator) *APILogger
NewAPILogger creates an initialized logger around the given TaskCommunicator.
func (*APILogger) Append ¶
Append (to satisfy the Appender interface) adds a log message to the internal buffer, and translates the log message into a format that is used by the remote endpoint.
func (*APILogger) Flush ¶
func (apiLgr *APILogger) Flush()
Flush pushes log messages (asynchronously, without waiting for messages to send.)
func (*APILogger) FlushAndWait ¶
type CommandLogger ¶
type CommandLogger struct {
// contains filtered or unexported fields
}
Wraps an Logger, with additional context about which command is currently being run.
func NewCommandLogger ¶
func NewCommandLogger(name string, logger *StreamLogger) *CommandLogger
func (*CommandLogger) Flush ¶
func (cmdLgr *CommandLogger) Flush()
func (*CommandLogger) GetSystemLogWriter ¶
func (cmdLgr *CommandLogger) GetSystemLogWriter(level slogger.Level) io.Writer
func (*CommandLogger) GetTaskLogWriter ¶
func (cmdLgr *CommandLogger) GetTaskLogWriter(level slogger.Level) io.Writer
func (*CommandLogger) LogExecution ¶
func (cmdLgr *CommandLogger) LogExecution(level slogger.Level, messageFmt string, args ...interface{})
func (*CommandLogger) LogLocal ¶
func (cmdLgr *CommandLogger) LogLocal(level slogger.Level, messageFmt string, args ...interface{})
type HTTPCommunicator ¶
type HTTPCommunicator struct { ServerURLRoot string TaskId string TaskSecret string HostId string HostSecret string MaxAttempts int RetrySleep time.Duration SignalChan chan Signal Logger *slogger.Logger HttpsCert string // contains filtered or unexported fields }
HTTPCommunicator handles communication with the API server. An HTTPCommunicator is scoped to a single task, and all communication performed by it is only relevant to that running task.
func NewHTTPCommunicator ¶
func NewHTTPCommunicator(serverURL, hostId, hostSecret, cert string) (*HTTPCommunicator, error)
NewHTTPCommunicator returns an initialized HTTPCommunicator. The cert parameter may be blank if default system certificates are being used.
func (*HTTPCommunicator) End ¶
func (h *HTTPCommunicator) End(detail *apimodels.TaskEndDetail) (*apimodels.EndTaskResponse, error)
End marks the communicator's task as finished with the given status.
func (*HTTPCommunicator) FetchExpansionVars ¶
func (h *HTTPCommunicator) FetchExpansionVars() (*apimodels.ExpansionVars, error)
FetchExpansionVars loads expansions for a communicator's task from the API server.
func (*HTTPCommunicator) GetCurrentTaskId ¶
func (h *HTTPCommunicator) GetCurrentTaskId() string
func (*HTTPCommunicator) GetDistro ¶
func (h *HTTPCommunicator) GetDistro() (*distro.Distro, error)
GetDistro returns the distro for the communicator's task.
func (*HTTPCommunicator) GetNextTask ¶
func (h *HTTPCommunicator) GetNextTask() (*apimodels.NextTaskResponse, error)
GetNextTask returns a next task response by getting the next task for a given host.
func (*HTTPCommunicator) GetProjectRef ¶
func (h *HTTPCommunicator) GetProjectRef() (*model.ProjectRef, error)
GetProjectConfig loads the communicator's task's project from the API server.
func (*HTTPCommunicator) GetTask ¶
func (h *HTTPCommunicator) GetTask() (*task.Task, error)
GetTask returns the communicator's task.
func (*HTTPCommunicator) GetVersion ¶
func (h *HTTPCommunicator) GetVersion() (*version.Version, error)
GetVersion loads the communicator's task's version from the API server.
func (*HTTPCommunicator) Heartbeat ¶
func (h *HTTPCommunicator) Heartbeat() (bool, error)
Heartbeat sends a heartbeat to the API server. The server can respond with and "abort" response. This function returns true if the agent should abort.
func (*HTTPCommunicator) Log ¶
func (h *HTTPCommunicator) Log(messages []model.LogMessage) error
Log sends a batch of log messages for the task's logs to the API server.
func (*HTTPCommunicator) Reset ¶
func (h *HTTPCommunicator) Reset(commSignal chan Signal, timeoutWatcher *TimeoutWatcher) (*APILogger, *StreamLogger, error)
func (*HTTPCommunicator) SetLogger ¶
func (h *HTTPCommunicator) SetLogger(logger *slogger.Logger)
func (*HTTPCommunicator) SetSignalChan ¶
func (h *HTTPCommunicator) SetSignalChan(communicatorChan chan Signal)
func (*HTTPCommunicator) SetTask ¶
func (h *HTTPCommunicator) SetTask(taskId, taskSecret string)
func (*HTTPCommunicator) Start ¶
func (h *HTTPCommunicator) Start() error
Start marks the communicator's task as started.
func (*HTTPCommunicator) TryGet ¶
func (h *HTTPCommunicator) TryGet(path string) (*http.Response, error)
func (*HTTPCommunicator) TryPostJSON ¶
func (h *HTTPCommunicator) TryPostJSON(path string, data interface{}) (*http.Response, error)
func (*HTTPCommunicator) TryTaskGet ¶
func (h *HTTPCommunicator) TryTaskGet(path string) (*http.Response, error)
func (*HTTPCommunicator) TryTaskPost ¶
func (h *HTTPCommunicator) TryTaskPost(path string, data interface{}) (*http.Response, error)
type Heartbeat ¶
Heartbeat encapsulates heartbeat behavior (i.e., pinging the API server at regular intervals to ensure that communication hasn't broken down).
type HeartbeatTicker ¶
type HeartbeatTicker struct { // Number of consecutive failed heartbeats allowed before signaling a failure MaxFailedHeartbeats int // Period of time to wait between heartbeat attempts Interval time.Duration // Channel on which to notify of failed heartbeats or aborted task SignalChan chan<- Signal // Interface which handles sending the actual heartbeat over the network TaskCommunicator Logger *slogger.Logger // contains filtered or unexported fields }
HeartbeatTicker manages heartbeat communication with the API server
func NewHeartbeatTicker ¶
func NewHeartbeatTicker(stopper <-chan struct{}) *HeartbeatTicker
func (*HeartbeatTicker) StartHeartbeating ¶
func (hbt *HeartbeatTicker) StartHeartbeating()
type MockCommunicator ¶
type MockCommunicator struct { TaskId string TaskSecret string LogChan chan []model.LogMessage Posts map[string][]interface{} sync.RWMutex // contains filtered or unexported fields }
func (*MockCommunicator) End ¶
func (mc *MockCommunicator) End(details *apimodels.TaskEndDetail) (*apimodels.EndTaskResponse, error)
func (*MockCommunicator) FetchExpansionVars ¶
func (*MockCommunicator) FetchExpansionVars() (*apimodels.ExpansionVars, error)
func (*MockCommunicator) GetCurrentTaskId ¶
func (mc *MockCommunicator) GetCurrentTaskId() string
func (*MockCommunicator) GetNextTask ¶
func (*MockCommunicator) GetNextTask() (*apimodels.NextTaskResponse, error)
func (*MockCommunicator) GetProjectRef ¶
func (*MockCommunicator) GetProjectRef() (*model.ProjectRef, error)
func (*MockCommunicator) GetVersion ¶
func (*MockCommunicator) GetVersion() (*version.Version, error)
func (*MockCommunicator) Heartbeat ¶
func (mc *MockCommunicator) Heartbeat() (bool, error)
func (*MockCommunicator) Log ¶
func (mc *MockCommunicator) Log(logMessages []model.LogMessage) error
func (*MockCommunicator) Reset ¶
func (mc *MockCommunicator) Reset(commSignal chan Signal, timeoutWatcher *TimeoutWatcher) (*APILogger, *StreamLogger, error)
func (*MockCommunicator) SetLogger ¶
func (m *MockCommunicator) SetLogger(*slogger.Logger)
func (*MockCommunicator) SetSignalChan ¶
func (m *MockCommunicator) SetSignalChan(chan Signal)
func (*MockCommunicator) SetTask ¶
func (mc *MockCommunicator) SetTask(taskId, taskSecret string)
func (*MockCommunicator) Start ¶
func (mc *MockCommunicator) Start() error
func (*MockCommunicator) TryGet ¶
func (*MockCommunicator) TryGet(path string) (*http.Response, error)
func (*MockCommunicator) TryPostJSON ¶
func (mc *MockCommunicator) TryPostJSON(path string, data interface{}) (*http.Response, error)
func (*MockCommunicator) TryTaskGet ¶
func (*MockCommunicator) TryTaskGet(path string) (*http.Response, error)
func (*MockCommunicator) TryTaskPost ¶
func (mc *MockCommunicator) TryTaskPost(path string, data interface{}) (*http.Response, error)
type Signal ¶
type Signal int64
Signal describes the various conditions under which the agent will complete execution of a task.
const ( // HeartbeatMaxFailed indicates that repeated attempts to send heartbeat to // the API server fails. HeartbeatMaxFailed Signal = iota // IncorrectSecret indicates that the secret for the task the agent is running // does not match the task secret held by API server. IncorrectSecret // AbortedByUser indicates a user decided to prematurely end the task. AbortedByUser // IdleTimeout indicates the task appears to be idle - e.g. no logs produced // for the duration indicated by DefaultIdleTimeout. IdleTimeout // Completed indicates that the task completed without incident. This signal is // used internally to shut down the signal handler. Completed // Directory Failure indicates that the task failed due to a problem for the agent // creating or moving into a new directory. DirectoryFailure )
Recognized agent signals.
type StreamLogger ¶
type StreamLogger struct { // Local is used for file system logging on the host the agent is running on. Local *slogger.Logger // System is used for logging system stats gotten from commands like df, ps, etc. System *slogger.Logger // Task is used for logging command input, output and errors of the task. Task *slogger.Logger // Execution is used for logging the agent's internal state. Execution *slogger.Logger // contains filtered or unexported fields }
StreamLogger holds a set of stream-delineated loggers. Each logger is used to communicate different kinds of logs to the API Server or local file system. StreamLogger is used to distinguish logs of system statistics, shell output, and internal agent logs.
func NewStreamLogger ¶
func NewStreamLogger(timeoutWatcher *TimeoutWatcher, apiLgr *APILogger) (*StreamLogger, error)
NewStreamLogger creates a StreamLogger wrapper for the apiLogger with a given timeoutWatcher. Any logged messages on the StreamLogger will reset the TimeoutWatcher.
func (*StreamLogger) Flush ¶
func (lgr *StreamLogger) Flush()
Flush flushes the logs to the server. Returns immediately.
func (*StreamLogger) FlushAndWait ¶
func (lgr *StreamLogger) FlushAndWait() int
FlushAndWait flushes and blocks until the HTTP request to send the logs has completed. This works in contrast with Flush, which triggers the flush asynchronously.
func (*StreamLogger) GetSystemLogWriter ¶
func (lgr *StreamLogger) GetSystemLogWriter(level slogger.Level) io.Writer
GetSystemLogWriter returns an io.Writer of the given level that writes to the system log stream.
func (*StreamLogger) GetTaskLogWriter ¶
func (lgr *StreamLogger) GetTaskLogWriter(level slogger.Level) io.Writer
GetTaskLogWriter returns an io.Writer of the given level that writes to the task log stream.
func (*StreamLogger) LogExecution ¶
func (lgr *StreamLogger) LogExecution(level slogger.Level, messageFmt string, args ...interface{})
LogExecution logs a message related to the agent's internal workings.
Internally this is used to log things like heartbeats and command internals that would pollute the regular task test output.
func (*StreamLogger) LogLocal ¶
func (lgr *StreamLogger) LogLocal(level slogger.Level, messageFmt string, args ...interface{})
LogLocal logs a message to the agent logs on the machine's local file system.
Anything logged by this method will not be sent to the server, so only use it to log information that would only be useful when debugging locally.
func (*StreamLogger) LogSystem ¶
func (lgr *StreamLogger) LogSystem(level slogger.Level, messageFmt string, args ...interface{})
LogSystem logs passive system messages.
Internally this is used for periodically logging process information and CPU usage.
func (*StreamLogger) LogTask ¶
func (lgr *StreamLogger) LogTask(level slogger.Level, messageFmt string, args ...interface{})
LogTask logs a message to the task's logs.
This log type is for main task input and output. LogTask should be used for logging first-class information like test results and shell script output.
type TaskCommunicator ¶
type TaskCommunicator interface { Start() error End(detail *apimodels.TaskEndDetail) (*apimodels.EndTaskResponse, error) GetTask() (*task.Task, error) GetProjectRef() (*model.ProjectRef, error) GetDistro() (*distro.Distro, error) GetVersion() (*version.Version, error) Log([]model.LogMessage) error Heartbeat() (bool, error) FetchExpansionVars() (*apimodels.ExpansionVars, error) GetNextTask() (*apimodels.NextTaskResponse, error) TryTaskGet(path string) (*http.Response, error) TryTaskPost(path string, data interface{}) (*http.Response, error) TryGet(path string) (*http.Response, error) TryPostJSON(path string, data interface{}) (*http.Response, error) SetTask(taskId, taskSecret string) GetCurrentTaskId() string SetSignalChan(chan Signal) SetLogger(*slogger.Logger) }
TaskCommunicator is an interface that handles the remote procedure calls between an agent and the remote server.
type TaskJSONCommunicator ¶
type TaskJSONCommunicator struct { PluginName string TaskCommunicator }
TaskJSONCommunicator handles plugin-specific JSON-encoded communication with the API server.
func (*TaskJSONCommunicator) PostTaskFiles ¶
func (t *TaskJSONCommunicator) PostTaskFiles(task_files []*artifact.File) error
PostTaskFiles is used by the PluginCommunicator interface for attaching task files.
func (*TaskJSONCommunicator) TaskGetJSON ¶
func (t *TaskJSONCommunicator) TaskGetJSON(endpoint string) (*http.Response, error)
TaskGetJSON does an HTTP GET for the communicator's plugin + task.
func (*TaskJSONCommunicator) TaskPostJSON ¶
func (t *TaskJSONCommunicator) TaskPostJSON(endpoint string, data interface{}) (*http.Response, error)
TaskPostJSON does an HTTP POST for the communicator's plugin + task.
func (*TaskJSONCommunicator) TaskPostResults ¶
func (t *TaskJSONCommunicator) TaskPostResults(results *task.TestResults) error
TaskPostResults posts a set of test results for the communicator's task. If results are empty or nil, this operation is a noop.
func (*TaskJSONCommunicator) TaskPostTestLog ¶
func (t *TaskJSONCommunicator) TaskPostTestLog(log *model.TestLog) (string, error)
TaskPostTestLog posts a test log for a communicator's task. Is a noop if the test Log is nil.
type TimeoutResetLogger ¶
type TimeoutResetLogger struct { *TimeoutWatcher *APILogger }
TimeoutResetLogger wraps any slogger.Appender and resets a TimeoutWatcher each time any log message is appended to it.
type TimeoutWatcher ¶
type TimeoutWatcher struct {
// contains filtered or unexported fields
}
TimeoutWatcher tracks and handles command timeout within the agent.
func NewTimeoutWatcher ¶
func NewTimeoutWatcher(stopChan <-chan struct{}) *TimeoutWatcher
func (*TimeoutWatcher) CheckIn ¶
func (tw *TimeoutWatcher) CheckIn()
CheckIn resets the idle timer to zero.
func (*TimeoutWatcher) NotifyTimeouts ¶
func (tw *TimeoutWatcher) NotifyTimeouts(sigChan chan<- Signal)
NotifyTimeouts sends a signal on sigChan whenever the timeout threshold of the current execution stage is reached.
func (*TimeoutWatcher) SetDuration ¶
func (tw *TimeoutWatcher) SetDuration(duration time.Duration)
SetDuration sets the duration after which a timeout is triggered.