This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Pods are way more scalable - Error detection is way better - [x] Unit tests - [ ] End to end test
- Loading branch information
1 parent
d89bc2e
commit 01a95bf
Showing
40 changed files
with
2,136 additions
and
1,319 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package events | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/golang/protobuf/ptypes/struct" | ||
"github.com/lyft/flyteplugins/go/tasks/v1/errors" | ||
"github.com/lyft/flyteplugins/go/tasks/v1/types" | ||
|
||
"github.com/golang/protobuf/ptypes" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/event" | ||
) | ||
|
||
// Additional info that should be sent to the front end. The Information is sent to the front-end if it meets certain | ||
// criterion, for example currently, it is sent only if an event was not already sent for | ||
type TaskEventInfo struct { | ||
// log information for the task execution | ||
Logs []*core.TaskLog | ||
// Set this value to the intended time when the status occurred at. If not provided, will be defaulted to the current | ||
// time at the time of publishing the event. | ||
OccurredAt *time.Time | ||
// Custom Event information that the plugin would like to expose to the front-end | ||
CustomInfo *structpb.Struct | ||
} | ||
|
||
// Convert all TaskStatus to an ExecutionPhase that is common to Flyte and Admin understands | ||
// NOTE: if we add a TaskStatus entry, we should add it here too | ||
func convertTaskPhaseToExecutionStatus(status types.TaskPhase) core.TaskExecutionPhase { | ||
switch status { | ||
case types.TaskPhaseRunning: | ||
return core.TaskExecutionPhase_TASK_PHASE_RUNNING | ||
case types.TaskPhaseSucceeded: | ||
return core.TaskExecutionPhase_TASK_PHASE_SUCCEEDED | ||
case types.TaskPhaseRetryableFailure, types.TaskPhasePermanentFailure: | ||
return core.TaskExecutionPhase_TASK_PHASE_FAILED | ||
case types.TaskPhaseQueued: | ||
return core.TaskExecutionPhase_TASK_PHASE_QUEUED | ||
default: | ||
return core.TaskExecutionPhase_TASK_PHASE_UNDEFINED | ||
} | ||
} | ||
|
||
func CreateEvent(taskCtx types.TaskContext, taskStatus types.TaskStatus, info *TaskEventInfo) *event.TaskExecutionEvent { | ||
|
||
newTaskExecutionPhase := convertTaskPhaseToExecutionStatus(taskStatus.Phase) | ||
taskExecutionID := taskCtx.GetTaskExecutionID().GetID() | ||
|
||
occurredAt := ptypes.TimestampNow() | ||
logs := make([]*core.TaskLog, 0) | ||
var customInfo *structpb.Struct | ||
|
||
if info != nil { | ||
customInfo = info.CustomInfo | ||
if info.OccurredAt != nil { | ||
t, err := ptypes.TimestampProto(*info.OccurredAt) | ||
if err != nil { | ||
occurredAt = t | ||
} | ||
} | ||
for _, l := range info.Logs { | ||
logs = append(logs, l) | ||
} | ||
} | ||
|
||
taskEvent := &event.TaskExecutionEvent{ | ||
TaskId: taskExecutionID.TaskId, | ||
ParentNodeExecutionId: taskExecutionID.NodeExecutionId, | ||
Phase: newTaskExecutionPhase, | ||
RetryAttempt: taskCtx.GetTaskExecutionID().GetID().RetryAttempt, | ||
InputUri: taskCtx.GetInputsFile().String(), | ||
OccurredAt: occurredAt, | ||
Logs: logs, | ||
CustomInfo: customInfo, | ||
} | ||
|
||
if newTaskExecutionPhase == core.TaskExecutionPhase_TASK_PHASE_FAILED { | ||
errorCode := "UnknownTaskError" | ||
message := "unknown reason" | ||
if taskStatus.Err != nil { | ||
ec, ok := errors.GetErrorCode(taskStatus.Err) | ||
if ok { | ||
errorCode = ec | ||
} | ||
message = taskStatus.Err.Error() | ||
} | ||
taskEvent.OutputResult = &event.TaskExecutionEvent_Error{ | ||
Error: &core.ExecutionError{ | ||
Code: errorCode, | ||
Message: message, | ||
ErrorUri: taskCtx.GetErrorFile().String(), | ||
}, | ||
} | ||
} else if newTaskExecutionPhase == core.TaskExecutionPhase_TASK_PHASE_SUCCEEDED { | ||
taskEvent.OutputResult = &event.TaskExecutionEvent_OutputUri{ | ||
OutputUri: taskCtx.GetOutputsFile().String(), | ||
} | ||
} | ||
return taskEvent | ||
} |
Oops, something went wrong.