Skip to content

feat: for mvp version, get appList from tsdb #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: preparation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9a46c3d
chore: update midway version
guangwong Oct 12, 2018
cdaf389
chore: change config
guangwong Oct 12, 2018
bfc3fdb
chore: update built-in assets version
guangwong Oct 12, 2018
b9ecc25
chore: use old version ws
guangwong Oct 12, 2018
6c2a63a
chore: update configs
guangwong Oct 12, 2018
d262173
chore: update configs
guangwong Oct 12, 2018
d4b8420
fix: fix wrong mode config
guangwong Oct 13, 2018
7650866
v0.0.2
guangwong Oct 15, 2018
ef4f781
test: add run cov
guangwong Oct 16, 2018
3fa8c0d
test: use blank password
guangwong Oct 16, 2018
5e5f1d2
test: init db
guangwong Oct 16, 2018
2dec4d4
test: fix test issue
guangwong Oct 16, 2018
bae7b8e
chore: add code cov
guangwong Oct 16, 2018
981ba7e
chore: add more test cov reporter
guangwong Oct 16, 2018
a9675f9
chore: mark hook executable
guangwong Oct 16, 2018
c9b54fc
chore: update cov.sh
guangwong Oct 16, 2018
bcbbfc3
test: add test cases
Oct 22, 2018
e505cfa
test: add test cases
Chunlin-Li Oct 22, 2018
805ec2e
chore: travis timezone
Chunlin-Li Oct 22, 2018
f2ade86
test: add test cases
Chunlin-Li Oct 22, 2018
2f1fce0
Merge pull request #1 from Chunlin-Li/test
guangwong Oct 23, 2018
32b1a84
test: add test for metricsManager
guangwong Oct 23, 2018
234a316
test: add test for metricsService
guangwong Oct 23, 2018
5977974
Merge pull request #2 from midwayjs/metrics_test
Chunlin-Li Oct 23, 2018
9f2c61b
Merge branch 'preparation' of github.com:midwayjs/sandbox into prepar…
Chunlin-Li Oct 23, 2018
c4f2e24
test: debugServer test case
Chunlin-Li Oct 23, 2018
46299e8
style: tslint
Chunlin-Li Oct 23, 2018
f9e470c
Merge pull request #3 from Chunlin-Li/preparation
guangwong Oct 24, 2018
a7f9319
feat: for mvp version, get appList from tsdb
guangwong Oct 25, 2018
23b3ef9
feat: add coreMetrics unusual config
guangwong Oct 25, 2018
dffcce5
feat: update metrics configs
guangwong Oct 25, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .githooks/pre-commit/filter.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ assembly/
mocks_data/proxy/**/__*
tms
coverage
.nyc_output

############################
# visual studio code settings
Expand Down
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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
- export TZ=Asia/Shanghai
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
after_script:
- codecov
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "0.0.1"
"version": "0.0.2"
}
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
"name": "sandbox",
"private": true,
"devDependencies": {
"nyc": "^11.2.1",
"git-hooks": "^1.1.10",
"lerna": "^3.4.0"
},
"nyc": {
"reporter": [
"text",
"json",
"html",
"lcovonly"
]
},
"scripts": {
"build": "lerna run build"
"bootstrap": "lerna bootstrap --no-ci",
"build": "lerna run build",
"cov": "sh scripts/cov.sh"
}
}
9 changes: 6 additions & 3 deletions packages/sandbox-core/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -38,7 +40,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",
Expand Down
4 changes: 2 additions & 2 deletions packages/sandbox-core/src/core/debugServer/debugServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions packages/sandbox-core/src/core/manager/errorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
62 changes: 18 additions & 44 deletions packages/sandbox-core/src/core/model/dw/sandboxGalaxySlsTraces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
89 changes: 89 additions & 0 deletions packages/sandbox-core/test/app/controller/applicationCtrl.test.ts
Original file line number Diff line number Diff line change
@@ -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',
},
});
});
});
50 changes: 50 additions & 0 deletions packages/sandbox-core/test/app/controller/errorCtrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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),
},
},
});
});
});
18 changes: 18 additions & 0 deletions packages/sandbox-core/test/core/debugServer/cipher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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);
});

});
Loading