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: Add the ability to override resources on a per-user basis #1981

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zusorio
Copy link
Member

@zusorio zusorio commented Nov 12, 2024

Closes #1951

Copy link

The generated OpenAPI client is not up to date with the latest changes in the OpenAPI specification.
Please run make openapi locally and commit the changes.

Copy link

github-actions bot commented Nov 12, 2024

API Changelog 4.15.1.dev18+g39fabe1f

GET /api/v1/projects/{project_slug}/models

  • ⚠️ removed the required property '/items/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/items/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/items/tool/config/resources/default_profile' to the response with the '200' status

POST /api/v1/projects/{project_slug}/models

  • ⚠️ removed the required property 'tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'tool/config/resources/memory' from the response with the '200' status
  • added the required property 'tool/config/resources/additional' to the response with the '200' status
  • added the required property 'tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/projects/{project_slug}/models/{model_slug}

  • ⚠️ removed the required property 'tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'tool/config/resources/memory' from the response with the '200' status
  • added the required property 'tool/config/resources/additional' to the response with the '200' status
  • added the required property 'tool/config/resources/default_profile' to the response with the '200' status

PATCH /api/v1/projects/{project_slug}/models/{model_slug}

  • ⚠️ removed the required property 'tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'tool/config/resources/memory' from the response with the '200' status
  • added the required property 'tool/config/resources/additional' to the response with the '200' status
  • added the required property 'tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/projects/{project_slug}/models/{model_slug}/provisioning

  • ⚠️ removed the required property '/anyOf[subschema 1: ModelProvisioning]/session/anyOf[subschema 1: Session]/version/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/anyOf[subschema 1: ModelProvisioning]/session/anyOf[subschema 1: Session]/version/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/anyOf[subschema 1: ModelProvisioning]/session/anyOf[subschema 1: Session]/version/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/anyOf[subschema 1: ModelProvisioning]/session/anyOf[subschema 1: Session]/version/tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/projects/{project_slug}/tools

  • ⚠️ removed the required property '/items/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/items/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/items/tool/config/resources/default_profile' to the response with the '200' status

POST /api/v1/projects/{project_slug}/tools

  • ⚠️ removed the required property 'tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'tool/config/resources/memory' from the response with the '200' status
  • added the required property 'tool/config/resources/additional' to the response with the '200' status
  • added the required property 'tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/sessions

  • ⚠️ removed the required property '/items/version/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/version/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/items/version/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/items/version/tool/config/resources/default_profile' to the response with the '200' status

POST /api/v1/sessions

  • ⚠️ removed the required property 'version/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'version/tool/config/resources/memory' from the response with the '200' status
  • added the required property 'version/tool/config/resources/additional' to the response with the '200' status
  • added the required property 'version/tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/sessions/{session_id}

  • ⚠️ removed the required property 'version/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'version/tool/config/resources/memory' from the response with the '200' status
  • added the required property 'version/tool/config/resources/additional' to the response with the '200' status
  • added the required property 'version/tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/tools

  • ⚠️ removed the required property '/items/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/config/resources/memory' from the response with the '200' status
  • added the required property '/items/config/resources/additional' to the response with the '200' status
  • added the required property '/items/config/resources/default_profile' to the response with the '200' status

POST /api/v1/tools

  • ⚠️ removed the required property 'config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'config/resources/memory' from the response with the '200' status
  • ⚠️ removed the request property 'config/resources/cpu'
  • ⚠️ removed the request property 'config/resources/memory'
  • added the new optional request property 'config/resources/additional'
  • added the new optional request property 'config/resources/default_profile'
  • added the required property 'config/resources/additional' to the response with the '200' status
  • added the required property 'config/resources/default_profile' to the response with the '200' status

