Add LOG_LIMIT to limit max log response size

Re-adds the log limit feature that limits the log size coming back from embark

Also adds the log limit to other process logs (ie blockchain).
This commit is contained in:
emizzle 2018-10-12 11:59:30 +11:00 committed by Pascal Precht
parent 64713254f6
commit 145f376000
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 9 additions and 6 deletions

View File

@ -108,7 +108,7 @@ export const commands = {
export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS');
export const processLogs = {
request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}),
request: (processName, limit) => action(PROCESS_LOGS[REQUEST], {processName, limit}),
success: (processLogs) => action(PROCESS_LOGS[SUCCESS], {processLogs}),
failure: (error) => action(PROCESS_LOGS[FAILURE], {error})
};

View File

@ -1 +1,2 @@
export const EMBARK_PROCESS_NAME = 'embark';
export const EMBARK_PROCESS_NAME = 'embark';
export const LOG_LIMIT = 50;

View File

@ -14,7 +14,7 @@ import {
import DataWrapper from "../components/DataWrapper";
import Processes from '../components/Processes';
import Console from '../components/Console';
import {EMBARK_PROCESS_NAME} from '../constants';
import {EMBARK_PROCESS_NAME, LOG_LIMIT} from '../constants';
import ContractsList from '../components/ContractsList';
import {getContracts, getProcesses, getProcessLogs} from "../reducers/selectors";
@ -39,10 +39,10 @@ class HomeContainer extends Component {
if (processName === EMBARK_PROCESS_NAME) {
if (this.props.processLogs.length === 0) {
this.props.fetchProcessLogs(processName);
this.props.fetchProcessLogs(processName, LOG_LIMIT);
}
} else {
this.props.fetchProcessLogs(processName);
this.props.fetchProcessLogs(processName, LOG_LIMIT);
this.props.listenToProcessLogs(processName);
}

View File

@ -85,7 +85,9 @@ class ProcessLauncher {
'get',
apiRoute,
(_req, res) => {
const result = self.logs.map((log, id) => Object.assign(log, {id})).slice(-50);
let limit = parseInt(req.query.limit, 10);
if(!Number.isInteger(limit)) limit = 0;
const result = self.logs.map((log, id) => Object.assign(log, {id})).slice(limit);
res.send(JSON.stringify(result));
}
);