Browse Source

Merge remote-tracking branch 'upstream/main' into feature/code-mode

tumao 3 years ago
parent
commit
ecc710b4a1

BIN
.github/images/screenshot.png


+ 1 - 1
client/src/components/menu/NavMenu.tsx

@@ -145,7 +145,7 @@ const useStyles = makeStyles((theme: Theme) =>
 const NavMenu: FC<NavMenuType> = props => {
   const { width, data, defaultActive = '' } = props;
   const classes = useStyles({ width });
-  const [expanded, setExpanded] = useState<boolean>(true);
+  const [expanded, setExpanded] = useState<boolean>(false);
   const [active, setActive] = useState<string>(defaultActive);
 
   const { t: commonTrans } = useTranslation();

+ 4 - 0
client/src/http/Collection.ts

@@ -110,6 +110,10 @@ export class CollectionHttp extends BaseModel implements CollectionView {
     return formatNumber(Number(this.rowCount));
   }
 
+  get _isLoaded() {
+    return this.isLoaded;
+  }
+
   get _status() {
     return this.isLoaded === true ? StatusEnum.loaded : StatusEnum.unloaded;
   }

+ 1 - 0
client/src/pages/collections/Types.ts

@@ -10,6 +10,7 @@ export interface CollectionData {
   _desc: string;
   _indexState: ChildrenStatusType;
   _fields?: FieldData[];
+  _isLoaded: boolean;
 }
 
 export interface CollectionView extends CollectionData {

+ 2 - 4
client/src/pages/overview/Overview.tsx

@@ -9,7 +9,6 @@ import { useLoadAndReleaseDialogHook } from '../../hooks/Dialog';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { CollectionHttp } from '../../http/Collection';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
-import { ShowCollectionsType } from '../../types/Milvus';
 import { formatNumber } from '../../utils/Common';
 import CollectionCard from './collectionCard/CollectionCard';
 import { CollectionData } from './collectionCard/Types';
@@ -49,9 +48,8 @@ const Overview = () => {
 
   const fetchData = useCallback(async () => {
     const res = await CollectionHttp.getStatistics();
-    const loadCollections = await CollectionHttp.getCollections({
-      type: ShowCollectionsType.InMemory,
-    });
+    const collections = await CollectionHttp.getCollections();
+    const loadCollections = collections.filter(c => c._isLoaded);
     setStatistics(res);
     setLoadCollections(loadCollections);
   }, []);

+ 3 - 3
server/generate-csv.ts

@@ -18,9 +18,9 @@ const generateVector = (dimension) => {
   return JSON.stringify(vectors);
 };
 
-while (records.length < 50000) {
-  const value = generateVector(4);
-  records.push({ vector: value, age: 10 });
+while (records.length < 5000) {
+  const value = generateVector(128);
+  records.push({ vector: value });
 }
 
 csvWriter

+ 2 - 0
server/package.json

@@ -37,6 +37,8 @@
     "cache-manager": "^3.4.4",
     "class-transformer": "^0.4.0",
     "class-validator": "^0.13.1",
+    "helmet": "^4.6.0",
+    "hyperlinker": "^1.0.0",
     "passport": "^0.4.1",
     "passport-jwt": "^4.0.0",
     "passport-local": "^1.0.0",

+ 34 - 33
server/src/collections/collections.controller.ts

@@ -9,12 +9,12 @@ import {
   Query,
   UsePipes,
   ValidationPipe,
-  CACHE_MANAGER,
-  Inject,
+  // CACHE_MANAGER,
+  // Inject,
   UseInterceptors,
   CacheInterceptor,
 } from '@nestjs/common';
-import { Cache } from 'cache-manager';
+// import { Cache } from 'cache-manager';
 import { ApiTags } from '@nestjs/swagger';
 import { CollectionsService } from './collections.service';
 import {
@@ -23,41 +23,43 @@ import {
   ShowCollections,
   VectorSearch,
 } from './dto';
-import { cacheKeys } from '../cache/config';
+// import { cacheKeys } from '../cache/config';
 
 //Including 2 kind of cache contorl, check getCollections and getStatistics for detail
 @ApiTags('collections')
 @Controller('collections')
 export class CollectionsController {
   constructor(
-    private collectionsService: CollectionsService,
-    @Inject(CACHE_MANAGER) private cacheManager: Cache,
+    private collectionsService: CollectionsService, // @Inject(CACHE_MANAGER) private cacheManager: Cache,
   ) {}
 
   // manually control cache if logic is complicated
   @Get()
   async getCollections(@Query() data?: ShowCollections) {
-    if (Number(data.type) === 1) {
-      let loadedCollections = await this.cacheManager.get(
-        cacheKeys.LOADEDCOLLECTIONS,
-      );
-      if (loadedCollections) {
-        return loadedCollections;
-      }
-      loadedCollections = await this.collectionsService.getLoadedColletions();
-      await this.cacheManager.set(
-        cacheKeys.LOADEDCOLLECTIONS,
-        loadedCollections,
-      );
-      return loadedCollections;
-    }
-    let allCollections = await this.cacheManager.get(cacheKeys.ALLCOLLECTIONS);
-    if (allCollections) {
-      return allCollections;
-    }
-    allCollections = await this.collectionsService.getAllCollections();
-    await this.cacheManager.set(cacheKeys.ALLCOLLECTIONS, allCollections);
-    return allCollections;
+    // if (Number(data.type) === 1) {
+    //   let loadedCollections = await this.cacheManager.get(
+    //     cacheKeys.LOADEDCOLLECTIONS,
+    //   );
+    //   if (loadedCollections) {
+    //     return loadedCollections;
+    //   }
+    //   loadedCollections = await this.collectionsService.getLoadedColletions();
+    //   await this.cacheManager.set(
+    //     cacheKeys.LOADEDCOLLECTIONS,
+    //     loadedCollections,
+    //   );
+    //   return loadedCollections;
+    // }
+    // let allCollections = await this.cacheManager.get(cacheKeys.ALLCOLLECTIONS);
+    // if (allCollections) {
+    //   return allCollections;
+    // }
+    // allCollections = await this.collectionsService.getAllCollections();
+    // await this.cacheManager.set(cacheKeys.ALLCOLLECTIONS, allCollections);
+    // return allCollections;
+    return Number(data.type === 1)
+      ? await this.collectionsService.getLoadedColletions()
+      : await this.collectionsService.getAllCollections();
   }
 
   // use interceptor to control cache automatically
@@ -70,14 +72,13 @@ export class CollectionsController {
   @Post()
   @UsePipes(new ValidationPipe())
   async createCollection(@Body() data: CreateCollection) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.createCollection(data);
   }
 
   @Delete(':name')
-  // todo: need check some special symbols
   async deleteCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.dropCollection({
       collection_name: name,
     });
@@ -104,7 +105,7 @@ export class CollectionsController {
 
   @Put(':name/load')
   async loadCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
     return await this.collectionsService.loadCollection({
       collection_name: name,
     });
@@ -112,7 +113,7 @@ export class CollectionsController {
 
   @Put(':name/release')
   async releaseCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
     return await this.collectionsService.releaseCollection({
       collection_name: name,
     });
@@ -120,7 +121,7 @@ export class CollectionsController {
 
   @Post(':name/insert')
   async insertData(@Param('name') name: string, @Body() data: InsertData) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.insert({
       collection_name: name,
       ...data,

+ 32 - 7
server/src/main.ts

@@ -1,26 +1,51 @@
+import * as helmet from 'helmet';
 import { NestFactory } from '@nestjs/core';
-import { Logger } from '@nestjs/common';
-
 import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
 import { AppModule } from './app.module';
 import { json } from 'body-parser';
+const hyperlinker = require('hyperlinker');
 
+/*
+  Milvus insight API server bootstrap function
+*/
 async function bootstrap() {
+  // by default the server will be listening on port 3000
   const port = 3000;
-  const app = await NestFactory.create(AppModule, {
-    cors: true,
-  });
+  // create the nest application with Cross-origin resource sharing
+  const app = await NestFactory.create(AppModule, { cors: true });
+  // security patches
+  app.use(helmet());
+  // set upload file size limit
+  app.use(json({ limit: '150mb' }));
+  // add an API prefix
   app.setGlobalPrefix('/api/v1');
 
+  // prepare swagger config
   const config = new DocumentBuilder()
     .setTitle('Milvus insight')
     .setVersion('1.0')
     .build();
+  // create swagger document
   const document = SwaggerModule.createDocument(app, config);
+  // set up API
   SwaggerModule.setup('api', app, document);
-  app.use(json({ limit: '150mb' }));
 
+  // start listening
   await app.listen(port);
-  Logger.log(`Milvus insight API server is running on port ${port}`);
+
+  // output server info
+  require('dns').lookup(require('os').hostname(), (err, add, fam) => {
+    // get link
+    // add = `127.0.0.1`;
+    const link = `http://${add}:${port}/api`;
+    const blue = `\x1b[34m%s\x1b[0m`;
+    const light = '\x1b[1m%s\x1b[0m';
+    console.log(blue, '\n    Milvus insight server started.');
+    console.log(
+      light,
+      `    View the API docs on ${hyperlinker(link, link)} \n`,
+    );
+  });
 }
+// Start the server
 bootstrap();

+ 10 - 0
server/yarn.lock

@@ -3132,6 +3132,11 @@ has@^1.0.3:
   dependencies:
     function-bind "^1.1.1"
 
+helmet@^4.6.0:
+  version "4.6.0"
+  resolved "https://registry.npmjs.org/helmet/-/helmet-4.6.0.tgz#579971196ba93c5978eb019e4e8ec0e50076b4df"
+  integrity sha512-HVqALKZlR95ROkrnesdhbbZJFi/rIVSoNq6f3jA/9u6MIbTsPh3xZwihjeI5+DO/2sOV6HMHooXcEOuwskHpTg==
+
 hosted-git-info@^2.1.4:
   version "2.8.9"
   resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
@@ -3193,6 +3198,11 @@ human-signals@^1.1.1:
   resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
   integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==
 
+hyperlinker@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.npmjs.org/hyperlinker/-/hyperlinker-1.0.0.tgz#23dc9e38a206b208ee49bc2d6c8ef47027df0c0e"
+  integrity sha512-Ty8UblRWFEcfSuIaajM34LdPXIhbs1ajEX/BBPv24J+enSVaEVY63xQ6lTO9VRYS5LAoghIG0IDJ+p+IPzKUQQ==
+
 iconv-lite@0.4.24, iconv-lite@^0.4.24:
   version "0.4.24"
   resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"