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

feat(api): add consistent hash table size api #3348

Merged
merged 6 commits into from May 14, 2024

Conversation

aoledk
Copy link
Contributor

@aoledk aoledk commented May 8, 2024

What this PR does / why we need it:

Add knob in BackendTrafficPolicy to configure consistent hash table size.

Which issue(s) this PR fixes:

Fixes #3272

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
@aoledk aoledk requested a review from a team as a code owner May 8, 2024 09:03

// The table size for consistent hashing, must be prime number limited to 5000011.
//
// +kubebuilder:validation:Minimum=1
Copy link
Contributor

Choose a reason for hiding this comment

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

should we make it 2? because 1 is actually not a prime number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, make the minimum to the smallest prime number 2 now.

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
@@ -58,7 +58,7 @@ type ConsistentHash struct {

// The table size for consistent hashing, must be prime number limited to 5000011.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add CEL to validate it must be prime number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like CEL in Kubernetes 1 doesn't support complex validation logic like IsPrime function. But we can validate whether table size is prime number when translating ClientTrafficPolicy to IR.

func IsPrime(n int) bool {
    if n <= 1 {
        return false
    }
    for i := 2; i*i <= n; i++ {
        if n%i == 0 {
            return false
        }
    }
    return true
}

Footnotes

  1. https://kubernetes.io/docs/reference/using-api/cel/#cel-options-language-features-and-libraries

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
Copy link
Contributor

@shawnh2 shawnh2 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding this! Leave some comments.

@@ -58,7 +58,7 @@ type ConsistentHash struct {

// The table size for consistent hashing, must be prime number limited to 5000011.
Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

api/v1alpha1/loadbalancer_types.go Show resolved Hide resolved
Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
@aoledk aoledk requested a review from zirain May 14, 2024 09:43
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks !

@arkodg arkodg merged commit 4cf85c3 into envoyproxy:main May 14, 2024
20 checks passed
@aoledk aoledk deleted the consistent-hash-table-size-api branch May 15, 2024 05:39
zhaohuabing pushed a commit to zhaohuabing/gateway that referenced this pull request May 15, 2024
* Add consistent hash table size api

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>

* Set consistent hash table size's minimum as the smallest prime number: 2

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>

* Comment tableSize api as notImplementedHide

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>

---------

Signed-off-by: Dingkang Li <dingkang1743@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support knob to configure consistent hash table size
4 participants