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

selector: percent selection should select at least one #3036

Merged
merged 3 commits into from
Apr 8, 2022

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

This bug was originally found in NetworkChaos:

If the user is using the maxPercentMode for both . and .Target, and blessed by the goddess of fortune, one of them doesn't select any pod. The other one will be injected for all traffic, which is not expected. After considering some time, I thought it would be reasonable to generate at least one target in the selector (if it's at least able to.)

In this PR, I modified two things:

  1. Replace the Floor in selector into Ceil
  2. Check the emptiness for every selector, but not only for the total records.

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 17, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • cwen0
  • iguoyr

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@YangKeao
Copy link
Member Author

/run-e2e-tests

@codecov
Copy link

codecov bot commented Mar 17, 2022

Codecov Report

Merging #3036 (7731343) into master (853ded5) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3036      +/-   ##
==========================================
- Coverage   37.98%   37.94%   -0.05%     
==========================================
  Files         106      106              
  Lines        9359     9359              
==========================================
- Hits         3555     3551       -4     
- Misses       5492     5495       +3     
- Partials      312      313       +1     
Impacted Files Coverage Δ
pkg/selector/generic/mode.go 25.64% <0.00%> (ø)
.../workflow/controllers/workflow_entry_reconciler.go 46.03% <0.00%> (-2.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7fde3d...7731343. Read the comment docs.

@YangKeao
Copy link
Member Author

/run-e2e-tests

1 similar comment
@YangKeao
Copy link
Member Author

/run-e2e-tests

Comment on lines 88 to +89
percentage := getRandomNumber(maxPercentage + 1) // + 1 because Intn works with half open interval [0,n) and we want [0,n]
num := int(math.Floor(float64(count) * float64(percentage) / 100))
num := int(math.Ceil(float64(count) * float64(percentage) / 100))
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove the maxPercentage+1 and update the comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. Consider the special situation where the maxPercentage is 100, then the percentage will be 0-100 (as the getRandomNumber always returns the number in [0,101)), which is actually expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

@iguoyr PTAL

Copy link
Member

@iguoyr iguoyr left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cwen0 cwen0 left a comment

Choose a reason for hiding this comment

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

LGTM @YangKeao You need to update docs for this.

@YangKeao
Copy link
Member Author

YangKeao commented Apr 8, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 524ab2a

@ti-chi-bot ti-chi-bot merged commit f9a443d into chaos-mesh:master Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants