From 419b7aa2ba6c605ab714b56e9e7ac76db260d0fe Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 08:46:04 +0100 Subject: [PATCH 1/5] Do not override last error --- internal/process/operation_manager.go | 12 ++++++------ internal/process/staged_manager.go | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/process/operation_manager.go b/internal/process/operation_manager.go index c023f858e4..9c3caf7b12 100644 --- a/internal/process/operation_manager.go +++ b/internal/process/operation_manager.go @@ -30,13 +30,13 @@ func (om *OperationManager) OperationSucceeded(operation internal.Operation, des // OperationFailed marks the operation as failed and returns status of the operation's update func (om *OperationManager) OperationFailed(operation internal.Operation, description string, err error, log *slog.Logger) (internal.Operation, time.Duration, error) { + operation.LastError = kebErr.LastError{ + Message: description, + Component: om.component, + Step: om.step, + } if err != nil { - operation.LastError = kebErr.LastError{ - Message: err.Error(), - Reason: kebErr.Reason(description), - Component: om.component, - Step: om.step, - } + operation.LastError.Reason = kebErr.Reason(err.Error()) } op, t, _ := om.update(operation, domain.Failed, description, log) diff --git a/internal/process/staged_manager.go b/internal/process/staged_manager.go index eb5e5c5654..41a7bf9740 100644 --- a/internal/process/staged_manager.go +++ b/internal/process/staged_manager.go @@ -232,7 +232,6 @@ func (m *StagedManager) runStep(step Step, operation internal.Operation, logger stepLogger := logger.With("step", step.Name(), "operation", processedOperation.ID) processedOperation, backoff, err = step.Run(processedOperation, stepLogger) if err != nil { - processedOperation.LastError = kebError.ReasonForError(err, step.Name()) logOperation := stepLogger.With("error_component", processedOperation.LastError.GetComponent(), "error_reason", processedOperation.LastError.GetReason()) logOperation.Warn(fmt.Sprintf("Last error from step: %s", processedOperation.LastError.Error())) // only save to storage, skip for alerting if error From d2da00ed1327d408ce14ae233e1cbce91e547b90 Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 08:57:10 +0100 Subject: [PATCH 2/5] wip --- internal/process/provisioning/create_runtime_resource_step.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index c0c5c4e57e..1ac1fd6273 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -70,6 +70,8 @@ func (s *CreateRuntimeResourceStep) Name() string { } func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log *slog.Logger) (internal.Operation, time.Duration, error) { + return s.operationManager.OperationFailed(operation, fmt.Sprintf("while updating Runtime resource object"), nil, log) + if time.Since(operation.UpdatedAt) > CreateRuntimeTimeout { log.Info(fmt.Sprintf("operation has reached the time limit: updated operation time: %s", operation.UpdatedAt)) return s.operationManager.OperationFailed(operation, fmt.Sprintf("operation has reached the time limit: %s", CreateRuntimeTimeout), nil, log) From 0349d0d010432d7edb5fa6d0f2df71d923c3221c Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 09:17:51 +0100 Subject: [PATCH 3/5] wip --- internal/process/operation_manager.go | 4 ++-- internal/process/operation_manager_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/process/operation_manager.go b/internal/process/operation_manager.go index 9c3caf7b12..5048bd107a 100644 --- a/internal/process/operation_manager.go +++ b/internal/process/operation_manager.go @@ -31,12 +31,12 @@ func (om *OperationManager) OperationSucceeded(operation internal.Operation, des // OperationFailed marks the operation as failed and returns status of the operation's update func (om *OperationManager) OperationFailed(operation internal.Operation, description string, err error, log *slog.Logger) (internal.Operation, time.Duration, error) { operation.LastError = kebErr.LastError{ - Message: description, + Reason: kebErr.Reason(description), Component: om.component, Step: om.step, } if err != nil { - operation.LastError.Reason = kebErr.Reason(err.Error()) + operation.LastError.Message = err.Error() } op, t, _ := om.update(operation, domain.Failed, description, log) diff --git a/internal/process/operation_manager_test.go b/internal/process/operation_manager_test.go index 0d3405697f..89c19988d1 100644 --- a/internal/process/operation_manager_test.go +++ b/internal/process/operation_manager_test.go @@ -118,10 +118,10 @@ func Test_OperationManager_LastError(t *testing.T) { err := operations.InsertOperation(op) require.NoError(t, err) op, _, err = opManager.OperationFailed(op, "friendly message", nil, fixLogger()) - assert.EqualValues(t, "", op.LastError.GetComponent()) + assert.EqualValues(t, "provisioner", op.LastError.GetComponent()) assert.EqualValues(t, "", op.LastError.Error()) - assert.EqualValues(t, "", op.LastError.GetReason()) - assert.EqualValues(t, "", op.LastError.GetStep()) + assert.EqualValues(t, "friendly message", op.LastError.GetReason()) + assert.EqualValues(t, "some_step", op.LastError.GetStep()) }) t.Run("when no description passed", func(t *testing.T) { @@ -146,10 +146,10 @@ func Test_OperationManager_LastError(t *testing.T) { err := operations.InsertOperation(op) require.NoError(t, err) op, _, err = opManager.OperationFailed(op, "", nil, fixLogger()) - assert.EqualValues(t, "", op.LastError.GetComponent()) + assert.EqualValues(t, "reconciler", op.LastError.GetComponent()) assert.EqualValues(t, "", op.LastError.Error()) assert.EqualValues(t, "", op.LastError.GetReason()) - assert.EqualValues(t, "", op.LastError.GetStep()) + assert.EqualValues(t, "some_step", op.LastError.GetStep()) }) } From 1ab64cf7b4ff9a819ef141690be036b1dc250455 Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 09:57:50 +0100 Subject: [PATCH 4/5] wip --- internal/process/provisioning/apply_kyma_step.go | 1 + internal/process/provisioning/create_runtime_resource_step.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/process/provisioning/apply_kyma_step.go b/internal/process/provisioning/apply_kyma_step.go index 2a992388d2..40a0e6005b 100644 --- a/internal/process/provisioning/apply_kyma_step.go +++ b/internal/process/provisioning/apply_kyma_step.go @@ -42,6 +42,7 @@ func (a *ApplyKymaStep) Name() string { func (a *ApplyKymaStep) Run(operation internal.Operation, logger *slog.Logger) (internal.Operation, time.Duration, error) { template, err := steps.DecodeKymaTemplate(operation.KymaTemplate) + err = fmt.Errorf("technical error") if err != nil { return a.operationManager.OperationFailed(operation, "unable to create a kyma template", err, logger) } diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index 1ac1fd6273..c0c5c4e57e 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -70,8 +70,6 @@ func (s *CreateRuntimeResourceStep) Name() string { } func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log *slog.Logger) (internal.Operation, time.Duration, error) { - return s.operationManager.OperationFailed(operation, fmt.Sprintf("while updating Runtime resource object"), nil, log) - if time.Since(operation.UpdatedAt) > CreateRuntimeTimeout { log.Info(fmt.Sprintf("operation has reached the time limit: updated operation time: %s", operation.UpdatedAt)) return s.operationManager.OperationFailed(operation, fmt.Sprintf("operation has reached the time limit: %s", CreateRuntimeTimeout), nil, log) From f0f6d4b6feefe68cb4db2e99a8ce4083dc339b01 Mon Sep 17 00:00:00 2001 From: KsaweryZietara Date: Wed, 18 Dec 2024 10:16:32 +0100 Subject: [PATCH 5/5] wip --- internal/process/provisioning/apply_kyma_step.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/process/provisioning/apply_kyma_step.go b/internal/process/provisioning/apply_kyma_step.go index 40a0e6005b..2a992388d2 100644 --- a/internal/process/provisioning/apply_kyma_step.go +++ b/internal/process/provisioning/apply_kyma_step.go @@ -42,7 +42,6 @@ func (a *ApplyKymaStep) Name() string { func (a *ApplyKymaStep) Run(operation internal.Operation, logger *slog.Logger) (internal.Operation, time.Duration, error) { template, err := steps.DecodeKymaTemplate(operation.KymaTemplate) - err = fmt.Errorf("technical error") if err != nil { return a.operationManager.OperationFailed(operation, "unable to create a kyma template", err, logger) }