From c0acaa9f76f46b6bccc9e4e00d3425617b43d4ee Mon Sep 17 00:00:00 2001 From: Daniel Rammer Date: Wed, 4 Dec 2024 12:59:18 -0600 Subject: [PATCH] only setting timestamps if SubNodeDeltaTimestamps has been initialized Signed-off-by: Daniel Rammer --- .../pkg/controller/nodes/array/handler.go | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/array/handler.go b/flytepropeller/pkg/controller/nodes/array/handler.go index 0918ab6035..4f98e66796 100644 --- a/flytepropeller/pkg/controller/nodes/array/handler.go +++ b/flytepropeller/pkg/controller/nodes/array/handler.go @@ -389,16 +389,19 @@ func (a *arrayNodeHandler) Handle(ctx context.Context, nCtx interfaces.NodeExecu arrayNodeState.SubNodeRetryAttempts.SetItem(index, uint64(subNodeStatus.GetAttempts())) arrayNodeState.SubNodeSystemFailures.SetItem(index, uint64(subNodeStatus.GetSystemFailures())) - startedAt := nCtx.NodeStatus().GetLastAttemptStartedAt() - subNodeStartedAt := subNodeStatus.GetLastAttemptStartedAt() - if subNodeStartedAt == nil { - // subNodeStartedAt == nil indicates either (1) node has not started or (2) node status has - // been reset (ex. retryable failure). in both cases we set the delta timestamp to 0 - arrayNodeState.SubNodeDeltaTimestamps.SetItem(index, 0) - } else if startedAt != nil && arrayNodeState.SubNodeDeltaTimestamps.GetItem(index) == 0 { - // otherwise if `SubNodeDeltaTimestamps` is unset, we compute the delta and set it - deltaDuration := uint64(subNodeStartedAt.Time.Sub(startedAt.Time).Seconds()) - arrayNodeState.SubNodeDeltaTimestamps.SetItem(index, deltaDuration) + indexUint := uint(index) // #nosec G115 + if arrayNodeState.SubNodeDeltaTimestamps.ItemsCount >= indexUint { + startedAt := nCtx.NodeStatus().GetLastAttemptStartedAt() + subNodeStartedAt := subNodeStatus.GetLastAttemptStartedAt() + if subNodeStartedAt == nil { + // subNodeStartedAt == nil indicates either (1) node has not started or (2) node status has + // been reset (ex. retryable failure). in both cases we set the delta timestamp to 0 + arrayNodeState.SubNodeDeltaTimestamps.SetItem(index, 0) + } else if startedAt != nil && arrayNodeState.SubNodeDeltaTimestamps.GetItem(index) == 0 { + // otherwise if `SubNodeDeltaTimestamps` is unset, we compute the delta and set it + deltaDuration := uint64(subNodeStartedAt.Time.Sub(startedAt.Time).Seconds()) + arrayNodeState.SubNodeDeltaTimestamps.SetItem(index, deltaDuration) + } } // increment task phase version if subNode phase or task phase changed