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 warn on unfinished handlers if workflow failed #1581

Merged
merged 1 commit into from
Aug 6, 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
8 changes: 6 additions & 2 deletions internal/internal_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func executeDispatcher(ctx Context, dispatcher dispatcher, timeout time.Duration
if len(us) > 0 {
env.GetLogger().Warn("Workflow has unhandled signals", "SignalNames", us)
}
//
// Warn if there are any update handlers still running
type warnUpdate struct {
Name string `json:"name"`
ID string `json:"id"`
Expand All @@ -696,7 +696,11 @@ func executeDispatcher(ctx Context, dispatcher dispatcher, timeout time.Duration
})
}
}
if len(updatesToWarn) > 0 {

// Verify that the workflow did not fail. If it did we will not warn about unhandled updates.
var canceledErr *CanceledError
var contErr *ContinueAsNewError
if len(updatesToWarn) > 0 && (rp.error == nil || errors.As(rp.error, &canceledErr) || errors.As(rp.error, &contErr)) {
env.GetLogger().Warn(unhandledUpdateWarningMessage, "Updates", updatesToWarn)
Comment on lines +700 to 704
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know we never discussed this but perhaps it makes sense to log them at debug level for workflow failing case?

Not a big deal either way.

Copy link
Contributor Author

@Quinn-With-Two-Ns Quinn-With-Two-Ns Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think I would punt on this for now. I suspect we will be doing more work on warning on dangling "things" (like activities) in workflow and can resist then

}

Expand Down
34 changes: 19 additions & 15 deletions internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,44 +649,48 @@ func TestWorkflowAllHandlersFinished(t *testing.T) {

}
// assertExpectedLogs asserts that the logs in the buffer are as expected
assertExpectedLogs := func(t *testing.T, buf *bytes.Buffer) {
assertExpectedLogs := func(t *testing.T, buf *bytes.Buffer, shouldWarn bool) {
logs := parseLogs(buf)
require.Len(t, logs, 1)
require.Equal(t, unhandledUpdateWarningMessage, logs[0]["msg"])
warnedUpdates := parseWarnedUpdates(logs[0]["Updates"])
require.Len(t, warnedUpdates, 2)
// Order of updates is not guaranteed
require.Equal(t, "update", warnedUpdates[0]["name"])
require.True(t, warnedUpdates[0]["id"] == "id_1" || warnedUpdates[0]["id"] == "id_2")
require.Equal(t, "update", warnedUpdates[1]["name"])
require.True(t, warnedUpdates[1]["id"] != warnedUpdates[0]["id"])
require.True(t, warnedUpdates[1]["id"] == "id_1" || warnedUpdates[1]["id"] == "id_2")
if shouldWarn {
require.Len(t, logs, 1)
require.Equal(t, unhandledUpdateWarningMessage, logs[0]["msg"])
warnedUpdates := parseWarnedUpdates(logs[0]["Updates"])
require.Len(t, warnedUpdates, 2)
// Order of updates is not guaranteed
require.Equal(t, "update", warnedUpdates[0]["name"])
require.True(t, warnedUpdates[0]["id"] == "id_1" || warnedUpdates[0]["id"] == "id_2")
require.Equal(t, "update", warnedUpdates[1]["name"])
require.True(t, warnedUpdates[1]["id"] != warnedUpdates[0]["id"])
require.True(t, warnedUpdates[1]["id"] == "id_1" || warnedUpdates[1]["id"] == "id_2")
} else {
require.Len(t, logs, 0)
}
}

t.Run("complete", func(t *testing.T) {
var buf bytes.Buffer
result, err := runWf("complete", &buf)
require.NoError(t, err)
require.Equal(t, 2, result)
assertExpectedLogs(t, &buf)
assertExpectedLogs(t, &buf, true)
})
t.Run("cancel", func(t *testing.T) {
var buf bytes.Buffer
_, err := runWf("cancel", &buf)
require.Error(t, err)
assertExpectedLogs(t, &buf)
assertExpectedLogs(t, &buf, true)
})
t.Run("failure", func(t *testing.T) {
var buf bytes.Buffer
_, err := runWf("failure", &buf)
require.Error(t, err)
assertExpectedLogs(t, &buf)
assertExpectedLogs(t, &buf, false)
})
t.Run("continue-as-new", func(t *testing.T) {
var buf bytes.Buffer
_, err := runWf("continue-as-new", &buf)
require.Error(t, err)
assertExpectedLogs(t, &buf)
assertExpectedLogs(t, &buf, true)
})
}

Expand Down
Loading