task_runner: emit event on task exit with exit result details

This commit is contained in:
Nick Ethier 2018-11-16 14:17:23 -05:00
parent 8ef73e63ce
commit 29591a7c2e
No known key found for this signature in database
GPG key ID: 07C1A3ECED90D24A
2 changed files with 23 additions and 0 deletions

View file

@ -369,6 +369,9 @@ MAIN:
select { select {
case result = <-resultCh: case result = <-resultCh:
// WaitCh returned a result // WaitCh returned a result
if result != nil {
tr.handleTaskExitResult(result)
}
case <-tr.ctx.Done(): case <-tr.ctx.Done():
// TaskRunner was told to exit immediately // TaskRunner was told to exit immediately
return return
@ -410,6 +413,7 @@ MAIN:
event := structs.NewTaskEvent(structs.TaskTerminated). event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode). SetExitCode(result.ExitCode).
SetSignal(result.Signal). SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err) SetExitMessage(result.Err)
tr.UpdateState(structs.TaskStateDead, event) tr.UpdateState(structs.TaskStateDead, event)
} }
@ -422,6 +426,20 @@ MAIN:
tr.logger.Debug("task run loop exiting") tr.logger.Debug("task run loop exiting")
} }
func (tr *TaskRunner) handleTaskExitResult(result *drivers.ExitResult) {
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)
tr.EmitEvent(event)
if !tr.clientConfig.DisableTaggedMetrics {
metrics.IncrCounterWithLabels([]string{"client", "allocs", "oom_killed"}, 1, tr.baseLabels)
}
}
// handleUpdates runs update hooks when triggerUpdateCh is ticked and exits // handleUpdates runs update hooks when triggerUpdateCh is ticked and exits
// when Run has returned. Should only be run in a goroutine from Run. // when Run has returned. Should only be run in a goroutine from Run.
func (tr *TaskRunner) handleUpdates() { func (tr *TaskRunner) handleUpdates() {

View file

@ -6196,6 +6196,11 @@ func (e *TaskEvent) SetDriverMessage(m string) *TaskEvent {
return e return e
} }
func (e *TaskEvent) SetOOMKilled(oom bool) *TaskEvent {
e.Details["oom_killed"] = strconv.FormatBool(oom)
return e
}
// TaskArtifact is an artifact to download before running the task. // TaskArtifact is an artifact to download before running the task.
type TaskArtifact struct { type TaskArtifact struct {
// GetterSource is the source to download an artifact using go-getter // GetterSource is the source to download an artifact using go-getter