Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override last error #1584

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/process/operation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Reason: kebErr.Reason(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.Message = err.Error()
}

op, t, _ := om.update(operation, domain.Failed, description, log)
Expand Down
10 changes: 5 additions & 5 deletions internal/process/operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
})
}

Expand Down
1 change: 0 additions & 1 deletion internal/process/staged_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading