Browse Source

support bypass check health on connection (#676)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 8 months ago
parent
commit
4de3d75316

+ 2 - 0
client/src/context/Auth.tsx

@@ -17,6 +17,7 @@ export const authContext = createContext<AuthContextType>({
     address: '',
     address: '',
     token: '',
     token: '',
     database: '',
     database: '',
+    checkHealth: true,
   },
   },
   setAuthReq: () => {},
   setAuthReq: () => {},
   isManaged: false,
   isManaged: false,
@@ -38,6 +39,7 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
         address: MILVUS_URL,
         address: MILVUS_URL,
         token: '',
         token: '',
         database: MILVUS_DATABASE,
         database: MILVUS_DATABASE,
+        checkHealth: true,
       })
       })
   );
   );
 
 

+ 1 - 0
client/src/i18n/cn/common.ts

@@ -16,6 +16,7 @@ const commonTrans = {
     prometheusInstance: 'Prometheus实例',
     prometheusInstance: 'Prometheus实例',
     prometheusNamespace: 'Prometheus命名空间',
     prometheusNamespace: 'Prometheus命名空间',
     connectionTip: '支持自托管Milvus或Zilliz云专用集群。',
     connectionTip: '支持自托管Milvus或Zilliz云专用集群。',
+    checkHealth:  '检查健康状态',
   },
   },
   status: {
   status: {
     loaded: '已加载',
     loaded: '已加载',

+ 1 - 0
client/src/i18n/en/common.ts

@@ -17,6 +17,7 @@ const commonTrans = {
     prometheusNamespace: 'Prometheus Namespace',
     prometheusNamespace: 'Prometheus Namespace',
     connectionTip:
     connectionTip:
       'Self-hosted Milvus or Zilliz Cloud Dedicated cluster are supported.',
       'Self-hosted Milvus or Zilliz Cloud Dedicated cluster are supported.',
+    checkHealth: 'Check Health',
   },
   },
   status: {
   status: {
     loaded: 'loaded',
     loaded: 'loaded',

+ 23 - 2
client/src/pages/connect/AuthForm.tsx

@@ -1,5 +1,5 @@
 import React, { useContext, useEffect, useMemo, useState } from 'react';
 import React, { useContext, useEffect, useMemo, useState } from 'react';
-import { Typography, Menu } from '@mui/material';
+import { Typography, Menu, Checkbox } from '@mui/material';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import CustomButton from '@/components/customButton/CustomButton';
 import CustomButton from '@/components/customButton/CustomButton';
 import CustomInput from '@/components/customInput/CustomInput';
 import CustomInput from '@/components/customInput/CustomInput';
@@ -30,6 +30,7 @@ const DEFAULT_CONNECTION = {
   token: '',
   token: '',
   username: '',
   username: '',
   password: '',
   password: '',
+  checkHealth: true,
   time: -1,
   time: -1,
 };
 };
 
 
@@ -68,7 +69,13 @@ export const AuthForm = () => {
   // UI handlers
   // UI handlers
   // handle input change
   // handle input change
   const handleInputChange = (
   const handleInputChange = (
-    key: 'address' | 'username' | 'password' | 'database' | 'token',
+    key:
+      | 'address'
+      | 'username'
+      | 'password'
+      | 'database'
+      | 'token'
+      | 'checkHealth',
     value: string | boolean
     value: string | boolean
   ) => {
   ) => {
     // set database to default if empty
     // set database to default if empty
@@ -128,6 +135,7 @@ export const AuthForm = () => {
           password: authReq.password,
           password: authReq.password,
           token: authReq.token,
           token: authReq.token,
           time: Date.now(),
           time: Date.now(),
+          checkHealth: authReq.checkHealth,
         },
         },
       ];
       ];
 
 
@@ -363,6 +371,19 @@ export const AuthForm = () => {
         <CustomButton type="submit" variant="contained" disabled={btnDisabled}>
         <CustomButton type="submit" variant="contained" disabled={btnDisabled}>
           {btnTrans(isConnecting ? 'connecting' : 'connect')}
           {btnTrans(isConnecting ? 'connecting' : 'connect')}
         </CustomButton>
         </CustomButton>
+
+        <div className={classes.checkHealth}>
+          <label>
+            <Checkbox
+              size="small"
+              checked={authReq.checkHealth}
+              onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
+                handleInputChange('checkHealth', e.target.checked);
+              }}
+            />
+            <Typography component="span">{attuTrans.checkHealth}</Typography>
+          </label>
+        </div>
       </section>
       </section>
 
 
       <Menu
       <Menu

+ 14 - 0
client/src/pages/connect/style.ts

@@ -28,6 +28,20 @@ export const useStyles = makeStyles((theme: Theme) => ({
     width: '100%',
     width: '100%',
     justifyContent: 'flex-start',
     justifyContent: 'flex-start',
   },
   },
+  checkHealth: {
+    display: 'flex',
+    alignItems: 'center',
+    marginTop: 4,
+    '& .MuiCheckbox-root': {
+      margin: 0,
+      padding: '8px 4px 8px 0',
+    },
+    '& span': {
+      cursor: 'pointer',
+      fontSize: 12,
+      fontStyle: 'italic',
+    },
+  },
   star: {
   star: {
     position: 'absolute',
     position: 'absolute',
     top: -48,
     top: -48,

+ 3 - 1
server/src/milvus/milvus.controller.ts

@@ -41,7 +41,8 @@ export class MilvusController {
   }
   }
 
 
   async connectMilvus(req: Request, res: Response, next: NextFunction) {
   async connectMilvus(req: Request, res: Response, next: NextFunction) {
-    const { address, username, password, database, token } = req.body;
+    const { address, username, password, database, token, checkHealth } =
+      req.body;
     try {
     try {
       const result = await this.milvusService.connectMilvus({
       const result = await this.milvusService.connectMilvus({
         address,
         address,
@@ -49,6 +50,7 @@ export class MilvusController {
         username,
         username,
         password,
         password,
         database,
         database,
+        checkHealth,
       });
       });
 
 
       res.send(result);
       res.send(result);

+ 8 - 6
server/src/milvus/milvus.service.ts

@@ -26,7 +26,7 @@ export class MilvusService {
 
 
   async connectMilvus(data: AuthReq): Promise<AuthObject> {
   async connectMilvus(data: AuthReq): Promise<AuthObject> {
     // Destructure the data object to get the connection details
     // Destructure the data object to get the connection details
-    const { address, token, username, password, database } = data;
+    const { address, token, username, password, database, checkHealth } = data;
     // Format the address to remove the http prefix
     // Format the address to remove the http prefix
     const milvusAddress = MilvusService.formatAddress(address);
     const milvusAddress = MilvusService.formatAddress(address);
 
 
@@ -71,12 +71,14 @@ export class MilvusService {
       }
       }
 
 
       // Check the health of the Milvus server
       // Check the health of the Milvus server
-      const res = await milvusClient.checkHealth();
+      if (checkHealth) {
+        const res = await milvusClient.checkHealth();
 
 
-      // If the server is not healthy, throw an error
-      if (!res.isHealthy) {
-        clientCache.delete(milvusClient.clientId);
-        throw new Error('Milvus is not ready yet.');
+        // If the server is not healthy, throw an error
+        if (!res.isHealthy) {
+          clientCache.delete(milvusClient.clientId);
+          throw new Error('Milvus is not ready yet.');
+        }
       }
       }
 
 
       // database
       // database

+ 1 - 0
server/src/types/index.ts

@@ -16,6 +16,7 @@ export type AuthReq = {
   address: string;
   address: string;
   token: string;
   token: string;
   database: string;
   database: string;
+  checkHealth: boolean;
 };
 };
 
 
 export type AuthObject = {
 export type AuthObject = {