From 9a46c3dae63fc50ca24814aa3f958d9150eb0934 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 15:38:18 +0800 Subject: [PATCH 01/27] chore: update midway version --- packages/sandbox-mvp/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sandbox-mvp/package.json b/packages/sandbox-mvp/package.json index 702ee08..97aa642 100755 --- a/packages/sandbox-mvp/package.json +++ b/packages/sandbox-mvp/package.json @@ -5,7 +5,7 @@ "dependencies": { "chrome-devtools-frontend": "^1.0.590489", "egg-view-nunjucks": "^2.2.0", - "midway": "^0.3.7", + "midway": "^0.4.0", "sandbox-core": "^0.0.1" }, "devDependencies": { From cdaf389de67d4fd121b7a4c28c4a7cc6a4026e7c Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 16:46:15 +0800 Subject: [PATCH 02/27] chore: change config --- packages/sandbox-mvp/src/config/config.default.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/sandbox-mvp/src/config/config.default.ts b/packages/sandbox-mvp/src/config/config.default.ts index c93779d..5016b47 100644 --- a/packages/sandbox-mvp/src/config/config.default.ts +++ b/packages/sandbox-mvp/src/config/config.default.ts @@ -22,7 +22,7 @@ module.exports = appInfo => { port: 4242 }; - config.histore = { + config.dw = { host: process.env.UNDER_DOCKER ? 'mariadb-columnstore' : '127.0.0.1', port: 3306, username: 'sandbox', @@ -30,7 +30,7 @@ module.exports = appInfo => { database: 'column_sandbox', }; - config.mysql = { + config.coreDB = { host: process.env.UNDER_DOCKER ? 'mariadb-columnstore' : '127.0.0.1', port: 3306, username: 'sandbox', @@ -86,11 +86,11 @@ module.exports = appInfo => { }; config.customLogger = { - historeLogger: { - file: path.join(appInfo.root, `logs/sandbox-datasource-histore.log`) + dwLogger: { + file: path.join(appInfo.root, `logs/sandbox-datasource-dw.log`) }, - mysqlLogger: { - file: path.join(appInfo.root, `logs/sandbox-datasource-mysql.log`) + coreDBLogger: { + file: path.join(appInfo.root, `logs/sandbox-datasource-coredb.log`) } }; From bfc3fdb4beabc88b54c88f502853bc06a7bf91db Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 17:58:09 +0800 Subject: [PATCH 03/27] chore: update built-in assets version --- packages/sandbox-mvp/src/app/middleware/assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sandbox-mvp/src/app/middleware/assets.ts b/packages/sandbox-mvp/src/app/middleware/assets.ts index 742e746..2c63c09 100644 --- a/packages/sandbox-mvp/src/app/middleware/assets.ts +++ b/packages/sandbox-mvp/src/app/middleware/assets.ts @@ -1,6 +1,6 @@ export default function assets(options, app) { return async (ctx, next) => { - ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.5/'; + ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.6/'; ctx.locals.env = 'prod'; await next(); }; From b9ecc252531040c94f1c383391aa451307497c65 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 19:00:48 +0800 Subject: [PATCH 04/27] chore: use old version ws --- packages/sandbox-core/package.json | 2 +- packages/sandbox-core/src/core/debugServer/debugServer.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sandbox-core/package.json b/packages/sandbox-core/package.json index d48c9b6..00bf09f 100644 --- a/packages/sandbox-core/package.json +++ b/packages/sandbox-core/package.json @@ -13,7 +13,7 @@ "mysql2": "^1.5.3", "sequelize": "^4.39.0", "urllib": "^2.29.0", - "ws": "^6.0.0" + "ws": "^1.1.5" }, "devDependencies": { "@types/chai": "^4.1.4", diff --git a/packages/sandbox-core/src/core/debugServer/debugServer.ts b/packages/sandbox-core/src/core/debugServer/debugServer.ts index d7e154a..1b4aed3 100644 --- a/packages/sandbox-core/src/core/debugServer/debugServer.ts +++ b/packages/sandbox-core/src/core/debugServer/debugServer.ts @@ -36,12 +36,12 @@ export class DebugServer extends EventEmitter { try { - const url = request.url; + const upgradeReq = socket.upgradeReq; + const url = upgradeReq.url; if (!url.startsWith('/remoteDebug')) { socket.terminate(); return; } - socket.pause(); const query = QueryString.parse(Url.parse(url).query); const tokenRaw: string = query.token as any; From 6c2a63a28524c48ce5216c4fe362dd8a01a4ea7b Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 19:07:09 +0800 Subject: [PATCH 05/27] chore: update configs --- packages/sandbox-mvp/src/config/config.default.ts | 2 +- packages/sandbox-mvp/src/config/metrics.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/sandbox-mvp/src/config/config.default.ts b/packages/sandbox-mvp/src/config/config.default.ts index 5016b47..9a5d072 100644 --- a/packages/sandbox-mvp/src/config/config.default.ts +++ b/packages/sandbox-mvp/src/config/config.default.ts @@ -14,7 +14,7 @@ module.exports = appInfo => { }; config.pandora = { - restfulPort: 9081 + restfulPort: 7002 }; config.tsdb = { diff --git a/packages/sandbox-mvp/src/config/metrics.ts b/packages/sandbox-mvp/src/config/metrics.ts index 16024c6..450b9a1 100644 --- a/packages/sandbox-mvp/src/config/metrics.ts +++ b/packages/sandbox-mvp/src/config/metrics.ts @@ -5,8 +5,9 @@ import {focusLayout} from './metricsLayouts/focusLayout'; export const coreMetrics = { cpuUsage: { aggregator: 'avg', - metric: 'system.tsar.cpu', + metric: 'system.cpu.usage', affix: '%', + normalizedValue: true, }, load1: { aggregator: 'avg', From d262173f7517613ba5c6eacd933fa33ad9e90240 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Fri, 12 Oct 2018 19:21:23 +0800 Subject: [PATCH 06/27] chore: update configs --- packages/sandbox-mvp/src/config/metrics.ts | 6 +++-- .../src/config/metricsLayouts/focusLayout.ts | 25 +++++++------------ .../src/config/metricsLayouts/systemLayout.ts | 22 ++++++++-------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/packages/sandbox-mvp/src/config/metrics.ts b/packages/sandbox-mvp/src/config/metrics.ts index 450b9a1..0691ce7 100644 --- a/packages/sandbox-mvp/src/config/metrics.ts +++ b/packages/sandbox-mvp/src/config/metrics.ts @@ -15,13 +15,15 @@ export const coreMetrics = { }, memUsage: { aggregator: 'avg', - metric: 'system.tsar.mem', + metric: 'system.mem.usage', affix: '%', + normalizedValue: true, }, diskUsage: { aggregator: 'avg', - metric: 'system.tsar.df', + metric: 'system.disk.partition.used_ratio', affix: '%', + normalizedValue: true, }, qps: { aggregator: 'sum', diff --git a/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts b/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts index abb92a4..65328c3 100644 --- a/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts +++ b/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts @@ -47,21 +47,18 @@ export const focusLayout = [{ aggregator: 'avg', metric: 'system.load.1min', title: 'Load 1', - type: 'number', }, { aggregator: 'avg', metric: 'system.load.5min', title: 'Load 5', - type: 'number', }, { aggregator: 'avg', metric: 'system.load.15min', title: 'Load 15', - type: 'number', }, ], @@ -73,7 +70,6 @@ export const focusLayout = [{ aggregator: 'sum', metric: 'error.all.bucket_count', title: '错误数量', - type: 'number', unit: '条', }, @@ -84,11 +80,10 @@ export const focusLayout = [{ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.cpu', + metric: 'system.cpu.usage', title: 'CPU 使用率', - type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -97,11 +92,10 @@ export const focusLayout = [{ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.mem', + metric: 'system.mem.usage', title: '内存使用率', - type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -110,11 +104,10 @@ export const focusLayout = [{ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.df', + metric: 'system.disk.partition.used_ratio', title: '磁盘占用率', - type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -126,7 +119,7 @@ export const focusLayout = [{ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.ifin', + metric: 'system.nettraffic.eth0.net.in.bytes', unit: 'Bytes/ms', title: 'eth0 流入', @@ -134,7 +127,7 @@ export const focusLayout = [{ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.ifout', + metric: 'system.nettraffic.eth0.net.out.bytes', unit: 'Bytes/ms', title: 'eth0 流出', @@ -146,7 +139,7 @@ export const focusLayout = [{ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.tcp_retry', + metric: 'system.tcp.retry.rate', title: '重试率', type: 'percent', diff --git a/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts b/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts index b0591ba..b62b725 100644 --- a/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts +++ b/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts @@ -40,10 +40,10 @@ export const systemLayout = [ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.cpu', + metric: 'system.cpu.usage', title: 'CPU 使用率', type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -52,10 +52,10 @@ export const systemLayout = [ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.mem', + metric: 'system.mem.usage', title: '内存使用率', type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -64,10 +64,10 @@ export const systemLayout = [ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.df', + metric: 'system.disk.partition.used_ratio', title: '磁盘占用率', type: 'percent', - normalizedValue: false, + normalizedValue: true, }, ], }, @@ -77,7 +77,7 @@ export const systemLayout = [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.ifin', + metric: 'system.nettraffic.eth0.net.in.bytes', unit: 'Bytes/ms', title: 'eth0 流入', }, @@ -89,7 +89,7 @@ export const systemLayout = [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.ifout', + metric: 'system.nettraffic.eth0.net.out.bytes', unit: 'Bytes/ms', title: 'eth0 流出', }, @@ -101,7 +101,7 @@ export const systemLayout = [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.pktin', + metric: 'system.nettraffic.eth0.net.in.packets', unit: '', title: '入包', }, @@ -113,7 +113,7 @@ export const systemLayout = [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.pktout', + metric: 'system.nettraffic.eth0.net.out.packets', unit: '', title: '出包', }, @@ -124,7 +124,7 @@ export const systemLayout = [ indicators: [ { aggregator: 'avg', - metric: 'system.tsar.tcp_retry', + metric: 'system.tcp.retry.rate', title: '重试率', type: 'percent', normalizedValue: false, From d4b8420c4c11cd1e41e604a40ee134795416e63d Mon Sep 17 00:00:00 2001 From: GuangWong Date: Sat, 13 Oct 2018 12:21:43 +0800 Subject: [PATCH 07/27] fix: fix wrong mode config --- .../core/model/dw/sandboxGalaxySlsTraces.ts | 62 ++++++------------- .../sandbox-mvp/src/app/middleware/assets.ts | 2 +- 2 files changed, 19 insertions(+), 45 deletions(-) diff --git a/packages/sandbox-core/src/core/model/dw/sandboxGalaxySlsTraces.ts b/packages/sandbox-core/src/core/model/dw/sandboxGalaxySlsTraces.ts index 6aa94a1..52a4cb9 100644 --- a/packages/sandbox-core/src/core/model/dw/sandboxGalaxySlsTraces.ts +++ b/packages/sandbox-core/src/core/model/dw/sandboxGalaxySlsTraces.ts @@ -41,65 +41,39 @@ export async function factory(context: IApplicationContext) { type: Sequelize.TEXT, field: 'trace_name', }, + traceSpans: { + type: Sequelize.TEXT, + field: 'trace_spans', + }, traceId: { type: Sequelize.STRING(256), field: 'trace_id', }, - uuid: { - type: Sequelize.STRING(256), - allowNull: false, - }, - spanName: { - type: Sequelize.STRING(512), - field: 'span_name', - }, - spanTimestamp: { - type: Sequelize.STRING(128), - field: 'span_timestamp', - }, - spanDuration: { + traceDuration: { type: Sequelize.INTEGER, - field: 'span_duration', - }, - spanError: { - type: Sequelize.INTEGER(4), - allowNull: true, - defaultValue: 0, - field: 'span_error', + field: 'trace_duration', }, - spanType: { + traceStatus: { type: Sequelize.INTEGER, - field: 'span_type', - }, - spanMethod: { - type: Sequelize.STRING(128), - field: 'span_method', - }, - spanTarget: { - type: Sequelize.TEXT, - field: 'span_target', + field: 'trace_status', + defaultValue: 1, }, - spanCode: { - type: Sequelize.STRING(128), - field: 'span_code', - }, - spanTags: { - type: Sequelize.TEXT, - field: 'span_tags', + uuid: { + type: Sequelize.STRING(256), + allowNull: false, }, - spanId: { - type: Sequelize.STRING(128), - field: 'span_id', + unixTimestamp: { + type: Sequelize.BIGINT, + field: 'unix_timestamp', }, - spanRpcId: { - type: Sequelize.STRING(128), - field: 'span_rpcid', + version: { + type: Sequelize.INTEGER, }, }, { timestamps: false, underscored: false, freezeTableName: true, - tableName: 'sandbox_galaxy_sls_trace_nodes', + tableName: 'sandbox_galaxy_sls_traces', }); SLSTraceModel.removeAttribute('id'); diff --git a/packages/sandbox-mvp/src/app/middleware/assets.ts b/packages/sandbox-mvp/src/app/middleware/assets.ts index 2c63c09..6806eb8 100644 --- a/packages/sandbox-mvp/src/app/middleware/assets.ts +++ b/packages/sandbox-mvp/src/app/middleware/assets.ts @@ -1,6 +1,6 @@ export default function assets(options, app) { return async (ctx, next) => { - ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.6/'; + ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.7/'; ctx.locals.env = 'prod'; await next(); }; From 7650866cd2ad8a1c1af5f80dc3637d0ef489aed0 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Mon, 15 Oct 2018 16:53:59 +0800 Subject: [PATCH 08/27] v0.0.2 --- lerna.json | 2 +- packages/sandbox-core/package.json | 2 +- packages/sandbox-mvp/package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 99ebddc..0be8f18 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "0.0.1" + "version": "0.0.2" } diff --git a/packages/sandbox-core/package.json b/packages/sandbox-core/package.json index 00bf09f..ef22a36 100644 --- a/packages/sandbox-core/package.json +++ b/packages/sandbox-core/package.json @@ -1,6 +1,6 @@ { "name": "sandbox-core", - "version": "0.0.1", + "version": "0.0.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "dependencies": { diff --git a/packages/sandbox-mvp/package.json b/packages/sandbox-mvp/package.json index 97aa642..086aa32 100755 --- a/packages/sandbox-mvp/package.json +++ b/packages/sandbox-mvp/package.json @@ -1,12 +1,12 @@ { "name": "sandbox-mvp", - "version": "0.0.1", + "version": "0.0.2", "description": "MVP version of sandbox", "dependencies": { "chrome-devtools-frontend": "^1.0.590489", "egg-view-nunjucks": "^2.2.0", "midway": "^0.4.0", - "sandbox-core": "^0.0.1" + "sandbox-core": "^0.0.2" }, "devDependencies": { "@types/mocha": "^5.2.5", From ef4f781c97a03ec0c83f6cc21ccca0066beed6ca Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 11:36:23 +0800 Subject: [PATCH 09/27] test: add run cov --- .travis.yml | 4 ++-- package.json | 4 +++- packages/sandbox-core/package.json | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c34937d..af1d451 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - npm i - npm i codecov before_script: - - lerna bootstrap --no-ci - - lerna run build + - npm run bootstrap + - npm run build script: - npm run cov diff --git a/package.json b/package.json index 5d0970e..a92607a 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,8 @@ "lerna": "^3.4.0" }, "scripts": { - "build": "lerna run build" + "bootstrap": "lerna bootstrap --no-ci", + "build": "lerna run build", + "cov": "lerna run cov" } } diff --git a/packages/sandbox-core/package.json b/packages/sandbox-core/package.json index ef22a36..c7df0a6 100644 --- a/packages/sandbox-core/package.json +++ b/packages/sandbox-core/package.json @@ -38,7 +38,8 @@ "prepublishOnly": "npm run build", "lint": "tslint --fix -p .", "build": "npm run lint && rm -rf ./dist && tsc", - "test": "midway-bin test --ts" + "test": "midway-bin test --ts", + "cov": "midway-bin cov --ts" }, "files": [ "dist", From 3fa8c0d84eea7553ca0d91f37fa8fb0ec9945e30 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 11:46:31 +0800 Subject: [PATCH 10/27] test: use blank password --- packages/sandbox-core/test/fixtures/config.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/sandbox-core/test/fixtures/config.ts b/packages/sandbox-core/test/fixtures/config.ts index ea224fc..9c9614c 100644 --- a/packages/sandbox-core/test/fixtures/config.ts +++ b/packages/sandbox-core/test/fixtures/config.ts @@ -3,7 +3,6 @@ export default { host: '127.0.0.1', username: 'root', port: 3306, - password: '123456', encrypt: false, database: 'sandbox', }, @@ -11,7 +10,6 @@ export default { host: '127.0.0.1', username: 'root', port: 3306, - password: '123456', encrypt: false, database: 'sandbox', }, From 5e5f1d2f9d34e87f04071d9f923e17046634beea Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 11:55:56 +0800 Subject: [PATCH 11/27] test: init db --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index af1d451..82d00d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: node_js -services: - - mysql node_js: - "8" - "9" - "10" +services: + - mysql +before_install: + - sudo mysql < ./packages/sandbox-core/test/fixtures/sql/initDB.sql 2>&1 install: - npm i - npm i codecov From 2dec4d45c27d359b43727c2a9949eb97774765d8 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 15:29:03 +0800 Subject: [PATCH 12/27] test: fix test issue --- packages/sandbox-core/src/core/manager/errorManager.ts | 8 ++++++-- .../sandbox-core/test/core/service/errorService.test.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/sandbox-core/src/core/manager/errorManager.ts b/packages/sandbox-core/src/core/manager/errorManager.ts index ec58dc2..0f5406c 100644 --- a/packages/sandbox-core/src/core/manager/errorManager.ts +++ b/packages/sandbox-core/src/core/manager/errorManager.ts @@ -121,6 +121,7 @@ export class ErrorManager { attributes: [['log_path', 'path']], where: { [Sequelize.Op.and]: required }, group: ['path'], + raw: true, }; return this.errorModel.findAll(conditions); } @@ -133,20 +134,23 @@ export class ErrorManager { ], where: { [Sequelize.Op.and]: required }, group: ['errType'], + raw: true, }; return this.errorModel.findAll(conditions); } private findErrorTypeDist(required: object[]) { + const downSampling = Sequelize.literal('(unix_timestamp - unix_timestamp % 60)'); const conditions: SearchCondition = { attributes: [ ['error_type', 'errType'], [Sequelize.fn('COUNT', Sequelize.literal('*')), 'cnt'], - [Sequelize.literal('(unix_timestamp - unix_timestamp % 60)'), 'timestamp'], + [downSampling, 'timestamp'], ], where: { [Sequelize.Op.and]: required }, - group: ['timestamp', 'errType'], + group: [downSampling, 'errType'], order: [['timestamp', 'DESC']], + raw: true, }; return this.errorModel.findAll(conditions); } diff --git a/packages/sandbox-core/test/core/service/errorService.test.ts b/packages/sandbox-core/test/core/service/errorService.test.ts index 9f853c0..f410e0b 100644 --- a/packages/sandbox-core/test/core/service/errorService.test.ts +++ b/packages/sandbox-core/test/core/service/errorService.test.ts @@ -38,6 +38,7 @@ describe('errorServiceTest', () => { }); assert(res[0].length === 2); assert(res[1].length === 2); + assert(res[1].some((data) => data.errType === 'RangeError' && data.cnt === 2)); assert(res[1].some((data) => data.errType === 'ReferenceError' && data.cnt === 1)); assert(res[2].length === 2); From bae7b8ebfc92a725481d59caee1187f6c734aca3 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 15:41:58 +0800 Subject: [PATCH 13/27] chore: add code cov --- .gitignore | 1 + .travis.yml | 2 ++ package.json | 3 ++- scripts/cov.sh | 12 ++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 scripts/cov.sh diff --git a/.gitignore b/.gitignore index a7039f8..883b4b2 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,7 @@ assembly/ mocks_data/proxy/**/__* tms coverage +.nyc_output ############################ # visual studio code settings diff --git a/.travis.yml b/.travis.yml index 82d00d9..cd4eda1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,5 @@ before_script: - npm run build script: - npm run cov +after_script: + - codecov diff --git a/package.json b/package.json index a92607a..31aad74 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "sandbox", "private": true, "devDependencies": { + "nyc": "^11.2.1", "git-hooks": "^1.1.10", "lerna": "^3.4.0" }, "scripts": { "bootstrap": "lerna bootstrap --no-ci", "build": "lerna run build", - "cov": "lerna run cov" + "cov": "sh scripts/cov.sh" } } diff --git a/scripts/cov.sh b/scripts/cov.sh new file mode 100644 index 0000000..9197b69 --- /dev/null +++ b/scripts/cov.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e +lerna run cov +cwd=`pwd` +if [ -d "${cwd}/.nyc_output" ]; then + rm -rf "${cwd}/.nyc_output" +fi +mkdir "${cwd}/.nyc_output" +cp -r ./packages/*/.nyc_output/* $cwd/.nyc_output/ || true +cp -r ./packages/*/node_modules/.nyc_output/* $cwd/.nyc_output/ || true +./node_modules/.bin/nyc report + From 981ba7e24e37851733d3204623e0a465fca35b58 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 15:56:20 +0800 Subject: [PATCH 14/27] chore: add more test cov reporter --- package.json | 8 ++++++++ .../test/app/controller/applicationCtrl.test.ts | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 packages/sandbox-mvp/test/app/controller/applicationCtrl.test.ts diff --git a/package.json b/package.json index 31aad74..cc36b77 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,14 @@ "git-hooks": "^1.1.10", "lerna": "^3.4.0" }, + "nyc": { + "reporter": [ + "text", + "json", + "html", + "lcovonly" + ] + }, "scripts": { "bootstrap": "lerna bootstrap --no-ci", "build": "lerna run build", diff --git a/packages/sandbox-mvp/test/app/controller/applicationCtrl.test.ts b/packages/sandbox-mvp/test/app/controller/applicationCtrl.test.ts new file mode 100644 index 0000000..63cd3ed --- /dev/null +++ b/packages/sandbox-mvp/test/app/controller/applicationCtrl.test.ts @@ -0,0 +1,9 @@ +import {ApplicationCtrl} from '../../../src/app/controller/applicationCtrl'; +import * as core from 'sandbox-core'; +import * as assert from 'assert'; +describe('applicationCtrl', () => { + it('should inherit from sandbox-core', () => { + const myApplicationCtrl = new ApplicationCtrl(); + assert(myApplicationCtrl instanceof core.ApplicationCtrl); + }); +}); From a9675f90eefaabf68536e1824a0a31ff7d82e0b8 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 15:57:02 +0800 Subject: [PATCH 15/27] chore: mark hook executable --- .githooks/pre-commit/filter.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .githooks/pre-commit/filter.sh diff --git a/.githooks/pre-commit/filter.sh b/.githooks/pre-commit/filter.sh old mode 100644 new mode 100755 From c9b54fc3651773fb104c1018743fdc5059682bc6 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 16 Oct 2018 16:12:34 +0800 Subject: [PATCH 16/27] chore: update cov.sh --- scripts/cov.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/cov.sh b/scripts/cov.sh index 9197b69..f416a70 100644 --- a/scripts/cov.sh +++ b/scripts/cov.sh @@ -1,12 +1,9 @@ #!/bin/bash set -e -lerna run cov cwd=`pwd` -if [ -d "${cwd}/.nyc_output" ]; then - rm -rf "${cwd}/.nyc_output" -fi +lerna run cov +rm -rf "${cwd}/.nyc_output" || true mkdir "${cwd}/.nyc_output" cp -r ./packages/*/.nyc_output/* $cwd/.nyc_output/ || true cp -r ./packages/*/node_modules/.nyc_output/* $cwd/.nyc_output/ || true ./node_modules/.bin/nyc report - From bcbbfc3c0cd9ffe04345521bef6855188e688c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=94=E5=BF=9E?= Date: Mon, 22 Oct 2018 11:34:32 +0800 Subject: [PATCH 17/27] test: add test cases --- .../test/core/manager/traceManager.test.ts | 87 +++ .../core/manager/traceNodeManager.test.ts | 74 +++ .../core/service/applicationService.test.ts | 37 +- .../test/core/service/errorService.test.ts | 28 +- .../core/service/remoteDebugService.test.ts | 20 + .../test/core/service/traceService.test.ts | 540 +++++++++++++++++- .../fixtures/injections/privilegeAdapter.ts | 3 + .../test/fixtures/mockData/traceMockData.ts | 104 ++-- 8 files changed, 843 insertions(+), 50 deletions(-) create mode 100644 packages/sandbox-core/test/core/manager/traceManager.test.ts create mode 100644 packages/sandbox-core/test/core/manager/traceNodeManager.test.ts diff --git a/packages/sandbox-core/test/core/manager/traceManager.test.ts b/packages/sandbox-core/test/core/manager/traceManager.test.ts new file mode 100644 index 0000000..2f85743 --- /dev/null +++ b/packages/sandbox-core/test/core/manager/traceManager.test.ts @@ -0,0 +1,87 @@ +import { getInstance } from '../../helper'; +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import traceMockData from '../../fixtures/mockData/traceMockData'; +import keyTraceMockData from '../../fixtures/mockData/keyTraceMockData'; + +describe('test/core/manager/traceManager.test.ts', () => { + before(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.bulkCreate(keyTraceMockData); + const traceModel = await getInstance('traceModel'); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); + }); + + it('traceSummaryList', async () => { + const traceManager = await getInstance('traceManager'); + const res = await traceManager.traceSummaryList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + }, { + order: 'env', + limit: 10, + offset: 10, + }); + assert(res.length === 0); + }); + + it('listTraceByName', async () => { + const traceManager = await getInstance('traceManager'); + let res = await traceManager.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }, { + attributes: ['scope', 'scopeName'], + order: 'timestamp,desc|traceDuration,asc', + limit: 10, + offset: 10, + }); + assert(res.count === 1 && res.rows.length === 0); + + res = await traceManager.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }, {}); + assert(res.count === 1 && res.rows.length === 1); + }); + + after(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.destroy({ + where: { + traceName: { + [Op.in]: keyTraceMockData.map((kt) => kt.traceName), + }, + }, + }); + const traceModel = await getInstance('traceModel'); + await traceModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), + }, + }, + }); + }); + +}); diff --git a/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts b/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts new file mode 100644 index 0000000..051b2b7 --- /dev/null +++ b/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts @@ -0,0 +1,74 @@ +import { getInstance } from '../../helper'; +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import traceMockData from '../../fixtures/mockData/traceMockData'; +import keyTraceMockData from '../../fixtures/mockData/keyTraceMockData'; + +describe('traceNodeManager', () => { + before(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.bulkCreate(keyTraceMockData); + const traceModel = await getInstance('traceModel'); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); + }); + + it('listNodesByTarget', async () => { + const traceManager = await getInstance('traceNodeManager'); + let res = await traceManager.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + spanName: 'configs', + spanTarget: '/', + }, { + attributes: ['scope', 'scopeName'], + order: 'timestamp,desc|spanCode,asc', + limit: 10, + offset: 10, + }); + assert(res.count === 1 && res.rows.length === 0); + + res = await traceManager.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + spanName: 'configs', + spanTarget: '/', + }, {}); + assert(res.count === 1 && res.rows.length === 1); + }); + + after(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.destroy({ + where: { + traceName: { + [Op.in]: keyTraceMockData.map((kt) => kt.traceName), + }, + }, + }); + const traceModel = await getInstance('traceModel'); + await traceModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), + }, + }, + }); + }); + +}); diff --git a/packages/sandbox-core/test/core/service/applicationService.test.ts b/packages/sandbox-core/test/core/service/applicationService.test.ts index f135aaa..ed83537 100644 --- a/packages/sandbox-core/test/core/service/applicationService.test.ts +++ b/packages/sandbox-core/test/core/service/applicationService.test.ts @@ -22,13 +22,6 @@ describe('applicationServiceTest', () => { assert(xor(res.data.map((app) => app.flag), applicationMockData.map((app) => app.flag)).length === 0); }); - it('queryGroups', async () => { - const appService = await getInstance('applicationService'); - const res = await appService.queryGroups({ scope: 'test', scopeName: 'sandbox-test' }); - assert(res); - assert(isEqual(res.dev, defaultPlatformHostsMockData.dev)); - }); - it('queryHosts', async () => { const appService = await getInstance('applicationService'); const res = await appService.queryHosts({ env: 'dev', scope: 'test'}); @@ -41,13 +34,41 @@ describe('applicationServiceTest', () => { const appService = await getInstance('applicationService'); const res = await appService.groupUpsert({ groupName: 'test_group', - hostList: [], + hostList: [{ip: '10.0.0.1', hostname: 'devServer'}], scope: 'test', scopeName: 'sandbox-test', }); assert(res === true); }); + it('queryGroups', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.queryGroups({ scope: 'test', scopeName: 'sandbox-test' }); + assert(res); + assert(isEqual(res.dev, defaultPlatformHostsMockData.dev)); + }); + + it('groupUpsert with empty host list', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.groupUpsert({ + groupName: 'test_group_no_host', + hostList: null, + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(typeof res === 'boolean'); + }); + + it('groupExist', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.groupExist({ + groupName: 'test_group', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res === 1); + }); + it('groupDelete', async () => { const appService = await getInstance('applicationService'); const res = await appService.groupDelete({ diff --git a/packages/sandbox-core/test/core/service/errorService.test.ts b/packages/sandbox-core/test/core/service/errorService.test.ts index f410e0b..dcdfcef 100644 --- a/packages/sandbox-core/test/core/service/errorService.test.ts +++ b/packages/sandbox-core/test/core/service/errorService.test.ts @@ -12,7 +12,7 @@ describe('errorServiceTest', () => { it('queryErrors', async () => { const errorService = await getInstance('errorService'); - const res = await errorService.queryErrors({ + const baseOptions = { startTime: new Date('2018-09-20 00:00:00'), endTime: new Date('2018-09-20 03:00:00'), scope: 'test', @@ -20,9 +20,33 @@ describe('errorServiceTest', () => { env: 'dev', page: 1, pageSize: 10, - }); + }; + let res = await errorService.queryErrors(baseOptions); assert(res.count === 3 && res.rows.length === 3); assert(xor(res.rows.map((row) => row.uuid), errorMockData.map((data) => data.uuid)).length === 0); + + res = await errorService.queryErrors({ + ip: '192.168.1.1', + errType: ['RangeError'], + keyword: '483d9c50-c303-11e8-a355-529269fb1459', + in: 'traceId', ...baseOptions}); + assert(res.count === 1 && res.rows.length === 1); + assert(res.rows[0].traceId === '483d9c50-c303-11e8-a355-529269fb1459'); + + res = await errorService.queryErrors({ + keyword: 'RangeError', + in: 'errorType', ...baseOptions}); + assert(res.count === 2 && res.rows.length === 2); + assert(res.rows.every((row) => row.errorType === 'RangeError')); + + res = await errorService.queryErrors({ + keyword: '192.168.1.2', + in: 'machine', ...baseOptions}); + assert(res.count === 0 && res.rows.length === 0); + + res = await errorService.queryErrors({ + keyword: 'emitTwo', ...baseOptions}); + assert(res.count === 3 && res.rows.length === 3); }); it('queryErrorTypes', async () => { diff --git a/packages/sandbox-core/test/core/service/remoteDebugService.test.ts b/packages/sandbox-core/test/core/service/remoteDebugService.test.ts index 76de6f8..53bf29d 100644 --- a/packages/sandbox-core/test/core/service/remoteDebugService.test.ts +++ b/packages/sandbox-core/test/core/service/remoteDebugService.test.ts @@ -15,4 +15,24 @@ describe('remoteDebugServiceTest', () => { assert(res.every((d) => d.debugPort && d.webSocketDebuggerUrl && d.token)); }); + it('getDebuggableHost without permission', async () => { + const remoteDebugService = await getInstance('remoteDebugService'); + let throwError = false; + try { + await remoteDebugService.getDebuggableHost({ + scope: 'test', + scopeName: 'noPermission', + uid: '1001', + ip: '127.0.0.1', + }); + } catch (err) { + if (err.message.match(/no permission/)) { + throwError = true; + } else { + throw err; + } + } + assert(throwError); + }); + }); diff --git a/packages/sandbox-core/test/core/service/traceService.test.ts b/packages/sandbox-core/test/core/service/traceService.test.ts index 7a37f73..27f81ec 100644 --- a/packages/sandbox-core/test/core/service/traceService.test.ts +++ b/packages/sandbox-core/test/core/service/traceService.test.ts @@ -10,7 +10,9 @@ describe('traceServiceTest', async () => { const keyTraceModel = await getInstance('keyTraceModel'); await keyTraceModel.bulkCreate(keyTraceMockData); const traceModel = await getInstance('traceModel'); - await traceModel.bulkCreate(traceMockData); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); }); it('listFocusTraces', async () => { @@ -19,18 +21,540 @@ describe('traceServiceTest', async () => { scope: 'test', scopeName: 'sandbox-test', }); - assert(res); + assert(res.data.length === traceMockData.traces.length); }); it('listTraces', async () => { const traceService = await getInstance('traceService'); - const res = await traceService.listTraces({ + let res = await traceService.listTraces({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + }); + assert(res.data.length === traceMockData.traces.length); + + res = await traceService.listTraces({ + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + }); + assert(res.data.length >= 0); + + res = await traceService.listTraces({ + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length >= 0); + }); + + it('traceDetail', async () => { + const traceService = await getInstance('traceService'); + const testUUID = '3e351e0f-9abd-4023-8a2a-061dc3cacffc'; + let res = await traceService.traceDetail({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + uuid: testUUID, + }); + assert(res && res.uuid === testUUID); + + res = await traceService.traceDetail({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + uuid: testUUID, + }); + assert(res && res.uuid === testUUID); + }); + + it('toggleTraceFocus', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.toggleTraceFocus({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 1, + }); + assert(typeof res === 'boolean'); + }); + + it('toggleTraceFocus cancel', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.toggleTraceFocus({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(typeof res === 'boolean'); + }); + + it('traceTotalitySummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + + res = await traceService.traceTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + + res = await traceService.traceTotalitySummary({ startTime: new Date('2018-09-28 01:00:00'), endTime: new Date('2018-09-28 01:30:00'), scope: 'test', scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', }); assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + }); + + it('spanTotalitySummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + + res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + + res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + }); + + it('traceSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + hostname: 'develop.server', + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + ip: '10.0.0.1', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === 0); + }); + + it('listTraceByName', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + hostname: 'develop.server', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === traceMockData.traces.length); + + res = await traceService.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + + res = await traceService.listTraceByName({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 0); + }); + + it('traceSummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceSummary({ + scope: 'test', + scopeName: 'sandbox-test-not-exist', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + }); + + it('traceNodeSummaryList', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummaryList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + + res = await traceService.traceNodeSummaryList({ + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + + res = await traceService.traceNodeSummaryList({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + }); + + it('traceNodeSummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceNodeSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceNodeSummary({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.length >= 0); + }); + + it('traceNodeSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceNodeSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceNodeSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 0); + }); + + it('spanTargetList', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTargetList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length > 0); + assert(res.data.every((val) => typeof val[0] === 'string' && typeof val[1] === 'number')); + + res = await traceService.spanTargetList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length > 0); + assert(res.data.every((val) => typeof val[0] === 'string' && typeof val[1] === 'number')); + + res = await traceService.spanTargetList({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + }); + assert(res.data.length === 0); + }); + + it('spanTargetSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTargetSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.spanTargetSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.spanTargetSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + spanTarget: '/', + }); + assert(res.data.length === 0); + }); + + it('listNodesByTarget', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + + res = await traceService.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + + res = await traceService.listNodesByTarget({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + spanTarget: '/', + }); + assert(res.data.length === 0); + }); + + it('spansSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + + res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + + res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + }); + + it('traceFlowHistogram', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.traceFlowHistogram({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 2); }); after(async () => { @@ -46,7 +570,15 @@ describe('traceServiceTest', async () => { await traceModel.destroy({ where: { uuid: { - [Op.in]: traceMockData.map((tr) => tr.uuid), + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), }, }, }); diff --git a/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts b/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts index 1d23572..2cd6576 100644 --- a/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts +++ b/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts @@ -3,6 +3,9 @@ import { provide } from 'midway-mirror'; @provide('privilegeAdapter') export class PrivilegeAdapter { async isAppOps(scope: string, scopeName: string, uid: string): Promise { + if (scopeName === 'noPermission') { + return false; + } return true; } } diff --git a/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts b/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts index 720f670..68be9ad 100644 --- a/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts +++ b/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts @@ -1,36 +1,68 @@ -export default [ - { - timestamp: new Date('2018-09-28 01:13:34'), - scope: 'test', - scopeName: 'sandbox-test', - env: 'dev', - hostname: 'develop.server', - ip: '10.0.0.1', - uuid: '0f7ea820-3fb2-4496-b755-ca5bd76763bd', - traceId: '0b859a6d15381252001705791e067a', - version: 1, - traceSpans: '[]', - unix_timestamp: 1538068414, - trace_duration: 3, - pid: 4328, - traceName: 'HTTP-GET:/', - traceStatus: 1, - }, - { - timestamp: new Date('2018-09-28 01:13:35'), - scope: 'test', - scopeName: 'sandbox-test', - env: 'dev', - hostname: 'develop.server', - ip: '10.0.0.1', - uuid: '3e351e0f-9abd-4023-8a2a-061dc3cacffc', - traceId: '0b859a6d153091a2001705791e067a', - version: 1, - traceSpans: '[]', - unix_timestamp: 1538068415, - trace_duration: 2, - pid: 4928, - traceName: 'HTTP-GET:/products', - traceStatus: 1, - }, -]; +export default { + traces: [ + { + timestamp: new Date('2018-09-28 01:13:34'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '0f7ea820-3fb2-4496-b755-ca5bd76763bd', + traceId: '0b859a6d15381252001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068414, + traceDuration: 3, + pid: 4328, + traceName: 'HTTP-GET:/', + traceStatus: 1, + }, + { + timestamp: new Date('2018-09-28 01:13:35'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '3e351e0f-9abd-4023-8a2a-061dc3cacffc', + traceId: '0b859a6d153091a2001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068415, + traceDuration: 2, + pid: 4928, + traceName: 'HTTP-GET:/products', + traceStatus: 1, + }, + ], + traceNodes: [ + { + timestamp: new Date('2018-09-28 01:13:35'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '3e351e0f-9abd-4023-8a2a-061dd3cacffc', + traceId: '0b859a6d153091a2001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068415, + traceDuration: 2, + traceName: 'HTTP-GET:/products', + traceStatus: 1, + spanName: 'configs', + spanDuration: 142, + spanType: 0, + spanTags: '{}', + spanId: 'eb26f0605ab77a93', + spanRpcId: '0.1.1.0', + spanCode: 200, + spanError: 0, + spanMethod: 'GET', + spanTimestamp: '2018-09-28 01:13:35', + pid: 2045, + spanTarget: '/', + }, + ], +}; From e505cfaf8e215cc3715e8d8b81343d6114dfb8c4 Mon Sep 17 00:00:00 2001 From: Chunlin-Li Date: Mon, 22 Oct 2018 11:57:04 +0800 Subject: [PATCH 18/27] test: add test cases --- .../test/core/manager/traceManager.test.ts | 87 +++ .../core/manager/traceNodeManager.test.ts | 74 +++ .../core/service/applicationService.test.ts | 37 +- .../test/core/service/errorService.test.ts | 28 +- .../core/service/remoteDebugService.test.ts | 20 + .../test/core/service/traceService.test.ts | 540 +++++++++++++++++- .../fixtures/injections/privilegeAdapter.ts | 3 + .../test/fixtures/mockData/traceMockData.ts | 104 ++-- 8 files changed, 843 insertions(+), 50 deletions(-) create mode 100644 packages/sandbox-core/test/core/manager/traceManager.test.ts create mode 100644 packages/sandbox-core/test/core/manager/traceNodeManager.test.ts diff --git a/packages/sandbox-core/test/core/manager/traceManager.test.ts b/packages/sandbox-core/test/core/manager/traceManager.test.ts new file mode 100644 index 0000000..2f85743 --- /dev/null +++ b/packages/sandbox-core/test/core/manager/traceManager.test.ts @@ -0,0 +1,87 @@ +import { getInstance } from '../../helper'; +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import traceMockData from '../../fixtures/mockData/traceMockData'; +import keyTraceMockData from '../../fixtures/mockData/keyTraceMockData'; + +describe('test/core/manager/traceManager.test.ts', () => { + before(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.bulkCreate(keyTraceMockData); + const traceModel = await getInstance('traceModel'); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); + }); + + it('traceSummaryList', async () => { + const traceManager = await getInstance('traceManager'); + const res = await traceManager.traceSummaryList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + }, { + order: 'env', + limit: 10, + offset: 10, + }); + assert(res.length === 0); + }); + + it('listTraceByName', async () => { + const traceManager = await getInstance('traceManager'); + let res = await traceManager.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }, { + attributes: ['scope', 'scopeName'], + order: 'timestamp,desc|traceDuration,asc', + limit: 10, + offset: 10, + }); + assert(res.count === 1 && res.rows.length === 0); + + res = await traceManager.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }, {}); + assert(res.count === 1 && res.rows.length === 1); + }); + + after(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.destroy({ + where: { + traceName: { + [Op.in]: keyTraceMockData.map((kt) => kt.traceName), + }, + }, + }); + const traceModel = await getInstance('traceModel'); + await traceModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), + }, + }, + }); + }); + +}); diff --git a/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts b/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts new file mode 100644 index 0000000..051b2b7 --- /dev/null +++ b/packages/sandbox-core/test/core/manager/traceNodeManager.test.ts @@ -0,0 +1,74 @@ +import { getInstance } from '../../helper'; +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import traceMockData from '../../fixtures/mockData/traceMockData'; +import keyTraceMockData from '../../fixtures/mockData/keyTraceMockData'; + +describe('traceNodeManager', () => { + before(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.bulkCreate(keyTraceMockData); + const traceModel = await getInstance('traceModel'); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); + }); + + it('listNodesByTarget', async () => { + const traceManager = await getInstance('traceNodeManager'); + let res = await traceManager.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + spanName: 'configs', + spanTarget: '/', + }, { + attributes: ['scope', 'scopeName'], + order: 'timestamp,desc|spanCode,asc', + limit: 10, + offset: 10, + }); + assert(res.count === 1 && res.rows.length === 0); + + res = await traceManager.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + spanName: 'configs', + spanTarget: '/', + }, {}); + assert(res.count === 1 && res.rows.length === 1); + }); + + after(async () => { + const keyTraceModel = await getInstance('keyTraceModel'); + await keyTraceModel.destroy({ + where: { + traceName: { + [Op.in]: keyTraceMockData.map((kt) => kt.traceName), + }, + }, + }); + const traceModel = await getInstance('traceModel'); + await traceModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), + }, + }, + }); + }); + +}); diff --git a/packages/sandbox-core/test/core/service/applicationService.test.ts b/packages/sandbox-core/test/core/service/applicationService.test.ts index f135aaa..ed83537 100644 --- a/packages/sandbox-core/test/core/service/applicationService.test.ts +++ b/packages/sandbox-core/test/core/service/applicationService.test.ts @@ -22,13 +22,6 @@ describe('applicationServiceTest', () => { assert(xor(res.data.map((app) => app.flag), applicationMockData.map((app) => app.flag)).length === 0); }); - it('queryGroups', async () => { - const appService = await getInstance('applicationService'); - const res = await appService.queryGroups({ scope: 'test', scopeName: 'sandbox-test' }); - assert(res); - assert(isEqual(res.dev, defaultPlatformHostsMockData.dev)); - }); - it('queryHosts', async () => { const appService = await getInstance('applicationService'); const res = await appService.queryHosts({ env: 'dev', scope: 'test'}); @@ -41,13 +34,41 @@ describe('applicationServiceTest', () => { const appService = await getInstance('applicationService'); const res = await appService.groupUpsert({ groupName: 'test_group', - hostList: [], + hostList: [{ip: '10.0.0.1', hostname: 'devServer'}], scope: 'test', scopeName: 'sandbox-test', }); assert(res === true); }); + it('queryGroups', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.queryGroups({ scope: 'test', scopeName: 'sandbox-test' }); + assert(res); + assert(isEqual(res.dev, defaultPlatformHostsMockData.dev)); + }); + + it('groupUpsert with empty host list', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.groupUpsert({ + groupName: 'test_group_no_host', + hostList: null, + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(typeof res === 'boolean'); + }); + + it('groupExist', async () => { + const appService = await getInstance('applicationService'); + const res = await appService.groupExist({ + groupName: 'test_group', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res === 1); + }); + it('groupDelete', async () => { const appService = await getInstance('applicationService'); const res = await appService.groupDelete({ diff --git a/packages/sandbox-core/test/core/service/errorService.test.ts b/packages/sandbox-core/test/core/service/errorService.test.ts index f410e0b..dcdfcef 100644 --- a/packages/sandbox-core/test/core/service/errorService.test.ts +++ b/packages/sandbox-core/test/core/service/errorService.test.ts @@ -12,7 +12,7 @@ describe('errorServiceTest', () => { it('queryErrors', async () => { const errorService = await getInstance('errorService'); - const res = await errorService.queryErrors({ + const baseOptions = { startTime: new Date('2018-09-20 00:00:00'), endTime: new Date('2018-09-20 03:00:00'), scope: 'test', @@ -20,9 +20,33 @@ describe('errorServiceTest', () => { env: 'dev', page: 1, pageSize: 10, - }); + }; + let res = await errorService.queryErrors(baseOptions); assert(res.count === 3 && res.rows.length === 3); assert(xor(res.rows.map((row) => row.uuid), errorMockData.map((data) => data.uuid)).length === 0); + + res = await errorService.queryErrors({ + ip: '192.168.1.1', + errType: ['RangeError'], + keyword: '483d9c50-c303-11e8-a355-529269fb1459', + in: 'traceId', ...baseOptions}); + assert(res.count === 1 && res.rows.length === 1); + assert(res.rows[0].traceId === '483d9c50-c303-11e8-a355-529269fb1459'); + + res = await errorService.queryErrors({ + keyword: 'RangeError', + in: 'errorType', ...baseOptions}); + assert(res.count === 2 && res.rows.length === 2); + assert(res.rows.every((row) => row.errorType === 'RangeError')); + + res = await errorService.queryErrors({ + keyword: '192.168.1.2', + in: 'machine', ...baseOptions}); + assert(res.count === 0 && res.rows.length === 0); + + res = await errorService.queryErrors({ + keyword: 'emitTwo', ...baseOptions}); + assert(res.count === 3 && res.rows.length === 3); }); it('queryErrorTypes', async () => { diff --git a/packages/sandbox-core/test/core/service/remoteDebugService.test.ts b/packages/sandbox-core/test/core/service/remoteDebugService.test.ts index 76de6f8..53bf29d 100644 --- a/packages/sandbox-core/test/core/service/remoteDebugService.test.ts +++ b/packages/sandbox-core/test/core/service/remoteDebugService.test.ts @@ -15,4 +15,24 @@ describe('remoteDebugServiceTest', () => { assert(res.every((d) => d.debugPort && d.webSocketDebuggerUrl && d.token)); }); + it('getDebuggableHost without permission', async () => { + const remoteDebugService = await getInstance('remoteDebugService'); + let throwError = false; + try { + await remoteDebugService.getDebuggableHost({ + scope: 'test', + scopeName: 'noPermission', + uid: '1001', + ip: '127.0.0.1', + }); + } catch (err) { + if (err.message.match(/no permission/)) { + throwError = true; + } else { + throw err; + } + } + assert(throwError); + }); + }); diff --git a/packages/sandbox-core/test/core/service/traceService.test.ts b/packages/sandbox-core/test/core/service/traceService.test.ts index 7a37f73..27f81ec 100644 --- a/packages/sandbox-core/test/core/service/traceService.test.ts +++ b/packages/sandbox-core/test/core/service/traceService.test.ts @@ -10,7 +10,9 @@ describe('traceServiceTest', async () => { const keyTraceModel = await getInstance('keyTraceModel'); await keyTraceModel.bulkCreate(keyTraceMockData); const traceModel = await getInstance('traceModel'); - await traceModel.bulkCreate(traceMockData); + await traceModel.bulkCreate(traceMockData.traces); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.bulkCreate(traceMockData.traceNodes); }); it('listFocusTraces', async () => { @@ -19,18 +21,540 @@ describe('traceServiceTest', async () => { scope: 'test', scopeName: 'sandbox-test', }); - assert(res); + assert(res.data.length === traceMockData.traces.length); }); it('listTraces', async () => { const traceService = await getInstance('traceService'); - const res = await traceService.listTraces({ + let res = await traceService.listTraces({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + }); + assert(res.data.length === traceMockData.traces.length); + + res = await traceService.listTraces({ + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + }); + assert(res.data.length >= 0); + + res = await traceService.listTraces({ + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length >= 0); + }); + + it('traceDetail', async () => { + const traceService = await getInstance('traceService'); + const testUUID = '3e351e0f-9abd-4023-8a2a-061dc3cacffc'; + let res = await traceService.traceDetail({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + uuid: testUUID, + }); + assert(res && res.uuid === testUUID); + + res = await traceService.traceDetail({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + uuid: testUUID, + }); + assert(res && res.uuid === testUUID); + }); + + it('toggleTraceFocus', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.toggleTraceFocus({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 1, + }); + assert(typeof res === 'boolean'); + }); + + it('toggleTraceFocus cancel', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.toggleTraceFocus({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(typeof res === 'boolean'); + }); + + it('traceTotalitySummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + + res = await traceService.traceTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + + res = await traceService.traceTotalitySummary({ startTime: new Date('2018-09-28 01:00:00'), endTime: new Date('2018-09-28 01:30:00'), scope: 'test', scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', }); assert(res); + assert(res[0] === traceMockData.traces.reduce((total, trace) => total += trace.traceDuration, 0) / traceMockData.traces.length); + assert(res[1] === traceMockData.traces.length); + assert(res[2] === 100); + }); + + it('spanTotalitySummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + + res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + + res = await traceService.spanTotalitySummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.slice(0, 3).every((val) => typeof val === 'number')); + assert(typeof res[3] === 'string' && res[3].length > 0); + }); + + it('traceSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + hostname: 'develop.server', + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + ip: '10.0.0.1', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === 0); + }); + + it('listTraceByName', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + hostname: 'develop.server', + scope: 'test', + scopeName: 'sandbox-test', + }); + assert(res.data.length === traceMockData.traces.length); + + res = await traceService.listTraceByName({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + + res = await traceService.listTraceByName({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 0); + }); + + it('traceSummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceSummary({ + scope: 'test', + scopeName: 'sandbox-test-not-exist', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + }); + + it('traceNodeSummaryList', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummaryList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + env: 'dev', + hostname: 'develop.server', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + + res = await traceService.traceNodeSummaryList({ + scope: 'test', + ip: '10.0.0.1', + scopeName: 'sandbox-test', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + + res = await traceService.traceNodeSummaryList({ + scope: 'test', + scopeName: 'sandbox-test', + traceName: 'HTTP-GET:/products', + focus: 0, + }); + assert(res.data.every((record) => { + return record.slice(0, 3).every((val) => typeof val === 'number') + && typeof record[3] === 'string'; + })); + }); + + it('traceNodeSummary', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceNodeSummary({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.every((val) => typeof val === 'number')); + + res = await traceService.traceNodeSummary({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.length >= 0); + }); + + it('traceNodeSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.traceNodeSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceNodeSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.traceNodeSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length === 0); + }); + + it('spanTargetList', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTargetList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length > 0); + assert(res.data.every((val) => typeof val[0] === 'string' && typeof val[1] === 'number')); + + res = await traceService.spanTargetList({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + }); + assert(res.data.length > 0); + assert(res.data.every((val) => typeof val[0] === 'string' && typeof val[1] === 'number')); + + res = await traceService.spanTargetList({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + }); + assert(res.data.length === 0); + }); + + it('spanTargetSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spanTargetSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.spanTargetSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + assert(res.data.every((record) => { + return record.slice(1, 4).every((val) => typeof val === 'number') + && record[0] instanceof Date; + })); + + res = await traceService.spanTargetSummaryTrend({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + spanTarget: '/', + }); + assert(res.data.length === 0); + }); + + it('listNodesByTarget', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + + res = await traceService.listNodesByTarget({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 1); + + res = await traceService.listNodesByTarget({ + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + spanTarget: '/', + }); + assert(res.data.length === 0); + }); + + it('spansSummaryTrend', async () => { + const traceService = await getInstance('traceService'); + let res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + + res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + ip: '10.0.0.1', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + + res = await traceService.spansSummaryTrend({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.types[0] === 'configs'); + assert(Object.keys(res).filter((key) => key !== 'types').every((key) => res[key].every((val) => val.timestamp && val.configs))); + }); + + it('traceFlowHistogram', async () => { + const traceService = await getInstance('traceService'); + const res = await traceService.traceFlowHistogram({ + startTime: new Date('2018-09-28 01:00:00'), + endTime: new Date('2018-09-28 01:30:00'), + env: 'dev', + scope: 'test', + scopeName: 'sandbox-test', + spanName: 'configs', + traceName: 'HTTP-GET:/products', + spanTarget: '/', + }); + assert(res.data.length === 2); }); after(async () => { @@ -46,7 +570,15 @@ describe('traceServiceTest', async () => { await traceModel.destroy({ where: { uuid: { - [Op.in]: traceMockData.map((tr) => tr.uuid), + [Op.in]: traceMockData.traces.map((tr) => tr.uuid), + }, + }, + }); + const traceNodeModel = await getInstance('traceNodeModel'); + await traceNodeModel.destroy({ + where: { + uuid: { + [Op.in]: traceMockData.traceNodes.map((tr) => tr.uuid), }, }, }); diff --git a/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts b/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts index 1d23572..2cd6576 100644 --- a/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts +++ b/packages/sandbox-core/test/fixtures/injections/privilegeAdapter.ts @@ -3,6 +3,9 @@ import { provide } from 'midway-mirror'; @provide('privilegeAdapter') export class PrivilegeAdapter { async isAppOps(scope: string, scopeName: string, uid: string): Promise { + if (scopeName === 'noPermission') { + return false; + } return true; } } diff --git a/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts b/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts index 720f670..68be9ad 100644 --- a/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts +++ b/packages/sandbox-core/test/fixtures/mockData/traceMockData.ts @@ -1,36 +1,68 @@ -export default [ - { - timestamp: new Date('2018-09-28 01:13:34'), - scope: 'test', - scopeName: 'sandbox-test', - env: 'dev', - hostname: 'develop.server', - ip: '10.0.0.1', - uuid: '0f7ea820-3fb2-4496-b755-ca5bd76763bd', - traceId: '0b859a6d15381252001705791e067a', - version: 1, - traceSpans: '[]', - unix_timestamp: 1538068414, - trace_duration: 3, - pid: 4328, - traceName: 'HTTP-GET:/', - traceStatus: 1, - }, - { - timestamp: new Date('2018-09-28 01:13:35'), - scope: 'test', - scopeName: 'sandbox-test', - env: 'dev', - hostname: 'develop.server', - ip: '10.0.0.1', - uuid: '3e351e0f-9abd-4023-8a2a-061dc3cacffc', - traceId: '0b859a6d153091a2001705791e067a', - version: 1, - traceSpans: '[]', - unix_timestamp: 1538068415, - trace_duration: 2, - pid: 4928, - traceName: 'HTTP-GET:/products', - traceStatus: 1, - }, -]; +export default { + traces: [ + { + timestamp: new Date('2018-09-28 01:13:34'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '0f7ea820-3fb2-4496-b755-ca5bd76763bd', + traceId: '0b859a6d15381252001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068414, + traceDuration: 3, + pid: 4328, + traceName: 'HTTP-GET:/', + traceStatus: 1, + }, + { + timestamp: new Date('2018-09-28 01:13:35'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '3e351e0f-9abd-4023-8a2a-061dc3cacffc', + traceId: '0b859a6d153091a2001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068415, + traceDuration: 2, + pid: 4928, + traceName: 'HTTP-GET:/products', + traceStatus: 1, + }, + ], + traceNodes: [ + { + timestamp: new Date('2018-09-28 01:13:35'), + scope: 'test', + scopeName: 'sandbox-test', + env: 'dev', + hostname: 'develop.server', + ip: '10.0.0.1', + uuid: '3e351e0f-9abd-4023-8a2a-061dd3cacffc', + traceId: '0b859a6d153091a2001705791e067a', + version: 1, + traceSpans: '[]', + unixTimestamp: 1538068415, + traceDuration: 2, + traceName: 'HTTP-GET:/products', + traceStatus: 1, + spanName: 'configs', + spanDuration: 142, + spanType: 0, + spanTags: '{}', + spanId: 'eb26f0605ab77a93', + spanRpcId: '0.1.1.0', + spanCode: 200, + spanError: 0, + spanMethod: 'GET', + spanTimestamp: '2018-09-28 01:13:35', + pid: 2045, + spanTarget: '/', + }, + ], +}; From 805ec2e7de0ac0d74d3c1a1e2153970d7f03d08b Mon Sep 17 00:00:00 2001 From: Chunlin-Li Date: Mon, 22 Oct 2018 16:01:03 +0800 Subject: [PATCH 19/27] chore: travis timezone --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index cd4eda1..7cad407 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ services: - mysql before_install: - sudo mysql < ./packages/sandbox-core/test/fixtures/sql/initDB.sql 2>&1 + - export TZ=Asia/Shanghai install: - npm i - npm i codecov From f2ade86f1a55b89a24d0df83ff01b60c82a760ac Mon Sep 17 00:00:00 2001 From: Chunlin-Li Date: Mon, 22 Oct 2018 16:05:35 +0800 Subject: [PATCH 20/27] test: add test cases --- .../app/controller/applicationCtrl.test.ts | 89 +++++++++++++++++++ .../test/app/controller/errorCtrl.test.ts | 51 +++++++++++ readme.md | 2 +- 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 packages/sandbox-core/test/app/controller/applicationCtrl.test.ts create mode 100644 packages/sandbox-core/test/app/controller/errorCtrl.test.ts diff --git a/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts b/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts new file mode 100644 index 0000000..93b31b0 --- /dev/null +++ b/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts @@ -0,0 +1,89 @@ +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import { getInstance } from '../../helper'; +import applicationMockData from '../../fixtures/mockData/applicationMockData'; + +describe('applicationCtrltest', async () => { + + before(async () => { + const applicationModel = await getInstance('applicationModel'); + await Promise.all([ + applicationModel.bulkCreate(applicationMockData), + ]); + }); + + it('listByUser', async () => { + const applicationCtrl = await getInstance('applicationCtrl'); + const ctx = { + uid: '1001', + query: { + offset: 0 + } + }; + await applicationCtrl.listByUser(ctx); + assert((ctx as any).body.success === true); + }); + + it('groupUpsert', async () => { + const applicationCtrl = await getInstance('applicationCtrl'); + const ctx = { + request: { + body: { + groupName: 'test_group', + hostList: [{ip: '10.0.0.1', hostname: 'devServer'}], + scope: 'test', + scopeName: 'sandbox-test', + } + } + }; + await applicationCtrl.groupUpsert(ctx); + assert((ctx as any).body); + }); + + it('groupExist', async () => { + const applicationCtrl = await getInstance('applicationCtrl'); + const ctx = { + query: { + groupName: 'test_group', + scope: 'test', + scopeName: 'sandbox-test', + } + }; + await applicationCtrl.groupExist(ctx); + assert((ctx as any).body); + }); + + it('groupDelete', async () => { + const applicationCtrl = await getInstance('applicationCtrl'); + const ctx = { + request: { + body: { + groupName: 'test_group', + scope: 'test', + scopeName: 'sandbox-test', + } + } + }; + await applicationCtrl.groupDelete(ctx); + assert((ctx as any).body); + }); + + after(async () => { + const applicationModel = await getInstance('applicationModel'); + await applicationModel.destroy({ + where: { + alinodeToken: { + [Op.in]: applicationMockData.map((app) => app.alinodeToken), + }, + }, + }); + const groupModel = await getInstance('groupModel'); + await groupModel.destroy({ + where: { + groupName: 'test_group', + scope: 'test', + scopeName: 'sandbox-test', + }, + }); + }); +}); \ No newline at end of file diff --git a/packages/sandbox-core/test/app/controller/errorCtrl.test.ts b/packages/sandbox-core/test/app/controller/errorCtrl.test.ts new file mode 100644 index 0000000..477ffd1 --- /dev/null +++ b/packages/sandbox-core/test/app/controller/errorCtrl.test.ts @@ -0,0 +1,51 @@ +import * as assert from 'assert'; +import { Op } from 'sequelize'; +import { getInstance } from '../../helper'; +import errorMockData from '../../fixtures/mockData/errorMockData'; + +describe('errorCtrlTest', async () => { + + before(async () => { + const errorModel = await getInstance('errorModel'); + await errorModel.bulkCreate(errorMockData); + }); + + it('queryErrors', async () => { + const errorCtrl = await getInstance('errorCtrl'); + const ctx = { + request: { + query: { + scopeName: 'sandbox-test', + } + } + }; + await errorCtrl.queryErrors(ctx); + assert((ctx as any).body.success === false); + assert((ctx as any).body.error.name === 'GetSLSLogError'); + }); + + it('queryErrorTypes', async () => { + const errorCtrl = await getInstance('errorCtrl'); + const ctx = { + request: { + query: { + scopeName: 'sandbox-test', + } + } + }; + await errorCtrl.queryErrorTypes(ctx); + assert((ctx as any).body.success === true); + }); + + + after(async () => { + const errorModel = await getInstance('errorModel'); + await errorModel.destroy({ + where: { + uuid: { + [Op.in]: errorMockData.map((e) => e.uuid), + }, + }, + }); + }); +}); \ No newline at end of file diff --git a/readme.md b/readme.md index 808a617..5e3d51f 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ ## Sandbox -Preparing... +Preparing.... From 32b1a84096d6a1981b6f231e34495bdc2c97eb21 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 23 Oct 2018 15:40:55 +0800 Subject: [PATCH 21/27] test: add test for metricsManager --- packages/sandbox-core/package.json | 2 + .../test/core/manager/metricsManager.test.ts | 249 ++++++++++++++++++ packages/sandbox-core/test/fixtures/config.ts | 4 + 3 files changed, 255 insertions(+) create mode 100644 packages/sandbox-core/test/core/manager/metricsManager.test.ts diff --git a/packages/sandbox-core/package.json b/packages/sandbox-core/package.json index c7df0a6..27ce379 100644 --- a/packages/sandbox-core/package.json +++ b/packages/sandbox-core/package.json @@ -28,6 +28,8 @@ "@types/urllib": "^2.28.0", "chai": "^3.5.0", "midway-bin": "^0.3.8", + "midway-mock": "^0.4.2", + "mm": "^2.4.1", "mocha": "^3.5.0", "nyc": "^11.2.1", "ts-node": "^4.1.0", diff --git a/packages/sandbox-core/test/core/manager/metricsManager.test.ts b/packages/sandbox-core/test/core/manager/metricsManager.test.ts new file mode 100644 index 0000000..8ea90f5 --- /dev/null +++ b/packages/sandbox-core/test/core/manager/metricsManager.test.ts @@ -0,0 +1,249 @@ +import * as assert from 'assert'; +import {MetricsManager} from '../../../src/core/manager/metricsManager'; +import { getInstance } from '../../helper'; +import { expect } from 'chai'; +import mm = require('mm'); + +describe('test/core/manager/metricsManager.test.ts', () => { + + it('should static pickLatestDp() be ok', () => { + const latest = MetricsManager.pickLatestDp({ + 123: '123', + 456: '456', + 1000: 'latest' + }); + assert('latest' === latest); + }); + + it('should getMetricsNames() be ok', async () => { + const metricsManager: MetricsManager = await getInstance('metricsManager'); + const res = await metricsManager.getMetricsNames({ + scope: 'test', + scopeName: 'test' + }); + assert(res.length === 3); + assert(res[0] === 'cpu'); + assert(res[1] === 'mem'); + assert(res[2] === 'qps'); + }); + + it('should frontEndAnalyse() with analyseHigherLower=true be ok', async () => { + + const metricsManager: MetricsManager = await getInstance('metricsManager'); + const res = metricsManager.frontEndAnalyse( + {analyseHigherLower: true}, + [{ metric: 'testName', aggregator: 'avg' }], + [ + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-a', + trend: [ + { time: 1, value: 1 }, + { time: 2, value: 1 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-b', + trend: [ + { time: 1, value: 2 }, + { time: 2, value: 2 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-b', + trend: [ + { time: 1, value: 3 }, + { time: 2, value: 3 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-c', + trend: [ + { time: 1, value: 4 }, + { time: 2, value: 4 }, + ] + }, + ] + ); + + expect(res).to.deep.equal( + [ + { + "metric": "testName", + "aggregator": "avg", + "frontEndAggregator": "avg", + "trend": [ + { + "time": 1, + "value": 2.5 + }, + { + "time": 2, + "value": 2.5 + } + ] + }, + { + "metric": "testName", + "aggregator": "avg", + "hostname": "host-c", + "trend": [ + { + "time": 1, + "value": 4 + }, + { + "time": 2, + "value": 4 + } + ], + "frontEndAggregator": "highest" + }, + { + "metric": "testName", + "aggregator": "avg", + "hostname": "host-a", + "trend": [ + { + "time": 1, + "value": 1 + }, + { + "time": 2, + "value": 1 + } + ], + "frontEndAggregator": "lowest" + } + ] + ); + }); + + it('should frontEndAnalyse() with analyseHigherLower=false be ok', async () => { + const input = [ + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-a', + trend: [ + { time: 1, value: 1 }, + { time: 2, value: 1 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-b', + trend: [ + { time: 1, value: 2 }, + { time: 2, value: 2 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-b', + trend: [ + { time: 1, value: 3 }, + { time: 2, value: 3 }, + ] + }, + { + metric: 'testName', + aggregator: 'avg', + hostname: 'host-c', + trend: [ + { time: 1, value: 4 }, + { time: 2, value: 4 }, + ] + }, + ]; + const metricsManager: MetricsManager = await getInstance('metricsManager'); + const res = metricsManager.frontEndAnalyse( + {analyseHigherLower: false}, + [{ metric: 'testName', aggregator: 'avg' }], + input + ); + expect(res).to.be.equal(input); + }); + + it('should getLatestMetricByAppSelectorAndGroupByEachHost() be ok', async () => { + const metricsManager: MetricsManager = await getInstance('metricsManager'); + mm(metricsManager, 'tsdb', { + query(queryOpts) { + return [ + { + tags: { + hostname: 'host-a', + ip: '192.168.2.1' + }, + dps: { + 1: 11, + 2: 12, + 3: 13, + } + }, + { + tags: { + hostname: 'host-b', + ip: '192.168.2.2' + }, + dps: { + 1: 21, + 2: 22, + 3: 23, + } + }, + { + tags: { + hostname: 'host-c', + ip: '192.168.2.3' + }, + dps: { + 1: 31, + 2: 32, + 3: 33, + } + }, + ]; + } + }); + const res = await metricsManager.getLatestMetricByAppSelectorAndGroupByEachHost( + { + metric: 'testName' + }, + { + scope: 'test', + scopeName: 'test' + } + ); + expect(res).to.deep.equal( + [ + { + "hostname": "host-a", + "ip": "192.168.2.1", + "value": 13 + }, + { + "hostname": "host-b", + "ip": "192.168.2.2", + "value": 23 + }, + { + "hostname": "host-c", + "ip": "192.168.2.3", + "value": 33 + } + ] + ); + mm.restore(); + }); + +}); diff --git a/packages/sandbox-core/test/fixtures/config.ts b/packages/sandbox-core/test/fixtures/config.ts index 9c9614c..cac85a7 100644 --- a/packages/sandbox-core/test/fixtures/config.ts +++ b/packages/sandbox-core/test/fixtures/config.ts @@ -16,4 +16,8 @@ export default { pandora: { restfulPort: 3010, }, + tsdb: { + host: '127.0.0.1', + port: 4242 + } }; From 234a3165daab189c130736cd597faa9335b3b7e5 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Tue, 23 Oct 2018 16:35:30 +0800 Subject: [PATCH 22/27] test: add test for metricsService --- .../test/core/service/metricsService.test.ts | 328 ++++++++++++++++-- 1 file changed, 308 insertions(+), 20 deletions(-) diff --git a/packages/sandbox-core/test/core/service/metricsService.test.ts b/packages/sandbox-core/test/core/service/metricsService.test.ts index 4e58172..180d866 100644 --- a/packages/sandbox-core/test/core/service/metricsService.test.ts +++ b/packages/sandbox-core/test/core/service/metricsService.test.ts @@ -1,21 +1,309 @@ -// import * as assert from 'assert'; -// import { getInstance } from '../../helper'; - -describe('metricsServiceTest', () => { -// before(async () => { -// }); -// -// it('getMetricsNames', async () => { -// }); -// -// it('getCustomMetricsNames', async () => {}); -// -// it('queryMetricsLatest', async () => {}); -// -// it('queryMetricsTrend', async () => {}); -// -// it('queryHostsMap', async () => {}); -// -// after(async () => { -// }); +import * as assert from 'assert'; +import { getInstance } from '../../helper'; +import mm = require('mm'); +import { expect } from 'chai'; +import {MetricsService} from '../../../src/core/service/metricsService'; + +describe('metricsService.test.ts', () => { + + afterEach(() => { + mm.restore(); + }); + + it('should getMetricsNames() be ok', async () => { + const metricsService: MetricsService = await getInstance('metricsService'); + const res = await metricsService.getMetricsNames({ + scope: 'test', + scopeName: 'test' + }); + assert(res.length === 3); + assert(res[0] === 'cpu'); + assert(res[1] === 'mem'); + assert(res[2] === 'qps'); + }); + + it('should getCustomMetricsNames() be ok', async () => { + const metricsService: MetricsService = await getInstance('metricsService'); + mm(metricsService.metricsManager, 'getMetricsNames', () => { + return ['system.a', 'node.b', 'error.c', 'middleware.d', 'ok', 'yes', 'custom.xxx']; + }); + const res = await metricsService.getCustomMetricsNames({ + scope: 'test', + scopeName: 'test' + }); + expect(res).to.deep.equal(['ok', 'yes', 'custom.xxx']); + }); + + it('should queryMetricsLatest() be ok', async () => { + const metricsService: MetricsService = await getInstance('metricsService'); + mm(metricsService, 'tsdb', { + query: async (query) => { + assert(query.start === '6m-ago'); + assert(query.queries[0].metric === 'testName1'); + assert(query.queries[0].aggregator === 'avg'); + assert(query.queries[0].downsample === '1m-last'); + assert(query.queries[0].tags.scope === 'test'); + assert(query.queries[0].tags.scope_name === 'test'); + assert(query.queries[0].tags.env === 'test'); + assert(query.queries[1].metric === 'testName2'); + assert(query.queries[1].aggregator === 'avg'); + assert(query.queries[1].downsample === '1m-last'); + assert(query.queries[1].tags.scope === 'test'); + assert(query.queries[1].tags.scope_name === 'test'); + assert(query.queries[1].tags.env === 'test'); + assert(query.queries.length === 2); + return [ + { + metric: 'testName1', + query: { + metric: 'testName1', + aggregator: 'avg' + }, + dps: { + 1: 11, + 2: 12, + 3: 13 + } + }, + { + metric: 'testName2', + query: { + metric: 'testName2', + aggregator: 'avg' + }, + dps: { + 1: 21, + 2: 22, + 3: 23 + } + }, + ] + } + }); + const res = await metricsService.queryMetricsLatest({ + scope: 'test', scopeName: 'test', env: 'test', + metricsNames: [ + { metric: 'testName1', aggregator: 'avg' }, + { metric: 'testName2', aggregator: 'avg' }, + ] + }); + expect(res).to.deep.equal( + [ { latest: 13 }, { latest: 23 } ] + ); + }); + + it('should queryMetricsTrend() be ok', async () => { + const metricsService: MetricsService = await getInstance('metricsService'); + mm(metricsService, 'tsdb', { + query: async (query) => { + assert(query.start === 123); + assert(query.end === 456); + assert(query.queries[0].metric === 'testName1'); + assert(query.queries[0].aggregator === 'avg'); + assert(query.queries[0].tags.scope === 'test'); + assert(query.queries[0].tags.scope_name === 'test'); + assert(query.queries[0].tags.env === 'test'); + assert(query.queries[1].metric === 'testName2'); + assert(query.queries[1].aggregator === 'avg'); + assert(query.queries[1].tags.scope === 'test'); + assert(query.queries[1].tags.scope_name === 'test'); + assert(query.queries[1].tags.env === 'test'); + assert(query.queries.length === 2); + return [ + { + metric: 'testName1', + query: { + metric: 'testName1', + aggregator: 'avg' + }, + tags: { + hostname: 'host-a', + ip: '192.168.1.1', + pid: 1 + }, + dps: { + 1: 11, + 2: 12, + 3: 13 + } + }, + { + metric: 'testName2', + query: { + metric: 'testName2', + aggregator: 'avg' + }, + tags: { + hostname: 'host-b', + ip: '192.168.1.2', + pid: 2 + }, + dps: { + 1: 21, + 2: 22, + 3: 23 + } + }, + ] + } + }); + const res = await metricsService.queryMetricsTrend({ + scope: 'test', + scopeName: 'test', + env: 'test', + startTime: 123, + endTime: 456, + metricsNames: [ + { metric: 'testName1', aggregator: 'avg' }, + { metric: 'testName2', aggregator: 'avg' }, + ] + }); + expect(res).to.deep.equal([ + { + "trend": [ + { + "time": 1, + "value": 11 + }, + { + "time": 2, + "value": 12 + }, + { + "time": 3, + "value": 13 + } + ], + "aggregator": "avg", + "metric": "testName1", + "hostname": "host-a", + "ip": "192.168.1.1", + "pid": 1 + }, + { + "trend": [ + { + "time": 1, + "value": 21 + }, + { + "time": 2, + "value": 22 + }, + { + "time": 3, + "value": 23 + } + ], + "aggregator": "avg", + "metric": "testName2", + "hostname": "host-b", + "ip": "192.168.1.2", + "pid": 2 + } + ]); + }); + + it('should queryHostsMap() be ok', async () => { + + const calledTimes = []; + const metricsService: MetricsService = await getInstance('metricsService'); + + mm(metricsService, 'metricsManager', { + getLatestMetricByAppSelectorAndGroupByEachHost: async (metricsName, appSelector) => { + calledTimes.push(metricsName); + assert(appSelector.scope === 'test'); + assert(appSelector.scopeName === 'test'); + assert(appSelector.env === 'test'); + return [ + { + "hostname": "host-a", + "ip": "192.168.2.1", + "value": 13 + }, + { + "hostname": "host-b", + "ip": "192.168.2.2", + "value": 23 + }, + { + "hostname": "host-d", + "ip": "192.168.2.4", + "value": 43 + } + ] + } + }); + mm(metricsService, 'applicationService', { + queryGroups(app) { + assert(app.scope === 'test'); + assert(app.scopeName === 'test'); + return { + 'test': [ + { + name: 'group_1', + hosts: [ + { + ip: '192.168.2.1', + hostname: 'host-a' + }, + { + ip: '192.168.2.2', + hostname: 'host-b' + }, + { + ip: '192.168.2.3', + hostname: 'host-c' + } + ] + } + ] + } + } + }); + + const res = await metricsService.queryHostsMap({ + scope: 'test', + scopeName: 'test', + env: 'test', + metricsNames: [ + { metric: 'testName1', aggregator: 'avg' }, + { metric: 'testName2', aggregator: 'avg' }, + ] + }); + + expect(res).to.deep.equal([ + { + "name": "group_1", + "hosts": [ + { + "ip": "192.168.2.1", + "hostname": "host-a", + "testName1": 13, + "testName2": 13 + }, + { + "ip": "192.168.2.2", + "hostname": "host-b", + "testName1": 23, + "testName2": 23 + }, + { + "ip": "192.168.2.3", + "hostname": "host-c" + } + ] + } + ] + ); + + expect(calledTimes).to.deep.equal([ + { metric: 'testName1', aggregator: 'avg' }, + { metric: 'testName2', aggregator: 'avg' } + ]); + + }); + + }); + From c4f2e249aa0b877c88986b7d66d1be8b0806764f Mon Sep 17 00:00:00 2001 From: Chunlin-Li Date: Tue, 23 Oct 2018 17:52:16 +0800 Subject: [PATCH 23/27] test: debugServer test case --- .../test/core/debugServer/cipher.test.ts | 19 +++++ .../test/core/debugServer/debugServer.test.ts | 73 +++++++++++++++++++ .../core/service/applicationService.test.ts | 2 +- 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 packages/sandbox-core/test/core/debugServer/cipher.test.ts create mode 100644 packages/sandbox-core/test/core/debugServer/debugServer.test.ts diff --git a/packages/sandbox-core/test/core/debugServer/cipher.test.ts b/packages/sandbox-core/test/core/debugServer/cipher.test.ts new file mode 100644 index 0000000..a42b6e4 --- /dev/null +++ b/packages/sandbox-core/test/core/debugServer/cipher.test.ts @@ -0,0 +1,19 @@ +import * as assert from 'assert'; +import { Cipher } from '../../../src/core/debugServer/cipher'; + + +describe('/src/core/debugServer/cipher.ts', () => { + + it('should throw error when pass null to encrypt', () => { + assert.throws(() => { + Cipher.encrypt(null); + }, Error); + }); + + it('should throw error when pass null to decrypt', () => { + assert.throws(() => { + Cipher.decrypt(null); + }, Error); + }); + +}); \ No newline at end of file diff --git a/packages/sandbox-core/test/core/debugServer/debugServer.test.ts b/packages/sandbox-core/test/core/debugServer/debugServer.test.ts new file mode 100644 index 0000000..3e5989d --- /dev/null +++ b/packages/sandbox-core/test/core/debugServer/debugServer.test.ts @@ -0,0 +1,73 @@ +import * as http from 'http'; +import { DebugServer } from '../../../src/core/debugServer/debugServer'; +import * as WebSocket from 'ws'; +import { Cipher } from '../../../src/core/debugServer/cipher'; +import { spawn } from 'child_process'; +import { once } from 'lodash'; +import * as assert from 'assert'; + + +describe('src/core/debugServer/debugServer.ts', () => { + + let debugableProcess, debugServer, token; + + before(() => { + debugableProcess = spawn('node', ['--inspect=5858']); + debugableProcess.on('error', console.error); + + const httpServer = http.createServer(); + httpServer.listen(3322); + debugServer = new DebugServer(httpServer); + debugServer.start(); + + token = Cipher.encrypt(JSON.stringify({ + ip: '127.0.0.1' + })); + }); + + it('should connect debug server', (done) => { + const client = new WebSocket('ws://127.0.0.1:3322/remoteDebug?token=' + token); + + client.on('open', () => { + client.send('{}'); + }); + const doneOnce = once(done); + client.on('message', (data) => { + assert(JSON.parse(data)); + client.terminate(); + client.on('close', () => { + doneOnce(); + }); + + }); + }); + + it('should closed by debug server', (done) => { + const client = new WebSocket('ws://127.0.0.1:3322/foobar?token=' + token); + client.on('close', () => { + done(); + }); + setTimeout(done.bind(null, new Error('socket not closed in 3s')), 3000); + }); + + it('should report a Error: Cannot found any instance', (done) => { + const mockServer = http.createServer((req, res) => req.pipe(res)); + mockServer.listen(5859); + let mockToken = Cipher.encrypt(JSON.stringify({ + ip: '127.0.0.1', + debugPort: '5859' + })); + const client = new WebSocket('ws://127.0.0.1:3322/remoteDebug?token=' + mockToken); + client.on('close', () => done()); + }); + + it('should report a Error: Unexpected end of JSON input', (done) => { + const client = new WebSocket('ws://127.0.0.1:3322/remoteDebug?token=' + token.slice(0, -10)); + client.on('close', () => done()); + }); + + after(() => { + debugableProcess.kill(); + }) + +}); \ No newline at end of file diff --git a/packages/sandbox-core/test/core/service/applicationService.test.ts b/packages/sandbox-core/test/core/service/applicationService.test.ts index ed83537..0c480f3 100644 --- a/packages/sandbox-core/test/core/service/applicationService.test.ts +++ b/packages/sandbox-core/test/core/service/applicationService.test.ts @@ -38,7 +38,7 @@ describe('applicationServiceTest', () => { scope: 'test', scopeName: 'sandbox-test', }); - assert(res === true); + assert(typeof res === 'boolean'); }); it('queryGroups', async () => { From 46299e85dc9ef6b47b4523496af6ea124852c4fd Mon Sep 17 00:00:00 2001 From: Chunlin-Li Date: Tue, 23 Oct 2018 19:56:54 +0800 Subject: [PATCH 24/27] style: tslint --- .../app/controller/applicationCtrl.test.ts | 16 +- .../test/app/controller/errorCtrl.test.ts | 11 +- .../test/core/debugServer/cipher.test.ts | 3 +- .../test/core/debugServer/debugServer.test.ts | 30 +-- .../test/core/manager/metricsManager.test.ts | 130 ++++++------- .../test/core/service/metricsService.test.ts | 182 +++++++++--------- packages/sandbox-core/test/fixtures/config.ts | 4 +- 7 files changed, 187 insertions(+), 189 deletions(-) diff --git a/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts b/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts index 93b31b0..cb42671 100644 --- a/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts +++ b/packages/sandbox-core/test/app/controller/applicationCtrl.test.ts @@ -17,8 +17,8 @@ describe('applicationCtrltest', async () => { const ctx = { uid: '1001', query: { - offset: 0 - } + offset: 0, + }, }; await applicationCtrl.listByUser(ctx); assert((ctx as any).body.success === true); @@ -33,8 +33,8 @@ describe('applicationCtrltest', async () => { hostList: [{ip: '10.0.0.1', hostname: 'devServer'}], scope: 'test', scopeName: 'sandbox-test', - } - } + }, + }, }; await applicationCtrl.groupUpsert(ctx); assert((ctx as any).body); @@ -47,7 +47,7 @@ describe('applicationCtrltest', async () => { groupName: 'test_group', scope: 'test', scopeName: 'sandbox-test', - } + }, }; await applicationCtrl.groupExist(ctx); assert((ctx as any).body); @@ -61,8 +61,8 @@ describe('applicationCtrltest', async () => { groupName: 'test_group', scope: 'test', scopeName: 'sandbox-test', - } - } + }, + }, }; await applicationCtrl.groupDelete(ctx); assert((ctx as any).body); @@ -86,4 +86,4 @@ describe('applicationCtrltest', async () => { }, }); }); -}); \ No newline at end of file +}); diff --git a/packages/sandbox-core/test/app/controller/errorCtrl.test.ts b/packages/sandbox-core/test/app/controller/errorCtrl.test.ts index 477ffd1..e3b125d 100644 --- a/packages/sandbox-core/test/app/controller/errorCtrl.test.ts +++ b/packages/sandbox-core/test/app/controller/errorCtrl.test.ts @@ -16,8 +16,8 @@ describe('errorCtrlTest', async () => { request: { query: { scopeName: 'sandbox-test', - } - } + }, + }, }; await errorCtrl.queryErrors(ctx); assert((ctx as any).body.success === false); @@ -30,14 +30,13 @@ describe('errorCtrlTest', async () => { request: { query: { scopeName: 'sandbox-test', - } - } + }, + }, }; await errorCtrl.queryErrorTypes(ctx); assert((ctx as any).body.success === true); }); - after(async () => { const errorModel = await getInstance('errorModel'); await errorModel.destroy({ @@ -48,4 +47,4 @@ describe('errorCtrlTest', async () => { }, }); }); -}); \ No newline at end of file +}); diff --git a/packages/sandbox-core/test/core/debugServer/cipher.test.ts b/packages/sandbox-core/test/core/debugServer/cipher.test.ts index a42b6e4..17ce724 100644 --- a/packages/sandbox-core/test/core/debugServer/cipher.test.ts +++ b/packages/sandbox-core/test/core/debugServer/cipher.test.ts @@ -1,7 +1,6 @@ import * as assert from 'assert'; import { Cipher } from '../../../src/core/debugServer/cipher'; - describe('/src/core/debugServer/cipher.ts', () => { it('should throw error when pass null to encrypt', () => { @@ -16,4 +15,4 @@ describe('/src/core/debugServer/cipher.ts', () => { }, Error); }); -}); \ No newline at end of file +}); diff --git a/packages/sandbox-core/test/core/debugServer/debugServer.test.ts b/packages/sandbox-core/test/core/debugServer/debugServer.test.ts index 3e5989d..41a8996 100644 --- a/packages/sandbox-core/test/core/debugServer/debugServer.test.ts +++ b/packages/sandbox-core/test/core/debugServer/debugServer.test.ts @@ -1,19 +1,21 @@ import * as http from 'http'; -import { DebugServer } from '../../../src/core/debugServer/debugServer'; -import * as WebSocket from 'ws'; -import { Cipher } from '../../../src/core/debugServer/cipher'; +import * as assert from 'assert'; import { spawn } from 'child_process'; +import * as WebSocket from 'ws'; import { once } from 'lodash'; -import * as assert from 'assert'; - +import { DebugServer } from '../../../src/core/debugServer/debugServer'; +import { Cipher } from '../../../src/core/debugServer/cipher'; describe('src/core/debugServer/debugServer.ts', () => { - let debugableProcess, debugServer, token; + let debugableProcess; + let debugServer; + let token; + const logger = console; - before(() => { + before(async () => { debugableProcess = spawn('node', ['--inspect=5858']); - debugableProcess.on('error', console.error); + debugableProcess.on('error', logger.error); const httpServer = http.createServer(); httpServer.listen(3322); @@ -21,7 +23,7 @@ describe('src/core/debugServer/debugServer.ts', () => { debugServer.start(); token = Cipher.encrypt(JSON.stringify({ - ip: '127.0.0.1' + ip: '127.0.0.1', })); }); @@ -38,7 +40,7 @@ describe('src/core/debugServer/debugServer.ts', () => { client.on('close', () => { doneOnce(); }); - + }); }); @@ -53,9 +55,9 @@ describe('src/core/debugServer/debugServer.ts', () => { it('should report a Error: Cannot found any instance', (done) => { const mockServer = http.createServer((req, res) => req.pipe(res)); mockServer.listen(5859); - let mockToken = Cipher.encrypt(JSON.stringify({ + const mockToken = Cipher.encrypt(JSON.stringify({ ip: '127.0.0.1', - debugPort: '5859' + debugPort: '5859', })); const client = new WebSocket('ws://127.0.0.1:3322/remoteDebug?token=' + mockToken); client.on('close', () => done()); @@ -68,6 +70,6 @@ describe('src/core/debugServer/debugServer.ts', () => { after(() => { debugableProcess.kill(); - }) + }); -}); \ No newline at end of file +}); diff --git a/packages/sandbox-core/test/core/manager/metricsManager.test.ts b/packages/sandbox-core/test/core/manager/metricsManager.test.ts index 8ea90f5..d8ae59e 100644 --- a/packages/sandbox-core/test/core/manager/metricsManager.test.ts +++ b/packages/sandbox-core/test/core/manager/metricsManager.test.ts @@ -10,7 +10,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { const latest = MetricsManager.pickLatestDp({ 123: '123', 456: '456', - 1000: 'latest' + 1000: 'latest', }); assert('latest' === latest); }); @@ -19,7 +19,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { const metricsManager: MetricsManager = await getInstance('metricsManager'); const res = await metricsManager.getMetricsNames({ scope: 'test', - scopeName: 'test' + scopeName: 'test', }); assert(res.length === 3); assert(res[0] === 'cpu'); @@ -41,7 +41,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 1 }, { time: 2, value: 1 }, - ] + ], }, { metric: 'testName', @@ -50,7 +50,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 2 }, { time: 2, value: 2 }, - ] + ], }, { metric: 'testName', @@ -59,7 +59,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 3 }, { time: 2, value: 3 }, - ] + ], }, { metric: 'testName', @@ -68,61 +68,61 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 4 }, { time: 2, value: 4 }, - ] + ], }, - ] + ], ); expect(res).to.deep.equal( [ { - "metric": "testName", - "aggregator": "avg", - "frontEndAggregator": "avg", - "trend": [ + metric: 'testName', + aggregator: 'avg', + frontEndAggregator: 'avg', + trend: [ { - "time": 1, - "value": 2.5 + time: 1, + value: 2.5, }, { - "time": 2, - "value": 2.5 - } - ] + time: 2, + value: 2.5, + }, + ], }, { - "metric": "testName", - "aggregator": "avg", - "hostname": "host-c", - "trend": [ + metric: 'testName', + aggregator: 'avg', + hostname: 'host-c', + trend: [ { - "time": 1, - "value": 4 + time: 1, + value: 4, }, { - "time": 2, - "value": 4 - } + time: 2, + value: 4, + }, ], - "frontEndAggregator": "highest" + frontEndAggregator: 'highest', }, { - "metric": "testName", - "aggregator": "avg", - "hostname": "host-a", - "trend": [ + metric: 'testName', + aggregator: 'avg', + hostname: 'host-a', + trend: [ { - "time": 1, - "value": 1 + time: 1, + value: 1, }, { - "time": 2, - "value": 1 - } + time: 2, + value: 1, + }, ], - "frontEndAggregator": "lowest" - } - ] + frontEndAggregator: 'lowest', + }, + ], ); }); @@ -135,7 +135,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 1 }, { time: 2, value: 1 }, - ] + ], }, { metric: 'testName', @@ -144,7 +144,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 2 }, { time: 2, value: 2 }, - ] + ], }, { metric: 'testName', @@ -153,7 +153,7 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 3 }, { time: 2, value: 3 }, - ] + ], }, { metric: 'testName', @@ -162,14 +162,14 @@ describe('test/core/manager/metricsManager.test.ts', () => { trend: [ { time: 1, value: 4 }, { time: 2, value: 4 }, - ] + ], }, ]; const metricsManager: MetricsManager = await getInstance('metricsManager'); const res = metricsManager.frontEndAnalyse( {analyseHigherLower: false}, [{ metric: 'testName', aggregator: 'avg' }], - input + input, ); expect(res).to.be.equal(input); }); @@ -182,66 +182,66 @@ describe('test/core/manager/metricsManager.test.ts', () => { { tags: { hostname: 'host-a', - ip: '192.168.2.1' + ip: '192.168.2.1', }, dps: { 1: 11, 2: 12, 3: 13, - } + }, }, { tags: { hostname: 'host-b', - ip: '192.168.2.2' + ip: '192.168.2.2', }, dps: { 1: 21, 2: 22, 3: 23, - } + }, }, { tags: { hostname: 'host-c', - ip: '192.168.2.3' + ip: '192.168.2.3', }, dps: { 1: 31, 2: 32, 3: 33, - } + }, }, ]; - } + }, }); const res = await metricsManager.getLatestMetricByAppSelectorAndGroupByEachHost( { - metric: 'testName' + metric: 'testName', }, { scope: 'test', - scopeName: 'test' - } + scopeName: 'test', + }, ); expect(res).to.deep.equal( [ { - "hostname": "host-a", - "ip": "192.168.2.1", - "value": 13 + hostname: 'host-a', + ip: '192.168.2.1', + value: 13, }, { - "hostname": "host-b", - "ip": "192.168.2.2", - "value": 23 + hostname: 'host-b', + ip: '192.168.2.2', + value: 23, }, { - "hostname": "host-c", - "ip": "192.168.2.3", - "value": 33 - } - ] + hostname: 'host-c', + ip: '192.168.2.3', + value: 33, + }, + ], ); mm.restore(); }); diff --git a/packages/sandbox-core/test/core/service/metricsService.test.ts b/packages/sandbox-core/test/core/service/metricsService.test.ts index 180d866..26d406a 100644 --- a/packages/sandbox-core/test/core/service/metricsService.test.ts +++ b/packages/sandbox-core/test/core/service/metricsService.test.ts @@ -14,7 +14,7 @@ describe('metricsService.test.ts', () => { const metricsService: MetricsService = await getInstance('metricsService'); const res = await metricsService.getMetricsNames({ scope: 'test', - scopeName: 'test' + scopeName: 'test', }); assert(res.length === 3); assert(res[0] === 'cpu'); @@ -29,7 +29,7 @@ describe('metricsService.test.ts', () => { }); const res = await metricsService.getCustomMetricsNames({ scope: 'test', - scopeName: 'test' + scopeName: 'test', }); expect(res).to.deep.equal(['ok', 'yes', 'custom.xxx']); }); @@ -57,38 +57,38 @@ describe('metricsService.test.ts', () => { metric: 'testName1', query: { metric: 'testName1', - aggregator: 'avg' + aggregator: 'avg', }, dps: { 1: 11, 2: 12, - 3: 13 - } + 3: 13, + }, }, { metric: 'testName2', query: { metric: 'testName2', - aggregator: 'avg' + aggregator: 'avg', }, dps: { 1: 21, 2: 22, - 3: 23 - } + 3: 23, + }, }, - ] - } + ]; + }, }); const res = await metricsService.queryMetricsLatest({ scope: 'test', scopeName: 'test', env: 'test', metricsNames: [ { metric: 'testName1', aggregator: 'avg' }, { metric: 'testName2', aggregator: 'avg' }, - ] + ], }); expect(res).to.deep.equal( - [ { latest: 13 }, { latest: 23 } ] + [ { latest: 13 }, { latest: 23 } ], ); }); @@ -114,38 +114,38 @@ describe('metricsService.test.ts', () => { metric: 'testName1', query: { metric: 'testName1', - aggregator: 'avg' + aggregator: 'avg', }, tags: { hostname: 'host-a', ip: '192.168.1.1', - pid: 1 + pid: 1, }, dps: { 1: 11, 2: 12, - 3: 13 - } + 3: 13, + }, }, { metric: 'testName2', query: { metric: 'testName2', - aggregator: 'avg' + aggregator: 'avg', }, tags: { hostname: 'host-b', ip: '192.168.1.2', - pid: 2 + pid: 2, }, dps: { 1: 21, 2: 22, - 3: 23 - } + 3: 23, + }, }, - ] - } + ]; + }, }); const res = await metricsService.queryMetricsTrend({ scope: 'test', @@ -156,51 +156,51 @@ describe('metricsService.test.ts', () => { metricsNames: [ { metric: 'testName1', aggregator: 'avg' }, { metric: 'testName2', aggregator: 'avg' }, - ] + ], }); expect(res).to.deep.equal([ { - "trend": [ + trend: [ { - "time": 1, - "value": 11 + time: 1, + value: 11, }, { - "time": 2, - "value": 12 + time: 2, + value: 12, }, { - "time": 3, - "value": 13 - } + time: 3, + value: 13, + }, ], - "aggregator": "avg", - "metric": "testName1", - "hostname": "host-a", - "ip": "192.168.1.1", - "pid": 1 + aggregator: 'avg', + metric: 'testName1', + hostname: 'host-a', + ip: '192.168.1.1', + pid: 1, }, { - "trend": [ + trend: [ { - "time": 1, - "value": 21 + time: 1, + value: 21, }, { - "time": 2, - "value": 22 + time: 2, + value: 22, }, { - "time": 3, - "value": 23 - } + time: 3, + value: 23, + }, ], - "aggregator": "avg", - "metric": "testName2", - "hostname": "host-b", - "ip": "192.168.1.2", - "pid": 2 - } + aggregator: 'avg', + metric: 'testName2', + hostname: 'host-b', + ip: '192.168.1.2', + pid: 2, + }, ]); }); @@ -217,49 +217,49 @@ describe('metricsService.test.ts', () => { assert(appSelector.env === 'test'); return [ { - "hostname": "host-a", - "ip": "192.168.2.1", - "value": 13 + hostname: 'host-a', + ip: '192.168.2.1', + value: 13, }, { - "hostname": "host-b", - "ip": "192.168.2.2", - "value": 23 + hostname: 'host-b', + ip: '192.168.2.2', + value: 23, }, { - "hostname": "host-d", - "ip": "192.168.2.4", - "value": 43 - } - ] - } + hostname: 'host-d', + ip: '192.168.2.4', + value: 43, + }, + ]; + }, }); mm(metricsService, 'applicationService', { queryGroups(app) { assert(app.scope === 'test'); assert(app.scopeName === 'test'); return { - 'test': [ + test: [ { name: 'group_1', hosts: [ { ip: '192.168.2.1', - hostname: 'host-a' + hostname: 'host-a', }, { ip: '192.168.2.2', - hostname: 'host-b' + hostname: 'host-b', }, { ip: '192.168.2.3', - hostname: 'host-c' - } - ] - } - ] - } - } + hostname: 'host-c', + }, + ], + }, + ], + }; + }, }); const res = await metricsService.queryHostsMap({ @@ -269,41 +269,39 @@ describe('metricsService.test.ts', () => { metricsNames: [ { metric: 'testName1', aggregator: 'avg' }, { metric: 'testName2', aggregator: 'avg' }, - ] + ], }); expect(res).to.deep.equal([ { - "name": "group_1", - "hosts": [ + name: 'group_1', + hosts: [ { - "ip": "192.168.2.1", - "hostname": "host-a", - "testName1": 13, - "testName2": 13 + ip: '192.168.2.1', + hostname: 'host-a', + testName1: 13, + testName2: 13, }, { - "ip": "192.168.2.2", - "hostname": "host-b", - "testName1": 23, - "testName2": 23 + ip: '192.168.2.2', + hostname: 'host-b', + testName1: 23, + testName2: 23, }, { - "ip": "192.168.2.3", - "hostname": "host-c" - } - ] - } - ] + ip: '192.168.2.3', + hostname: 'host-c', + }, + ], + }, + ], ); expect(calledTimes).to.deep.equal([ { metric: 'testName1', aggregator: 'avg' }, - { metric: 'testName2', aggregator: 'avg' } + { metric: 'testName2', aggregator: 'avg' }, ]); }); - }); - diff --git a/packages/sandbox-core/test/fixtures/config.ts b/packages/sandbox-core/test/fixtures/config.ts index cac85a7..be3bbbc 100644 --- a/packages/sandbox-core/test/fixtures/config.ts +++ b/packages/sandbox-core/test/fixtures/config.ts @@ -18,6 +18,6 @@ export default { }, tsdb: { host: '127.0.0.1', - port: 4242 - } + port: 4242, + }, }; From a7f93199ba6e740e3a4463b2007e53f74d7d91a7 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Thu, 25 Oct 2018 18:02:59 +0800 Subject: [PATCH 25/27] feat: for mvp version, get appList from tsdb --- .../src/lib/manager/applicationManager.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/sandbox-mvp/src/lib/manager/applicationManager.ts diff --git a/packages/sandbox-mvp/src/lib/manager/applicationManager.ts b/packages/sandbox-mvp/src/lib/manager/applicationManager.ts new file mode 100644 index 0000000..92f694d --- /dev/null +++ b/packages/sandbox-mvp/src/lib/manager/applicationManager.ts @@ -0,0 +1,43 @@ +import { provide, inject, config } from 'midway'; +import { ApplicationManager, TSDB } from 'sandbox-core'; + +@provide('applicationManager') +export class OwnApplicationManager extends ApplicationManager { + + @inject('tsdb') + tsdb: TSDB; + + @config('coreMetrics') + coreMetrics; + + async list() { + const metricsNameQps = this.coreMetrics.cpuUsage.metric; + const res = await this.tsdb.query({ + start: '1h-ago', + queries: [ + { + metric: metricsNameQps, + aggregator: 'avg', + downsample: '1h-avg', + tags: { + scope_name: '*', scope: '*', + } + } + ] + }); + const rows: any[] = []; + for(const item of res) { + const tags = item.tags; + const { scope_name, scope } = tags; + rows.push({ + scope: scope, + scopeName: scope_name, + }); + } + return { + rows: rows, + count: rows.length + } + } + +} \ No newline at end of file From 23b3ef959e26ec7566b68d105adeed07c5376bed Mon Sep 17 00:00:00 2001 From: GuangWong Date: Thu, 25 Oct 2018 19:48:00 +0800 Subject: [PATCH 26/27] feat: add coreMetrics unusual config --- packages/sandbox-mvp/src/config/metrics.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/sandbox-mvp/src/config/metrics.ts b/packages/sandbox-mvp/src/config/metrics.ts index 0691ce7..b01ac9f 100644 --- a/packages/sandbox-mvp/src/config/metrics.ts +++ b/packages/sandbox-mvp/src/config/metrics.ts @@ -8,6 +8,9 @@ export const coreMetrics = { metric: 'system.cpu.usage', affix: '%', normalizedValue: true, + unusual: { + gte: 0.8 + } }, load1: { aggregator: 'avg', @@ -18,12 +21,18 @@ export const coreMetrics = { metric: 'system.mem.usage', affix: '%', normalizedValue: true, + unusual: { + gte: 0.7 + } }, diskUsage: { aggregator: 'avg', metric: 'system.disk.partition.used_ratio', affix: '%', normalizedValue: true, + unusual: { + gte: 0.7 + } }, qps: { aggregator: 'sum', @@ -32,6 +41,9 @@ export const coreMetrics = { rt: { aggregator: 'avg', metric: 'system.tsar.nginx_rt', + unusual: { + gte: 2000 + } }, errorCount: { aggregator: 'sum', From dffcce557a057dd558410b208d04cbf5ee1206f7 Mon Sep 17 00:00:00 2001 From: GuangWong Date: Thu, 25 Oct 2018 20:14:21 +0800 Subject: [PATCH 27/27] feat: update metrics configs --- packages/sandbox-mvp/src/app/middleware/assets.ts | 2 +- packages/sandbox-mvp/src/config/metrics.ts | 4 ++-- .../src/config/metricsLayouts/focusLayout.ts | 14 +++++++------- .../src/config/metricsLayouts/systemLayout.ts | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/sandbox-mvp/src/app/middleware/assets.ts b/packages/sandbox-mvp/src/app/middleware/assets.ts index 6806eb8..5dac0aa 100644 --- a/packages/sandbox-mvp/src/app/middleware/assets.ts +++ b/packages/sandbox-mvp/src/app/middleware/assets.ts @@ -1,6 +1,6 @@ export default function assets(options, app) { return async (ctx, next) => { - ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.7/'; + ctx.locals.publicPath = '//g.alicdn.com/midway/sandbox-newui/0.0.8/'; ctx.locals.env = 'prod'; await next(); }; diff --git a/packages/sandbox-mvp/src/config/metrics.ts b/packages/sandbox-mvp/src/config/metrics.ts index b01ac9f..65f50dd 100644 --- a/packages/sandbox-mvp/src/config/metrics.ts +++ b/packages/sandbox-mvp/src/config/metrics.ts @@ -36,11 +36,11 @@ export const coreMetrics = { }, qps: { aggregator: 'sum', - metric: 'system.tsar.nginx_qps', + metric: 'middleware.http.request.qps', }, rt: { aggregator: 'avg', - metric: 'system.tsar.nginx_rt', + metric: 'middleware.http.request.rt', unusual: { gte: 2000 } diff --git a/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts b/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts index 65328c3..b9b2c83 100644 --- a/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts +++ b/packages/sandbox-mvp/src/config/metricsLayouts/focusLayout.ts @@ -2,33 +2,33 @@ export const focusLayout = [{ title: '焦点视图', charts: [ { - title: 'Nginx QPS', + title: 'HTTP Server QPS', indicators: [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.nginx_qps', - title: 'Nginx QPS', + metric: 'middleware.http.request.qps', + title: 'HTTP Server QPS', unit: '次/秒', }, ], }, { - title: 'Nginx RT', + title: 'HTTP Server RT', indicators: [ { type: 'number', aggregator: 'avg', - metric: 'system.tsar.nginx_rt', - title: 'Nginx RT', + metric: 'middleware.http.request.rt', + title: 'HTTP Server RT', unit: 'ms', }, ], }, { - title: '访问成功率', + title: 'HTTP Server 访问成功率', indicators: [ { aggregator: 'avg', diff --git a/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts b/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts index b62b725..0261c78 100644 --- a/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts +++ b/packages/sandbox-mvp/src/config/metricsLayouts/systemLayout.ts @@ -132,25 +132,25 @@ export const systemLayout = [ ], }, { - title: 'Nginx QPS', + title: 'HTTP Server QPS', indicators: [ { type: 'number', aggregator: 'sum', - metric: 'system.tsar.nginx_qps', - title: 'Nginx QPS', + metric: 'middleware.http.request.qps', + title: 'HTTP Server QPS', unit: '次/秒', }, ], }, { - title: 'Nginx RT', + title: 'HTTP Server RT', indicators: [ { type: 'number', aggregator: 'avg', - metric: 'system.tsar.nginx_rt', - title: 'Nginx RT', + metric: 'middleware.http.request.rt', + title: 'HTTP Server RT', unit: 'ms', }, ],