-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add percentage routing and migration status to user table
This adds a few entries into the .ini: ``` [tokenserver] spanner_entry = # Name of the spanner node name e.g. https://spanner.example.com spanner_node_id = # default spanner node id migrate_new_user_percentage = # percentage of users to send to spanner ``` *note* the "percentage" is a terrible hack that just sends the first _n_ of every 100 users to spanner. Closes #159
- Loading branch information
Showing
12 changed files
with
144 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tokenserver/assignment/sqlnode/migrations/versions/8440ac37978a_migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""migration | ||
Revision ID: 8440ac37978a | ||
Revises: 75e8ca84b0bc | ||
Create Date: 2019-12-16 15:46:07.048437 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '8440ac37978a' | ||
down_revision = '75e8ca84b0bc' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
op.add_column("users", sa.Column("migration_state", sa.String)) | ||
pass | ||
|
||
|
||
def downgrade(): | ||
op.drop_column("users", "migration_state") | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ def setUp(self): | |
self.backend.add_service('sync-1.5', '{node}/1.5/{uid}') | ||
self.backend.add_service('queuey-1.0', '{node}/{service}/{uid}') | ||
self.backend.add_node('sync-1.0', 'https://phx12', 100) | ||
self.backend._migrate_new_user_percentage = 0 | ||
|
||
def test_node_allocation(self): | ||
user = self.backend.get_user("sync-1.0", "[email protected]") | ||
|
@@ -426,6 +427,22 @@ def test_first_seen_at(self): | |
self.assertEqual(user3["uid"], user2["uid"]) | ||
self.assertNotEqual(user3["first_seen_at"], user2["first_seen_at"]) | ||
|
||
def test_spanner_allocation(self): | ||
SERVICE = "sync-1.5" | ||
sync_15_node = 'https://etc1' | ||
# TODO: this should go in with whatever inits the backend: | ||
self.backend._spanner_entry = (self.backend._spanner_entry or | ||
"https://spanner.example.com") | ||
self.backend.add_service('spanner', 'https://spanner/1.5/{uid}') | ||
self.backend.add_node('sync-1.5', sync_15_node, 100) | ||
self.backend.add_node('spanner', 'https://spanner', capacity=1000) | ||
self.backend._migrate_new_user_percentage = 1 | ||
|
||
user0 = self.backend.allocate_user(SERVICE, "[email protected]") | ||
user1 = self.backend.allocate_user(SERVICE, "[email protected]") | ||
self.assertEqual(user0['node'], self.backend._spanner_entry) | ||
self.assertEqual(user1['node'], sync_15_node) | ||
|
||
|
||
class TestSQLDB(NodeAssignmentTests, unittest.TestCase): | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,15 @@ def test_assignation(self): | |
user = self.backend.get_user(DEFAULT_EMAIL, DEFAULT_SERVICE) | ||
self.assertEquals(user['uid'], 1) | ||
self.assertEquals(user['node'], DEFAULT_NODE) | ||
|
||
def test_AAA_assignment_spanner(self): | ||
settings = self.config.get_settings() | ||
settings['tokenserver.migrate_new_user_percentage'] = 1 | ||
self.config.add_settings(settings) | ||
|
||
user0 = self.backend.allocate_user( | ||
DEFAULT_SERVICE, '[email protected]') | ||
user1 = self.backend.allocate_user( | ||
DEFAULT_SERVICE, '[email protected]') | ||
self.assertEquals(user0['node'], settings['tokenserver.spanner_entry']) | ||
self.assertEquals(user1['node'], settings['tokenserver.service_entry']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters