Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add monitoring and reportMisbehavior plugin setups - Closes #5876 and #5291 #5892

Merged
merged 3 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Jenkinsfile.sdk
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pipeline {
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:ci --ignore lisk-{framework,commander}'
sh 'npx lerna run test:ci --ignore lisk-{framework,commander,@liskhq/lisk-framework-*}'
}
}
post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"blockchain",
"forging"
],
"homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/framework-plugin/lisk-framework-forger-plugin#readme",
"homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/framework-plugins/lisk-framework-forger-plugin#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/LiskHQ/lisk-sdk.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lisk",
"blockchain"
],
"homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/framework-plugin/lisk-framework-http-api-plugin#readme",
"homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/framework-plugins/lisk-framework-http-api-plugin#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/LiskHQ/lisk-sdk.git"
Expand Down
3 changes: 3 additions & 0 deletions framework-plugins/lisk-framework-monitor-plugin/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist-node
jest.config.js
.eslintrc.js
7 changes: 7 additions & 0 deletions framework-plugins/lisk-framework-monitor-plugin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: '../../.eslintrc.js',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
};
1 change: 1 addition & 0 deletions framework-plugins/lisk-framework-monitor-plugin/.npmignore
1 change: 1 addition & 0 deletions framework-plugins/lisk-framework-monitor-plugin/.npmrc
61 changes: 61 additions & 0 deletions framework-plugins/lisk-framework-monitor-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# @liskhq/lisk-framework-monitor-plugin

@liskhq/lisk-framework-monitor-plugin is a plugin for lisk-framework that provides network statistics of the running node.

## Installation

```sh
$ npm install --save @liskhq/lisk-framework-monitor-plugin
```

## Config Options

```
{
port?: number,
whiteList?: string[],
webhook?: string[],
cors?: {
origin: string,
methods: string,
},
limits?: {
max: number,
delayMs: number,
delayAfter: number,
windowMs: number,
headersTimeout: number,
serverSetTimeout: number,
},
dataPath?: string,
}
```

## License

Copyright 2016-2020 Lisk Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

---

Copyright © 2016-2020 Lisk Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[lisk core github]: https://github.com/LiskHQ/lisk
[lisk documentation site]: https://lisk.io/documentation/lisk-elements
72 changes: 72 additions & 0 deletions framework-plugins/lisk-framework-monitor-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@liskhq/lisk-framework-monitor-plugin",
"version": "0.1.0",
"description": "A plugin for lisk-framework that provides network statistics of the running node",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
"keywords": [
"lisk",
"blockchain"
],
"homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/framework-plugins/lisk-framework-monitor-plugin#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/LiskHQ/lisk-sdk.git"
},
"bugs": {
"url": "https://github.com/LiskHQ/lisk-sdk/issues"
},
"engines": {
"node": ">=12.13.0 <=12",
"npm": ">=6.12.0"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
"format": "prettier --write '**/*'",
"lint": "eslint --ext .js,.ts .",
"lint:fix": "eslint --fix --ext .js,.ts .",
"test": "jest",
"test:coverage": "jest --coverage=true --coverage-reporters=text",
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
"test:watch": "npm test -- --watch",
"prebuild": "rm -r dist-node/* || mkdir dist-node || true",
"build": "tsc",
"build:check": "node -e \"require('./dist-node')\"",
"prepublishOnly": "npm run lint && npm test && npm run build && npm run build:check"
},
"dependencies": {
"@liskhq/lisk-utils": "^0.1.0-alpha.1",
"@liskhq/lisk-validator": "^0.5.0-alpha.0",
"cors": "2.8.5",
"express": "4.17.1",
"express-rate-limit": "5.1.3",
"ip": "1.1.5",
"lisk-framework": "^0.7.0-alpha.3"
},
"devDependencies": {
"@types/cors": "2.8.6",
"@types/express": "4.17.6",
"@types/express-rate-limit": "5.0.0",
"@types/ip": "1.1.0",
"@types/jest": "26.0.13",
"@types/jest-when": "2.7.1",
"@types/node": "12.12.11",
"@typescript-eslint/eslint-plugin": "3.10.1",
"@typescript-eslint/parser": "3.10.1",
"eslint": "7.8.1",
"eslint-config-lisk-base": "1.2.2",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "24.0.0",
"jest": "26.4.2",
"jest-extended": "0.11.5",
"jest-when": "2.7.2",
"prettier": "2.0.5",
"source-map-support": "0.5.19",
"ts-jest": "26.3.0",
"ts-node": "8.6.2",
"tsconfig-paths": "3.9.0",
"typescript": "3.8.3"
}
}
1 change: 1 addition & 0 deletions framework-plugins/lisk-framework-monitor-plugin/scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export const defaultConfig = {
type: 'object',
properties: {
port: {
type: 'integer',
minimum: 1,
maximum: 65535,
},
whiteList: {
type: 'array',
items: {
type: 'string',
},
},
cors: {
type: 'object',
properties: {
origin: {
anyOf: [{ type: 'string' }, { type: 'boolean' }],
},
methods: {
type: 'array',
},
},
required: ['origin'],
},
limits: {
type: 'object',
properties: {
max: {
type: 'integer',
},
delayMs: {
type: 'integer',
},
delayAfter: {
type: 'integer',
},
windowMs: {
type: 'integer',
},
headersTimeout: {
type: 'integer',
minimum: 1,
maximum: 40000,
},
serverSetTimeout: {
type: 'integer',
minimum: 1,
maximum: 120000,
},
},
required: ['max', 'delayMs', 'delayAfter', 'windowMs', 'headersTimeout', 'serverSetTimeout'],
},
},
required: ['port', 'whiteList', 'cors', 'limits'],
default: {
port: 4003,
whiteList: ['127.0.0.1'],
cors: {
origin: '*',
methods: ['GET', 'POST', 'PUT'],
},
limits: {
max: 0,
delayMs: 0,
delayAfter: 0,
windowMs: 60000,
headersTimeout: 5000,
serverSetTimeout: 20000,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export * from './default_config';
15 changes: 15 additions & 0 deletions framework-plugins/lisk-framework-monitor-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export { MonitorPlugin } from './monitor_plugin';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/
import { Request, Response, NextFunction } from 'express';

interface ErrorWithDetails extends Error {
errors: Error[];
}

export const errorMiddleware = () => (
err: Error | Error[] | ErrorWithDetails,
_req: Request,
res: Response,
_next: NextFunction,
): void => {
let errors;

if (Array.isArray(err)) {
errors = err;
} else if ((err as ErrorWithDetails).errors) {
errors = (err as ErrorWithDetails).errors;
} else {
errors = [err];
}

for (const error of errors) {
// Include message property in response
Object.defineProperty(error, 'message', { enumerable: true });
}

res.status(500).send({ errors });
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright © 2020 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export * from './whitelist';
export * from './errors';
Loading