-
Notifications
You must be signed in to change notification settings - Fork 159
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
fregataa
wants to merge
6
commits into
main
Choose a base branch
from
feat/add-own-session-occupied-resource-slot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
87b457e
feat: Add sum of resource slots field to scaling group schema
fregataa d82cd0e
add news fragment
fregataa 14a07f0
fix wrong orm api usage
fregataa ea55b25
update description
fregataa 0aea158
add TODO msg
fregataa 2f40a6b
chore: update api schema dump
fregataa 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 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 sum of resource slots field to scaling group schema |
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 |
---|---|---|
|
@@ -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. " | ||
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. 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: | ||
|
@@ -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, | ||
|
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 it difficult to pass the type we use instead of JSONString?