-
Notifications
You must be signed in to change notification settings - Fork 50
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: Tokenserver: Add node assignment logic #1158
Conversation
41b4b21
to
f8db1c9
Compare
481e153
to
4353165
Compare
4131eca
to
f9da58a
Compare
4353165
to
6a8fc24
Compare
@@ -321,12 +325,12 @@ impl FromRequest for KeyId { | |||
|
|||
let (keys_changed_at_string, encoded_client_state) = x_key_id | |||
.split_once("-") | |||
.ok_or_else(|| TokenserverError::invalid_key_id("Invalid X-KeyID header"))?; | |||
.ok_or_else(|| TokenserverError::invalid_credentials("Unauthorized"))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small changes here to fix failing integration tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible future feature, but we've got a few times where we return the same error, and I doubt that we're logging these. It might be worth returning something like an errno to identify which of these got triggered.
Since we're rolling out a new service and there may be unexpected data, getting a response like that could save us time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wary of changing the API between the old and new Tokenservers; I don't want to give clients something unexpected. Do you think logging an errno would be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, logging would be fine. We don't have to return the data to the caller.
@@ -242,6 +187,83 @@ impl TokenserverDb { | |||
Ok(result as u64 > 0) | |||
} | |||
|
|||
/// Gets the least-loaded node that has available slots. | |||
fn get_best_node_sync(&self, params: params::GetBestNode) -> DbResult<results::GetBestNode> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to this database method on the old Tokenserver
sync_db_method!(replace_users, replace_users_sync, ReplaceUsers); | ||
sync_db_method!(post_user, post_user_sync, PostUser); | ||
|
||
/// Creates a new user and assigns them to a node. | ||
fn allocate_user(&self, params: params::AllocateUser) -> DbFuture<'_, results::AllocateUser> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to this database method on the old Tokenserver
|
||
/// Gets the user with the given email and service ID, or if one doesn't exist, allocates a new | ||
/// user. | ||
fn get_or_create_user( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds (roughly) to this database method on the old Tokenserver
@@ -845,6 +1094,684 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[tokio::test] | |||
async fn test_node_allocation() -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these new unit tests are rewrites of these unit tests on the old Tokenserver
@@ -5,6 +5,8 @@ | |||
|
|||
from tokenserver.test_support import TestCase | |||
|
|||
MAX_GENERATION = 9223372036854775807 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh, interesting choice.
@@ -321,12 +325,12 @@ impl FromRequest for KeyId { | |||
|
|||
let (keys_changed_at_string, encoded_client_state) = x_key_id | |||
.split_once("-") | |||
.ok_or_else(|| TokenserverError::invalid_key_id("Invalid X-KeyID header"))?; | |||
.ok_or_else(|| TokenserverError::invalid_credentials("Unauthorized"))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible future feature, but we've got a few times where we return the same error, and I doubt that we're logging these. It might be worth returning something like an errno to identify which of these got triggered.
Since we're rolling out a new service and there may be unexpected data, getting a response like that could save us time.
Description
Adds the logic used to create users and assign them to the correct nodes.
Testing
I added integration and unit tests that provide comprehensive coverage, but the following cases are the important ones:
available
andcurrent_load
are adjusted accordinglyavailable
is zero butcurrent_load
is less thancapacity
Issue(s)
Closes #1051