Skip to content

Commit

Permalink
Merge pull request #268 from zilliztech/refactor
Browse files Browse the repository at this point in the history
Support import sever module in client
  • Loading branch information
shanghaikid authored Sep 18, 2023
2 parents 6f025d5 + ed0f72d commit a8c9abf
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 694 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Attu docker build test

on:
pull_request:
branches:
- main
types: [opened, synchronize]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Docker Build
run: docker build -t zilliz/attu:dev --build-arg VERSION=dev .
3 changes: 2 additions & 1 deletion client/src/components/layout/GlobalEffect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useContext } from 'react';
import axiosInstance from '@/http/Axios';
import { rootContext, authContext } from '@/context';
import { HTTP_STATUS_CODE, MILVUS_ADDRESS } from '@/consts';
import { MILVUS_ADDRESS } from '@/consts';
import { HTTP_STATUS_CODE } from '@server/utils/Const';

let axiosResInterceptor: number | null = null;
// let timer: Record<string, ReturnType<typeof setTimeout> | number>[] = [];
Expand Down
61 changes: 0 additions & 61 deletions client/src/consts/Http.ts

This file was deleted.

1 change: 0 additions & 1 deletion client/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './Http';
export * from './Insert';
export * from './Localstorage';
export * from './Milvus';
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/WebSocket.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createContext, useContext, useEffect, useState, useRef } from 'react';
import { io, Socket } from 'socket.io-client';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
import { authContext } from '@/context';
import { url, CollectionHttp, MilvusHttp } from '@/http';
import { CollectionView } from '@/pages/collections/Types';
import { checkIndexBuilding, checkLoading } from '@/utils';
import { WebSocketType } from './Types';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';

export const webSocketContext = createContext<WebSocketType>({
collections: [],
Expand Down
2 changes: 1 addition & 1 deletion client/src/http/Milvus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
import BaseModel from './BaseModel';

export class MilvusHttp extends BaseModel {
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/collections/Collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import DropCollectionDialog from '../dialogs/DropCollectionDialog';
import RenameCollectionDialog from '../dialogs/RenameCollectionDialog';
import InsertDialog from '../dialogs/insert/Dialog';
import ImportSampleDialog from '../dialogs/ImportSampleDialog';
import { LOADING_STATE, WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
import { LOADING_STATE } from '@/consts';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
import { checkIndexBuilding, checkLoading } from '@/utils';
import Aliases from './Aliases';

Expand Down
8 changes: 2 additions & 6 deletions client/src/pages/overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ import dayjs from 'dayjs';
import { rootContext, webSocketContext, dataContext } from '@/context';
import EmptyCard from '@/components/cards/EmptyCard';
import icons from '@/components/icons/Icons';
import {
WS_EVENTS,
WS_EVENTS_TYPE,
LOADING_STATE,
MILVUS_DEPLOY_MODE,
} from '@/consts';
import { LOADING_STATE, MILVUS_DEPLOY_MODE } from '@/consts';
import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
import { useNavigationHook } from '@/hooks';
import { CollectionHttp, MilvusHttp } from '@/http';
import { ALL_ROUTER_TYPES } from '@/router/Types';
Expand Down
3 changes: 2 additions & 1 deletion client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
"@/*": ["src/*"],
"@server/*": ["../server/src/*"]
},
"allowJs": true,
"skipLibCheck": true,
Expand Down
2 changes: 2 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default defineConfig({
// extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
alias: {
'@': path.resolve(__dirname, './src'),
// be careful to include server modules in the client
'@server': path.resolve(__dirname, './../server/src'),
},
},
});
6 changes: 3 additions & 3 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import {
ErrorMiddleware,
ReqHeaderMiddleware,
} from './middleware';
import { EXPIRED_TIME, INSIGHT_CACHE } from './utils/Const';
import { EXPIRED_TIME, CACHE_KEY } from './utils';
import { getIp } from './utils/Network';
// initialize express app
export const app = express();

// initialize cache store
const insightCache = new LruCache({
const cache = new LruCache({
maxAge: EXPIRED_TIME,
updateAgeOnGet: true,
});
Expand All @@ -54,7 +54,7 @@ const server = http.createServer(app);
const PORT = 3000;
// setup middlewares
// use cache
app.set(INSIGHT_CACHE, insightCache);
app.set(CACHE_KEY, cache);
// use cors https://expressjs.com/en/resources/middleware/cors.html
app.use(cors());
// use helmet https://github.com/helmetjs/helmet
Expand Down
8 changes: 4 additions & 4 deletions server/src/collections/collections.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export class CollectionController {
);

// segments
this.router.get('/:name/psegments', this.getPSegement.bind(this));
this.router.get('/:name/qsegments', this.getQSegement.bind(this));
this.router.get('/:name/psegments', this.getPSegment.bind(this));
this.router.get('/:name/qsegments', this.getQSegment.bind(this));

this.router.put('/:name/compact', this.compact.bind(this));
return this.router;
Expand Down Expand Up @@ -335,7 +335,7 @@ export class CollectionController {
}
}

async getPSegement(req: Request, res: Response, next: NextFunction) {
async getPSegment(req: Request, res: Response, next: NextFunction) {
const name = req.params?.name;
try {
const result = await this.collectionsService.getPersistentSegmentInfo({
Expand All @@ -347,7 +347,7 @@ export class CollectionController {
}
}

async getQSegement(req: Request, res: Response, next: NextFunction) {
async getQSegment(req: Request, res: Response, next: NextFunction) {
const name = req.params?.name;
try {
const result = await this.collectionsService.getQuerySegmentInfo({
Expand Down
10 changes: 4 additions & 6 deletions server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import {
GePersistentSegmentInfoReq,
CompactReq,
} from '@zilliz/milvus2-sdk-node';
import { throwErrorFromSDK } from '../utils/Error';
import { findKeyValue, genRows } from '../utils/Helper';
import { ROW_COUNT } from '../utils/Const';
import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils';
import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';

export class CollectionsService {
constructor(private milvusService: MilvusService) {}
constructor(private milvusService: MilvusService) { }

async getCollections(data?: ShowCollectionsReq) {
const res = await this.milvusService.client.showCollections(data);
Expand Down Expand Up @@ -189,8 +187,8 @@ export class CollectionsService {
try {
replicas = loadCollection
? await this.getReplicas({
collectionID: collectionInfo.collectionID,
})
collectionID: collectionInfo.collectionID,
})
: replicas;
} catch (e) {
console.log('ignore getReplica');
Expand Down
Loading

0 comments on commit a8c9abf

Please sign in to comment.