Skip to content

Commit

Permalink
feat: support Zilliz Cloud serverless (#743)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid authored Jan 20, 2025
1 parent 05a4a3c commit 535f566
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
7 changes: 6 additions & 1 deletion client/src/context/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const authContext = createContext<AuthContextType>({
},
setAuthReq: () => {},
isManaged: false,
isServerless: false,
isAuth: false,
login: async () => {
return { clientId: '', database: '' };
Expand Down Expand Up @@ -91,6 +92,9 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
window.localStorage.removeItem(MILVUS_CLIENT_ID);
};

const isManaged = authReq.address.includes('zilliz');
const isServerless = isManaged && authReq.address.includes('serverless');

return (
<Provider
value={{
Expand All @@ -100,7 +104,8 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
logout,
clientId,
isAuth: !!clientId,
isManaged: authReq.address.includes('zilliz'),
isManaged: isManaged,
isServerless:isServerless,
}}
>
{props.children}
Expand Down
6 changes: 3 additions & 3 deletions client/src/context/System.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const systemContext = createContext<SystemContextType>({

const { Provider } = systemContext;
export const SystemProvider = (props: { children: React.ReactNode }) => {
const { isAuth } = useContext(authContext);
const { isAuth, isServerless } = useContext(authContext);

const [data, setData] = useState<any>({});

Expand All @@ -20,8 +20,8 @@ export const SystemProvider = (props: { children: React.ReactNode }) => {
// fetch all data
const [metrics, users, roles] = await Promise.all([
MilvusService.getMetrics(),
UserService.getUsers(),
UserService.getRoles(),
!isServerless ? UserService.getUsers() : { usernames: [] },
!isServerless ? UserService.getRoles() : { results: [] },
]);

// parse data
Expand Down
1 change: 1 addition & 0 deletions client/src/context/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type AuthContextType = {
setAuthReq: Dispatch<SetStateAction<AuthReq>>;
clientId: string;
isManaged: boolean;
isServerless: boolean;
isAuth: boolean;
logout: (pass?: boolean) => void;
login: (params: AuthReq) => Promise<AuthObject>;
Expand Down
11 changes: 8 additions & 3 deletions client/src/pages/databases/Databases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ const DatabasesTab = (props: {
databaseName: string;
tabClass: string; // tab class
}) => {
// context
const { isManaged } = useContext(authContext);
const { databaseName, tabClass, databasePage } = props;
const { t: collectionTrans } = useTranslation('collection');

Expand All @@ -330,12 +332,15 @@ const DatabasesTab = (props: {
component: <Collections />,
path: `collections`,
},
{
];

if (!isManaged) {
dbTab.push({
label: collectionTrans('properties'),
component: <Properties type="database" target={databaseName} />,
path: `properties`,
},
];
});
}

const actionDbTab = dbTab.findIndex(t => t.path === databasePage);

Expand Down
9 changes: 7 additions & 2 deletions client/src/pages/home/DatabaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const DatabaseCard: FC<DatabaseCardProps> = ({
isActive = false,
}) => {
// context
const { isManaged } = useContext(authContext);
const { isManaged, isServerless } = useContext(authContext);
const { setDialog, openSnackBar, handleCloseDialog } =
useContext(rootContext);

Expand Down Expand Up @@ -150,6 +150,11 @@ const DatabaseCard: FC<DatabaseCardProps> = ({
<section
className={`${wrapperClass} ${classes.wrapper} ${classes.create}`}
onClick={() => {
if (isManaged) {
// go to https://cloud.zilliz.com/orgs/
window.open('https://cloud.zilliz.com/', '_blank');
return;
}
setDialog({
open: true,
type: 'custom',
Expand Down Expand Up @@ -201,7 +206,7 @@ const DatabaseCard: FC<DatabaseCardProps> = ({
</>
)}
</div>
{database.name !== 'default' && (
{database.name !== 'default' && !isServerless && (
<CustomButton
className={classes.delIcon}
tooltip={`${btnTrans('drop')} ${dbTrans('database')}`}
Expand Down
2 changes: 0 additions & 2 deletions server/src/milvus/milvus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ export class MilvusService {
if (clientCache.has(clientId)) {
const { milvusClient } = clientCache.get(clientId);

console.info('Deleting client', clientId);

const res = await milvusClient.closeConnection();

// clear crons
Expand Down

0 comments on commit 535f566

Please sign in to comment.