Skip to content

Commit

Permalink
support bypass check health on connection (#676)
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid authored Oct 22, 2024
1 parent 8870508 commit 4de3d75
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions client/src/context/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const authContext = createContext<AuthContextType>({
address: '',
token: '',
database: '',
checkHealth: true,
},
setAuthReq: () => {},
isManaged: false,
Expand All @@ -38,6 +39,7 @@ export const AuthProvider = (props: { children: React.ReactNode }) => {
address: MILVUS_URL,
token: '',
database: MILVUS_DATABASE,
checkHealth: true,
})
);

Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/cn/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const commonTrans = {
prometheusInstance: 'Prometheus实例',
prometheusNamespace: 'Prometheus命名空间',
connectionTip: '支持自托管Milvus或Zilliz云专用集群。',
checkHealth: '检查健康状态',
},
status: {
loaded: '已加载',
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const commonTrans = {
prometheusNamespace: 'Prometheus Namespace',
connectionTip:
'Self-hosted Milvus or Zilliz Cloud Dedicated cluster are supported.',
checkHealth: 'Check Health',
},
status: {
loaded: 'loaded',
Expand Down
25 changes: 23 additions & 2 deletions client/src/pages/connect/AuthForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 CustomButton from '@/components/customButton/CustomButton';
import CustomInput from '@/components/customInput/CustomInput';
Expand Down Expand Up @@ -30,6 +30,7 @@ const DEFAULT_CONNECTION = {
token: '',
username: '',
password: '',
checkHealth: true,
time: -1,
};

Expand Down Expand Up @@ -68,7 +69,13 @@ export const AuthForm = () => {
// UI handlers
// handle input change
const handleInputChange = (
key: 'address' | 'username' | 'password' | 'database' | 'token',
key:
| 'address'
| 'username'
| 'password'
| 'database'
| 'token'
| 'checkHealth',
value: string | boolean
) => {
// set database to default if empty
Expand Down Expand Up @@ -128,6 +135,7 @@ export const AuthForm = () => {
password: authReq.password,
token: authReq.token,
time: Date.now(),
checkHealth: authReq.checkHealth,
},
];

Expand Down Expand Up @@ -363,6 +371,19 @@ export const AuthForm = () => {
<CustomButton type="submit" variant="contained" disabled={btnDisabled}>
{btnTrans(isConnecting ? 'connecting' : 'connect')}
</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>

<Menu
Expand Down
14 changes: 14 additions & 0 deletions client/src/pages/connect/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ export const useStyles = makeStyles((theme: Theme) => ({
width: '100%',
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: {
position: 'absolute',
top: -48,
Expand Down
4 changes: 3 additions & 1 deletion server/src/milvus/milvus.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ export class MilvusController {
}

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 {
const result = await this.milvusService.connectMilvus({
address,
token,
username,
password,
database,
checkHealth,
});

res.send(result);
Expand Down
14 changes: 8 additions & 6 deletions server/src/milvus/milvus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MilvusService {

async connectMilvus(data: AuthReq): Promise<AuthObject> {
// 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
const milvusAddress = MilvusService.formatAddress(address);

Expand Down Expand Up @@ -71,12 +71,14 @@ export class MilvusService {
}

// 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
Expand Down
1 change: 1 addition & 0 deletions server/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type AuthReq = {
address: string;
token: string;
database: string;
checkHealth: boolean;
};

export type AuthObject = {
Expand Down

0 comments on commit 4de3d75

Please sign in to comment.