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 {
case result = <-resultCh:
// WaitCh returned a result
if result != nil {
tr.handleTaskExitResult(result)
}
case <-tr.ctx.Done():
// TaskRunner was told to exit immediately
return
@ -410,6 +413,7 @@ MAIN:
event := structs.NewTaskEvent(structs.TaskTerminated).
SetExitCode(result.ExitCode).
SetSignal(result.Signal).
SetOOMKilled(result.OOMKilled).
SetExitMessage(result.Err)
tr.UpdateState(structs.TaskStateDead, event)
}
@ -422,6 +426,20 @@ MAIN:
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
// when Run has returned. Should only be run in a goroutine from Run.
func (tr *TaskRunner) handleUpdates() {

View file

@ -6196,6 +6196,11 @@ func (e *TaskEvent) SetDriverMessage(m string) *TaskEvent {
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.
type TaskArtifact struct {
// GetterSource is the source to download an artifact using go-getter