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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changes/3707.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add sum of resource slots field to scaling group schema
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. The sum of occupied slots across compute sessions that occupying agent's resources. Only includes sessions owned by the 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'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it difficult to pass the type we use instead of JSONString?

}

type StorageVolume implements Item {
Expand Down
37 changes: 37 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,15 @@ class ScalingGroup(graphene.ObjectType):
),
)

# TODO: Replace this field with a generic resource slot query API
own_session_occupied_resource_slots = graphene.Field(
graphene.JSONString,
description=(
"Added in 25.03.0. The sum of occupied slots across compute sessions that occupying agent's resources. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not 25.03.0, but rather 25.3.1.

"Only includes sessions owned by the user."
),
)

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

# TODO: Replace this field with a generic resource slot query API
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.agent_row)
.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