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

reverseproxy: Allow 0 as weights for weighted_round_robin #6388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peanutduck
Copy link

Enable 0 weights to be allowed when using weighted_round_robin policy with cookie. Discussed in https://caddy.community/t/invalid-weight-value/24440

@CLAassistant
Copy link

CLAassistant commented Jun 12, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks -- I wonder, does the actual selection algorithm need adjusting though to accommodate a 0 weight? Have you tested to ensure this works? (I guess we should consider adding test cases.)

if weightInt < 1 {
return d.Errf("invalid weight value '%s': weight should be non-zero and positive", weight)
if weightInt < 0 {
return d.Errf("invalid weight value '%s': weight should be positive", weight)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return d.Errf("invalid weight value '%s': weight should be positive", weight)
return d.Errf("invalid weight value '%s': weight should be non-negative", weight)

0 isn't positive but is also allowed now 😉

Copy link
Author

Choose a reason for hiding this comment

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

Good question, I don't have the enough knowledge to write the test case for this. Any guide would be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

Have you at least tested various configs yourself to ensure they work? If so that's probably enough to start with.

But it looks like the existing tests are in selectionpolicies_test.go at func TestWeightedRoundRobinPolicy(t *testing.T) {. You could test a zero-weight in there as well.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your reply, will work on generating the test case.

Copy link
Member

Choose a reason for hiding this comment

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

@peanutduck this still needs tests. Are you interested in finishing this up?

Change positive to non-negative
@francislavoie francislavoie added the bug 🐞 Something isn't working label Jun 12, 2024
@francislavoie francislavoie added this to the v2.9.0 milestone Jun 12, 2024
@mholt mholt added the needs tests 💯 Requires automated tests label Jun 18, 2024
@mholt mholt modified the milestones: v2.9.0-beta.1, v2.9.0-beta.2 Oct 2, 2024
@francislavoie francislavoie changed the title reverse_proxy: Allow 0 as weights reverseproxy: Allow 0 as weights for weighted_round_robin Oct 20, 2024
@mholt mholt modified the milestones: v2.9.0-beta.3, v2.9.0-beta.4 Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working needs tests 💯 Requires automated tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants