-
Notifications
You must be signed in to change notification settings - Fork 178
feat(BA-6644): Add domain id, resource group id in session row #12452
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f301430
feat(BA-6644): add session scope id columns
seedspirit aa76655
test(BA-6644): update fixtures and tests for session scope id columns
seedspirit 0320b1a
test(BA-6644): add session scope ids to remaining test fixtures
seedspirit 88cdf47
changelog: add news fragment for PR #12452
seedspirit ca3eb14
refactor: split scaling group component fixtures
seedspirit 77f9c1e
fix: linearize alembic migration head
seedspirit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Add domain_id and resource_group_id columns to session rows and populate them at session creation |
This file contains hidden or 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 hidden or 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 hidden or 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
74 changes: 74 additions & 0 deletions
74
src/ai/backend/manager/models/alembic/versions/ada41cb881bb_add_session_scope_id_columns.py
This file contains hidden or 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,74 @@ | ||
| """add session scope id columns | ||
|
|
||
| Revision ID: ada41cb881bb | ||
| Revises: a379b72f1206 | ||
| Create Date: 2026-06-30 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| from ai.backend.manager.models.base import GUID | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "ada41cb881bb" | ||
| down_revision = "a379b72f1206" | ||
| # Part of: 26.7.0 | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column("sessions", sa.Column("domain_id", GUID(), nullable=True)) | ||
| op.add_column("sessions", sa.Column("resource_group_id", GUID(), nullable=True)) | ||
| op.create_index("ix_sessions_domain_id", "sessions", ["domain_id"]) | ||
| op.create_index("ix_sessions_resource_group_id", "sessions", ["resource_group_id"]) | ||
|
|
||
| op.execute( | ||
| sa.text(""" | ||
| UPDATE sessions | ||
| SET domain_id = domains.id | ||
| FROM domains | ||
| WHERE sessions.domain_name = domains.name | ||
| AND sessions.domain_id IS NULL | ||
| """) | ||
| ) | ||
| op.execute( | ||
| sa.text(""" | ||
| UPDATE sessions | ||
| SET resource_group_id = scaling_groups.id | ||
| FROM scaling_groups | ||
| WHERE sessions.scaling_group_name = scaling_groups.name | ||
| AND sessions.resource_group_id IS NULL | ||
| """) | ||
| ) | ||
| op.alter_column("sessions", "domain_id", nullable=False) | ||
| op.alter_column("sessions", "resource_group_id", nullable=False) | ||
| op.create_foreign_key( | ||
| op.f("fk_sessions_domain_id_domains"), | ||
| "sessions", | ||
| "domains", | ||
| ["domain_id"], | ||
| ["id"], | ||
| ) | ||
| op.create_foreign_key( | ||
| op.f("fk_sessions_resource_group_id_scaling_groups"), | ||
| "sessions", | ||
| "scaling_groups", | ||
| ["resource_group_id"], | ||
| ["id"], | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_constraint( | ||
| op.f("fk_sessions_resource_group_id_scaling_groups"), | ||
| "sessions", | ||
| type_="foreignkey", | ||
| ) | ||
| op.drop_constraint(op.f("fk_sessions_domain_id_domains"), "sessions", type_="foreignkey") | ||
| op.drop_index("ix_sessions_resource_group_id", table_name="sessions") | ||
| op.drop_index("ix_sessions_domain_id", table_name="sessions") | ||
| op.drop_column("sessions", "resource_group_id") | ||
| op.drop_column("sessions", "domain_id") |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 +29,11 @@ | |
| from ai.backend.common.identifier.deployment import DeploymentID | ||
| from ai.backend.common.identifier.deployment_preset import DeploymentPresetID | ||
| from ai.backend.common.identifier.deployment_revision import DeploymentRevisionID | ||
| from ai.backend.common.identifier.domain import DomainID | ||
| from ai.backend.common.identifier.image import ImageID | ||
| from ai.backend.common.identifier.replica import ReplicaID | ||
| from ai.backend.common.identifier.replica_group import ReplicaGroupID | ||
| from ai.backend.common.identifier.resource_group import ResourceGroupName | ||
| from ai.backend.common.identifier.resource_group import ResourceGroupID, ResourceGroupName | ||
| from ai.backend.common.identifier.runtime_variant import RuntimeVariantID | ||
| from ai.backend.common.identifier.vfolder import VFolderUUID | ||
| from ai.backend.common.types import ( | ||
|
|
@@ -105,6 +106,7 @@ | |
| UserNotFoundInDeployment, | ||
| ) | ||
| from ai.backend.manager.errors.resource import ( | ||
| DomainNotFound, | ||
| ProjectNotFound, | ||
| RuntimeVariantNotFound, | ||
| ScalingGroupNotFound, | ||
|
|
@@ -124,6 +126,7 @@ | |
| from ai.backend.manager.models.deployment_revision_preset.row import ( | ||
| DeploymentRevisionPresetRow, | ||
| ) | ||
| from ai.backend.manager.models.domain import DomainRow | ||
| from ai.backend.manager.models.endpoint import ( | ||
| EndpointAutoScalingRuleRow, | ||
| EndpointRow, | ||
|
|
@@ -2099,6 +2102,29 @@ async def _resolve_user_and_active_access_key( | |
| raise UserNotFoundInDeployment(f"{user_uuid} not found") | ||
| raise NoActiveKeypairForDeployment(f"{user_uuid} has no active keypair") | ||
|
|
||
| async def _resolve_deployment_scope_ids( | ||
| self, | ||
| db_sess: SASession, | ||
| deployment_info: DeploymentInfo, | ||
| ) -> tuple[DomainID, ResourceGroupID]: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote it this way because this method is used in only one place, and since it will be removed during future refactoring based on the ID, I didn't wrap it in a separate data class or split it into two methods. |
||
| domain_id = await db_sess.scalar( | ||
| sa.select(DomainRow.id).where(DomainRow.name == deployment_info.metadata.domain) | ||
| ) | ||
| if domain_id is None: | ||
| raise DomainNotFound(deployment_info.metadata.domain) | ||
|
|
||
| resource_group_id = await db_sess.scalar( | ||
| sa.select(ScalingGroupRow.id).where( | ||
| ScalingGroupRow.name == deployment_info.metadata.resource_group | ||
| ) | ||
| ) | ||
| if resource_group_id is None: | ||
| raise ScalingGroupNotFound( | ||
| f"Resource group {deployment_info.metadata.resource_group!r} not found" | ||
| ) | ||
|
|
||
| return DomainID(domain_id), ResourceGroupID(resource_group_id) | ||
|
|
||
| async def fetch_deployment_context( | ||
| self, | ||
| deployment_info: DeploymentInfo, | ||
|
|
@@ -2147,6 +2173,10 @@ async def fetch_deployment_context( | |
| group_id = user_info.group_id | ||
| resource_policy = user_info.resource_policy | ||
|
|
||
| domain_id, resource_group_id = await self._resolve_deployment_scope_ids( | ||
| db_sess, deployment_info | ||
| ) | ||
|
|
||
| revision_query = ( | ||
| sa.select(DeploymentRevisionRow) | ||
| .where(DeploymentRevisionRow.id == revision_id) | ||
|
|
@@ -2212,7 +2242,9 @@ async def fetch_deployment_context( | |
| main_gid=session_owner_user.container_main_gid, | ||
| supplementary_gids=session_owner_user.container_gids or [], | ||
| ), | ||
| domain_id=domain_id, | ||
| group_id=group_id, | ||
| resource_group_id=resource_group_id, | ||
| resource_policy=dict(resource_policy), | ||
| image=ImageContext( | ||
| ref=image_row.image_ref, | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this used?