GET /api/v1/tools/*/versions

  • ⚠️ removed the required property '/items/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/items/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/items/tool/config/resources/default_profile' to the response with the '200' status

GET /api/v1/tools/default

  • ⚠️ removed the required property 'config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'config/resources/memory' from the response with the '200' status
  • added the required property 'config/resources/additional' to the response with the '200' status
  • added the required property 'config/resources/default_profile' to the response with the '200' status

GET /api/v1/tools/{tool_id}

  • ⚠️ removed the required property 'config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'config/resources/memory' from the response with the '200' status
  • added the required property 'config/resources/additional' to the response with the '200' status
  • added the required property 'config/resources/default_profile' to the response with the '200' status

PUT /api/v1/tools/{tool_id}

  • ⚠️ removed the required property 'config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property 'config/resources/memory' from the response with the '200' status
  • ⚠️ removed the request property 'config/resources/cpu'
  • ⚠️ removed the request property 'config/resources/memory'
  • added the new optional request property 'config/resources/additional'
  • added the new optional request property 'config/resources/default_profile'
  • added the required property 'config/resources/additional' to the response with the '200' status
  • added the required property 'config/resources/default_profile' to the response with the '200' status

GET /api/v1/users/{user_id}/sessions

  • ⚠️ removed the required property '/items/version/tool/config/resources/cpu' from the response with the '200' status
  • ⚠️ removed the required property '/items/version/tool/config/resources/memory' from the response with the '200' status
  • added the required property '/items/version/tool/config/resources/additional' to the response with the '200' status
  • added the required property '/items/version/tool/config/resources/default_profile' to the response with the '200' status

This comment has been minimized.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.53%. Comparing base (5290f43) to head (b821a01).

Files with missing lines Patch % Lines
backend/capellacollab/tools/crud.py 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1981      +/-   ##
==========================================
+ Coverage   85.46%   85.53%   +0.07%     
==========================================
  Files         225      225              
  Lines        7411     7448      +37     
  Branches      513      524      +11     
==========================================
+ Hits         6334     6371      +37     
+ Misses        913      912       -1     
- Partials      164      165       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@zusorio zusorio force-pushed the custom-resources-for-users branch from c773244 to cab1a6a Compare November 12, 2024 17:28

This comment has been minimized.

Copy link

github-actions bot commented Nov 12, 2024

A Storybook preview is available for commit 39fabe1.
➡️ View Storybook
➡️ View Chromatic build

@zusorio zusorio force-pushed the custom-resources-for-users branch from cab1a6a to ee32de9 Compare November 12, 2024 17:59

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from ee32de9 to 913c962 Compare November 12, 2024 18:05

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from 913c962 to 7f8a7f0 Compare November 13, 2024 13:13
@zusorio zusorio marked this pull request as ready for review November 14, 2024 07:14
@zusorio zusorio force-pushed the custom-resources-for-users branch 2 times, most recently from 7c78706 to dee00aa Compare November 18, 2024 14:49

This comment has been minimized.

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from dee00aa to 6faaae9 Compare November 18, 2024 15:02

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from 6faaae9 to bccb9e0 Compare November 19, 2024 09:01

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from bccb9e0 to c7638a7 Compare November 19, 2024 09:26

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from c7638a7 to 36301ab Compare November 19, 2024 11:04

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from 36301ab to 5511b3e Compare November 19, 2024 11:28

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from 5511b3e to bd2222e Compare November 19, 2024 11:34

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch from bd2222e to c65e4ac Compare November 19, 2024 11:44

This comment has been minimized.

@zusorio zusorio force-pushed the custom-resources-for-users branch 2 times, most recently from 978e1df to b821a01 Compare November 20, 2024 11:31

This comment has been minimized.

Copy link

This report was generated by comparing bca8fb2 with 5290f43.
If you would like to check difference, please check here.

success

ArtifactName: reg

✨✨ That's perfect, there is no visual difference! ✨✨

item count
pass 412
change 0
new 0
delete 0

Comment on lines +254 to +259
default_profile: DefaultResourceProfile = pydantic.Field(
default_factory=DefaultResourceProfile,
description="Default resource profile, which is used when no other profile matches.",
)
additional: dict[str, AdditionalResourceProfile] = pydantic.Field(
default={},
description="Additional resource profiles, which can be used to limit the resource usage of sessions.",
)
Copy link
Member

Choose a reason for hiding this comment

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

I'd add another layer in the configuration:

resources: 
  profiles:
    default: ...
    additional: ...

If you change it, make sure to also update the docs and migration script.

)


class Resources(core_pydantic.BaseModelStrict):
Copy link
Member

@MoritzWeber0 MoritzWeber0 Dec 2, 2024

Choose a reason for hiding this comment

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

The API Changelog generation indicates for which endpoints the class is used: #1981 (comment)

For data protection and political reasons, we should not expose the list of usernames of the profiles to users with role user. We should hide the list of usernames in the response for normal users (e.g., via pydantic validator). Alternatively, we can return only the relevant resource profile for the user.

Comment on lines +73 to +85
tools = get_tools(db)
for tool in tools:
updated = False
for profile in tool.config.resources.additional.values():
if old_username in profile.usernames:
profile.usernames = [
new_username if username == old_username else username
for username in profile.usernames
]
updated = True
if updated:
orm.attributes.flag_modified(tool, "config")
db.commit()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tools = get_tools(db)
for tool in tools:
updated = False
for profile in tool.config.resources.additional.values():
if old_username in profile.usernames:
profile.usernames = [
new_username if username == old_username else username
for username in profile.usernames
]
updated = True
if updated:
orm.attributes.flag_modified(tool, "config")
db.commit()
tools = get_tools(db)
for tool in tools:
for profile in tool.config.resources.additional.values():
if old_username in profile.usernames:
profile.usernames = [
new_username if username == old_username else username
for username in profile.usernames
]
orm.attributes.flag_modified(tool, "config")
db.commit()


@pydantic.field_validator("additional")
@classmethod
def check_additional_profiles(
Copy link
Member

Choose a reason for hiding this comment

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

A validation if the user exists is missing.

@@ -80,6 +81,8 @@ def create_user(
def update_user(
Copy link
Member

Choose a reason for hiding this comment

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

If the user is deleted, the username should be removed from the list.

@zusorio zusorio force-pushed the custom-resources-for-users branch from b821a01 to 3b05699 Compare December 16, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overwrite resources for individual tool users
2 participants