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

Handle either tolerated_failure_count or tolerated_failure_percentage #284

Merged
merged 1 commit into from
Oct 9, 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
15 changes: 10 additions & 5 deletions lib/floe/workflow/states/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,18 @@ def success?(context)
total = contexts.count

return true if num_failed.zero? || total.zero?
return true if tolerated_failure_percentage && tolerated_failure_percentage == 100
return false if tolerated_failure_count.nil? && tolerated_failure_percentage.nil?
Copy link
Member

@kbrock kbrock Oct 9, 2024

Choose a reason for hiding this comment

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

can this be a configuration error and not a runtime error?

UPDATE: I guess maybe it is alright to leave as is

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't a payload validation, this is saying if there are any failures in the sub workflows and no tolerated_failure_* has been provided then the state has failed


# Some have failed, check the tolerated_failure thresholds to see if
# we should fail the whole state.
return true if tolerated_failure_count && num_failed < tolerated_failure_count
return true if tolerated_failure_percentage && (100 * num_failed / total.to_f) < tolerated_failure_percentage

false
#
# If either ToleratedFailureCount or ToleratedFailurePercentage are breached
# then the whole state is considered failed.
count_tolerated = tolerated_failure_count.nil? || num_failed < tolerated_failure_count
pct_tolerated = tolerated_failure_percentage.nil? || tolerated_failure_percentage == 100 ||
((100 * num_failed / total.to_f) < tolerated_failure_percentage)

count_tolerated && pct_tolerated
end

private
Expand Down
38 changes: 38 additions & 0 deletions spec/workflow/states/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,44 @@
end
end
end

context "with both ToleratedFailureCount and ToleratedFailurePercentage" do
context "with ToleratedFailureCount being lower than the failed percentge" do
let(:tolerated_failure_percentage) { 50 }
let(:tolerated_failure_count) { 1 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with ToleratedFailurePercentage being lower than the failed count" do
let(:tolerated_failure_percentage) { 10 }
let(:tolerated_failure_count) { 3 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with neither being high enough for success" do
let(:tolerated_failure_percentage) { 10 }
let(:tolerated_failure_count) { 1 }

it "returns false" do
expect(state.success?(ctx)).to be_falsey
end
end

context "with both being high enough for success" do
let(:tolerated_failure_percentage) { 50 }
let(:tolerated_failure_count) { 3 }

it "returns true" do
expect(state.success?(ctx)).to be_truthy
end
end
end
end
end
end