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(BA-750): Add sum of resource slots field to scaling group schema #3707

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/manager/graphql-reference/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,11 @@
"""
status: String = "ALIVE"
): JSONString

"""
Added in 25.03.0. Sum of occupied slots of compute sessions owned by user.
"""
own_session_occupied_resource_slots: JSONString

Check notice on line 1189 in docs/manager/graphql-reference/schema.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector

Field 'own_session_occupied_resource_slots' was added to object type 'ScalingGroup'

Field 'own_session_occupied_resource_slots' was added to object type 'ScalingGroup'
}

type StorageVolume implements Item {
Expand Down
36 changes: 36 additions & 0 deletions src/ai/backend/manager/models/scaling_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class ScalingGroup(graphene.ObjectType):
),
)

own_session_occupied_resource_slots = graphene.Field(
graphene.JSONString,
description="Added in 25.03.0. Sum of occupied slots of compute sessions owned by user.",
)

async def resolve_agent_count_by_status(
self, info: graphene.ResolveInfo, status: str = AgentStatus.ALIVE.name
) -> int:
Expand Down Expand Up @@ -479,6 +484,37 @@ async def resolve_agent_total_resource_slots_by_status(
"available_slots": total_available_slots.to_json(),
}

async def resolve_own_session_occupied_resource_slots(
self, info: graphene.ResolveInfo
) -> Mapping[str, Any]:
from .agent import AgentRow
from .kernel import AGENT_RESOURCE_OCCUPYING_KERNEL_STATUSES, KernelRow

graph_ctx: GraphQueryContext = info.context
user = graph_ctx.user
async with graph_ctx.db.begin_readonly_session() as db_session:
query = (
sa.select(KernelRow)
.join(
KernelRow,
AgentRow,
KernelRow.agent == AgentRow.id,
)
.where(
sa.and_(
KernelRow.status.in_(AGENT_RESOURCE_OCCUPYING_KERNEL_STATUSES),
KernelRow.user_uuid == user["uuid"],
AgentRow.scaling_group == self.name,
)
)
)
result = await db_session.scalars(query)
kernel_rows = cast(list[KernelRow], result.all())
occupied_slots = ResourceSlot()
for kernel in kernel_rows:
occupied_slots += kernel.occupied_slots
return occupied_slots.to_json()

@classmethod
def from_row(
cls,
Expand Down
Loading