Skip to content

Commit

Permalink
fix: Fixed the maximum desired number of sessions value in the Model …
Browse files Browse the repository at this point in the history
…Launcher modal to follow `max_session_count_per_model_session` (#2726)

### This PR resolves [#2723 Issue](#2723)

[teams](https://teams.microsoft.com/l/message/19:[email protected]/1727418901786?tenantId=13c6a44d-9b52-4b9e-aa34-0513ee7131f2&groupId=74ae2c4d-ec4d-4fdf-b2c2-f5041d1e8631&parentMessageId=1727418901786&teamName=devops&channelName=Backend.AI%20Talks&createdTime=1727418901786)

This PR introduces a new query to fetch the user's resource policy and applies the `max_session_count_per_model_session` limit to the service launcher page. The changes include:

- Added two new queries: `ServiceLauncherPageContent_UserInfoQuery` and `ServiceLauncherPageContent_UserResourcePolicyQuery`
- Utilized `useLazyLoadQuery` to fetch user information and resource policy
- Applied the `max_session_count_per_model_session` from the user's resource policy to the session count input field

These changes allow for dynamic session count limits based on the user's resource policy, improving the flexibility and customization of the service launcher.

**Checklist:**

- [ ] Documentation update for new resource policy feature
- [ ] Minimum required manager version: 23.09.6
- [ ] Test cases to verify the application of custom max session count limits
  • Loading branch information
ironAiken2 committed Sep 30, 2024
1 parent 0c00d60 commit 25973e0
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions react/src/components/ServiceLauncherPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import VFolderSelect from './VFolderSelect';
import VFolderTableFormItem from './VFolderTableFormItem';
import { ServiceLauncherPageContentFragment$key } from './__generated__/ServiceLauncherPageContentFragment.graphql';
import { ServiceLauncherPageContentModifyMutation } from './__generated__/ServiceLauncherPageContentModifyMutation.graphql';
import { ServiceLauncherPageContent_UserInfoQuery } from './__generated__/ServiceLauncherPageContent_UserInfoQuery.graphql';
import { ServiceLauncherPageContent_UserResourcePolicyQuery } from './__generated__/ServiceLauncherPageContent_UserResourcePolicyQuery.graphql';
import { MinusOutlined } from '@ant-design/icons';
import {
App,
Expand All @@ -47,7 +49,7 @@ import graphql from 'babel-plugin-relay/macro';
import _ from 'lodash';
import React, { Suspense, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useFragment, useMutation } from 'react-relay';
import { useFragment, useLazyLoadQuery, useMutation } from 'react-relay';
import { StringParam, useQueryParams } from 'use-query-params';

const ServiceValidationView = React.lazy(
Expand Down Expand Up @@ -354,6 +356,41 @@ const ServiceLauncherPageContent: React.FC<ServiceLauncherPageContentProps> = ({
},
});

const { user } = useLazyLoadQuery<ServiceLauncherPageContent_UserInfoQuery>(
graphql`
query ServiceLauncherPageContent_UserInfoQuery(
$domain_name: String
$email: String
) {
user(domain_name: $domain_name, email: $email) {
id
# https://github.com/lablup/backend.ai/pull/1354
resource_policy @since(version: "23.09.0")
}
}
`,
{
domain_name: useCurrentDomainValue(),
email: baiClient?.email,
},
);

const { user_resource_policy } =
useLazyLoadQuery<ServiceLauncherPageContent_UserResourcePolicyQuery>(
graphql`
query ServiceLauncherPageContent_UserResourcePolicyQuery(
$user_RP_name: String
) {
user_resource_policy(name: $user_RP_name) @since(version: "23.09.6") {
max_session_count_per_model_session
}
}
`,
{
user_RP_name: user?.resource_policy,
},
);

const [
commitModifyEndpoint,
// inInFlightCommitModifyEndpoint
Expand Down Expand Up @@ -565,7 +602,13 @@ const ServiceLauncherPageContent: React.FC<ServiceLauncherPageContentProps> = ({
});
}
})
.catch((err: any) => {
.catch((err) => {
// Form has `scrollToFirstError` prop, but it doesn't work. So, we need to scroll manually.
err?.errorFields?.[0]?.name &&
form.scrollToField(err.errorFields[0].name, {
behavior: 'smooth',
block: 'center',
});
// this catch function only for form validation error and unhandled error in `form.validateFields()..then()`.
// It's not for error handling in mutation.
});
Expand Down Expand Up @@ -595,7 +638,7 @@ const ServiceLauncherPageContent: React.FC<ServiceLauncherPageContentProps> = ({
serviceName: endpoint?.name,
resourceGroup: endpoint?.resource_group,
allocationPreset: 'custom',
desiredRoutingCount: endpoint?.desired_session_count || 0,
desiredRoutingCount: endpoint?.desired_session_count || 1,
// FIXME: memory doesn't applied to resource allocation
resource: {
cpu: parseInt(JSON.parse(endpoint?.resource_slots)?.cpu),
Expand Down Expand Up @@ -836,15 +879,25 @@ const ServiceLauncherPageContent: React.FC<ServiceLauncherPageContentProps> = ({
rules={[
{
required: true,
},
{
type: 'number',
min: 0,
max: 10,
},
{
type: 'number',
max:
user_resource_policy?.max_session_count_per_model_session ??
0,
},
]}
>
<InputNumberWithSlider
min={0}
max={10}
max={
user_resource_policy?.max_session_count_per_model_session ??
0
}
inputNumberProps={{
//TODO: change unit based on resource limit
addonAfter: '#',
Expand Down

0 comments on commit 25973e0

Please sign in to comment.