Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 60d345d

Browse files
authored
Fixing pod plugin event reporting timestamps (#307)
* corrected timestamps for pod plugin Signed-off-by: Dan Rammer <daniel@union.ai> * but actually this time Signed-off-by: Dan Rammer <daniel@union.ai> * added reported at support Signed-off-by: Daniel Rammer <daniel@union.ai> * fixed merge Signed-off-by: Daniel Rammer <daniel@union.ai> * updated flyteidl Signed-off-by: Daniel Rammer <daniel@union.ai> * updated flyteidl deps Signed-off-by: Daniel Rammer <daniel@union.ai> --------- Signed-off-by: Dan Rammer <daniel@union.ai> Signed-off-by: Daniel Rammer <daniel@union.ai>
1 parent 0a681cd commit 60d345d

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/aws/aws-sdk-go-v2/service/athena v1.0.0
1313
github.com/bstadlbauer/dask-k8s-operator-go-client v0.1.0
1414
github.com/coocood/freecache v1.1.1
15-
github.com/flyteorg/flyteidl v1.3.12
15+
github.com/flyteorg/flyteidl v1.3.14
1616
github.com/flyteorg/flytestdlib v1.0.15
1717
github.com/go-test/deep v1.0.7
1818
github.com/golang/protobuf v1.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQL
232232
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
233233
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
234234
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
235-
github.com/flyteorg/flyteidl v1.3.12 h1:RTcxCrqKU235cWuy+j3gkmqPJOaaYEcJaT6fsRjoS8Q=
236-
github.com/flyteorg/flyteidl v1.3.12/go.mod h1:Pkt2skI1LiHs/2ZoekBnyPhuGOFMiuul6HHcKGZBsbM=
235+
github.com/flyteorg/flyteidl v1.3.14 h1:o5M0g/r6pXTPu5PEurbYxbQmuOu3hqqsaI2M6uvK0N8=
236+
github.com/flyteorg/flyteidl v1.3.14/go.mod h1:Pkt2skI1LiHs/2ZoekBnyPhuGOFMiuul6HHcKGZBsbM=
237237
github.com/flyteorg/flytestdlib v1.0.15 h1:kv9jDQmytbE84caY+pkZN8trJU2ouSAmESzpTEhfTt0=
238238
github.com/flyteorg/flytestdlib v1.0.15/go.mod h1:ghw/cjY0sEWIIbyCtcJnL/Gt7ZS7gf9SUi0CCPhbz3s=
239239
github.com/flyteorg/stow v0.3.6 h1:jt50ciM14qhKBaIrB+ppXXY+SXB59FNREFgTJqCyqIk=

go/tasks/pluginmachinery/core/phase.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ type ExternalResource struct {
8686
type TaskInfo struct {
8787
// log information for the task execution
8888
Logs []*core.TaskLog
89-
// Set this value to the intended time when the status occurred at. If not provided, will be defaulted to the current
90-
// time at the time of publishing the event.
89+
// This value represents the time the status occurred at. If not provided, it will be defaulted to the time Flyte
90+
// checked the task status.
9191
OccurredAt *time.Time
92+
// This value represents the time the status was reported at. If not provided, will be defaulted to the current time
93+
// when Flyte published the event.
94+
ReportedAt *time.Time
9295
// Custom Event information that the plugin would like to expose to the front-end
9396
CustomInfo *structpb.Struct
9497
// A collection of information about external resources launched by this task

go/tasks/pluginmachinery/flytek8s/pod_helper.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,13 @@ func GetLastTransitionOccurredAt(pod *v1.Pod) metav1.Time {
664664
var lastTransitionTime metav1.Time
665665
containerStatuses := append(pod.Status.ContainerStatuses, pod.Status.InitContainerStatuses...)
666666
for _, containerStatus := range containerStatuses {
667-
if r := containerStatus.LastTerminationState.Running; r != nil {
667+
if r := containerStatus.State.Running; r != nil {
668668
if r.StartedAt.Unix() > lastTransitionTime.Unix() {
669669
lastTransitionTime = r.StartedAt
670670
}
671-
} else if r := containerStatus.LastTerminationState.Terminated; r != nil {
671+
} else if r := containerStatus.State.Terminated; r != nil {
672672
if r.FinishedAt.Unix() > lastTransitionTime.Unix() {
673-
lastTransitionTime = r.StartedAt
673+
lastTransitionTime = r.FinishedAt
674674
}
675675
}
676676
}
@@ -681,3 +681,16 @@ func GetLastTransitionOccurredAt(pod *v1.Pod) metav1.Time {
681681

682682
return lastTransitionTime
683683
}
684+
685+
func GetReportedAt(pod *v1.Pod) metav1.Time {
686+
var reportedAt metav1.Time
687+
for _, condition := range pod.Status.Conditions {
688+
if condition.Reason == "PodCompleted" && condition.Type == v1.PodReady && condition.Status == v1.ConditionFalse {
689+
if condition.LastTransitionTime.Unix() > reportedAt.Unix() {
690+
reportedAt = condition.LastTransitionTime
691+
}
692+
}
693+
}
694+
695+
return reportedAt
696+
}

go/tasks/plugins/k8s/pod/plugin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@ func (plugin) GetTaskPhaseWithLogs(ctx context.Context, pluginContext k8s.Plugin
148148
pod := r.(*v1.Pod)
149149

150150
transitionOccurredAt := flytek8s.GetLastTransitionOccurredAt(pod).Time
151+
reportedAt := flytek8s.GetReportedAt(pod).Time
152+
if reportedAt.IsZero() {
153+
reportedAt = transitionOccurredAt
154+
}
155+
151156
info := pluginsCore.TaskInfo{
152157
OccurredAt: &transitionOccurredAt,
158+
ReportedAt: &reportedAt,
153159
}
154160

155161
if pod.Status.Phase != v1.PodPending && pod.Status.Phase != v1.PodUnknown {

0 commit comments

Comments
 (0)