Skip to content

Commit

Permalink
DEVPROD-2417 Add final block to task details (#7674)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana committed Apr 11, 2024
1 parent 350d4d7 commit 8b18dd1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ func (a *Agent) finishTask(ctx context.Context, tc *taskContext, status string,
tc.logger.Task().Info("Post task completed - FAILURE. Overall task status changed to FAILED.")
setEndTaskFailureDetails(tc, detail, evergreen.TaskFailed, "", "")
}
detail.PostErrored = tc.getPostErrored()
a.runEndTaskSync(ctx, tc, detail)
case evergreen.TaskFailed:
a.handleTimeoutAndOOM(ctx, tc, status)
Expand All @@ -982,6 +983,7 @@ func (a *Agent) finishTask(ctx context.Context, tc *taskContext, status string,
// already logged the error, and the post commands cannot cause the
// task to fail since the task already failed.
_ = a.runPostOrTeardownTaskCommands(ctx, tc)
detail.PostErrored = tc.getPostErrored()
a.runEndTaskSync(ctx, tc, detail)
case evergreen.TaskSystemFailed:
// This is a special status indicating that the agent failed for reasons
Expand Down
14 changes: 14 additions & 0 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@ post:
})
}

func (s *AgentSuite) TestPostSucceedsButErrorIsStored() {
projYml := `
post:
- command: shell.exec
params:
script: exit 1
`
s.setupRunTask(projYml)
s.NoError(s.a.runPostOrTeardownTaskCommands(s.ctx, s.tc))
s.NoError(s.tc.logger.Close())
s.True(s.tc.getPostErrored())
}

func (s *AgentSuite) TestPostTimeoutDoesNotFailTask() {
projYml := `
buildvariants:
Expand Down Expand Up @@ -700,6 +713,7 @@ post:

s.NoError(s.tc.logger.Close())
checkMockLogs(s.T(), s.mockCommunicator, s.tc.taskConfig.Task.Id, nil, []string{panicLog})
s.True(s.tc.getPostErrored())
}

func (s *AgentSuite) TestPostTimeoutFailsTask() {
Expand Down
3 changes: 3 additions & 0 deletions agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ func (a *Agent) runCommand(ctx context.Context, tc *taskContext, logger client.L
case err := <-cmdChan:
if err != nil {
tc.logger.Task().Errorf("Command %s failed: %s.", cmd.FullDisplayName(), err)
if options.block == command.PostBlock {
tc.setPostErrored(true)
}
if options.canFailTask ||
(cmd.Name() == "git.get_project" && tc.taskConfig.Task.Requester == evergreen.MergeTestRequester) {
// any git.get_project in the commit queue should fail
Expand Down
13 changes: 13 additions & 0 deletions agent/task_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

type taskContext struct {
currentCommand command.Command
postErrored bool
logger client.LoggerProducer
task client.TaskData
ranSetupGroup bool
Expand All @@ -38,6 +39,18 @@ type taskContext struct {
sync.RWMutex
}

func (tc *taskContext) getPostErrored() bool {
tc.RLock()
defer tc.RUnlock()
return tc.postErrored
}

func (tc *taskContext) setPostErrored(errored bool) {
tc.Lock()
defer tc.Unlock()
tc.postErrored = errored
}

func (tc *taskContext) setCurrentCommand(command command.Command) {
tc.Lock()
defer tc.Unlock()
Expand Down
1 change: 1 addition & 0 deletions apimodels/agent_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type TaskTestResultsInfo struct {
type TaskEndDetail struct {
Status string `bson:"status,omitempty" json:"status,omitempty"`
Type string `bson:"type,omitempty" json:"type,omitempty"`
PostErrored bool `bson:"post_errored,omitempty" json:"post_errored,omitempty"`
Description string `bson:"desc,omitempty" json:"desc,omitempty"`
TimedOut bool `bson:"timed_out,omitempty" json:"timed_out,omitempty"`
TimeoutType string `bson:"timeout_type,omitempty" json:"timeout_type,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (

// Agent version to control agent rollover. The format is the calendar date
// (YYYY-MM-DD).
AgentVersion = "2024-04-10"
AgentVersion = "2024-04-11"
)

// ConfigSection defines a sub-document in the evergreen config
Expand Down
12 changes: 8 additions & 4 deletions rest/model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ type LogLinks struct {
}

type ApiTaskEndDetail struct {
// The status of the completed task
// The status of the completed task.
Status *string `json:"status"`
// The method by which the task failed
// The method by which the task failed.
Type *string `json:"type"`
// Description of the final status of this task
// Description of the final status of this task.
Description *string `json:"desc"`
// Whether this task ended in a timeout
// PostErrored is true when the post command errored.
PostErrored bool `json:"post_errored"`
// Whether this task ended in a timeout.
TimedOut bool `json:"timed_out"`
TimeoutType *string `json:"timeout_type"`
OOMTracker APIOomTrackerInfo `json:"oom_tracker_info"`
Expand All @@ -181,6 +183,7 @@ func (at *ApiTaskEndDetail) BuildFromService(t apimodels.TaskEndDetail) error {
at.Status = utility.ToStringPtr(t.Status)
at.Type = utility.ToStringPtr(t.Type)
at.Description = utility.ToStringPtr(t.Description)
at.PostErrored = t.PostErrored
at.TimedOut = t.TimedOut
at.TimeoutType = utility.ToStringPtr(t.TimeoutType)

Expand All @@ -198,6 +201,7 @@ func (ad *ApiTaskEndDetail) ToService() apimodels.TaskEndDetail {
Status: utility.FromStringPtr(ad.Status),
Type: utility.FromStringPtr(ad.Type),
Description: utility.FromStringPtr(ad.Description),
PostErrored: ad.PostErrored,
TimedOut: ad.TimedOut,
TimeoutType: utility.FromStringPtr(ad.TimeoutType),
OOMTracker: ad.OOMTracker.ToService(),
Expand Down

0 comments on commit 8b18dd1

Please sign in to comment.