Skip to content

Commit

Permalink
Apply message field filter as last check in live
Browse files Browse the repository at this point in the history
  • Loading branch information
graduta committed Oct 5, 2023
1 parent 3b21084 commit 6063a8a
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions InfoLogger/public/logFilter/LogFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,27 @@ export default class LogFilter extends Observable {
return logValue.replace(/\r?\n|\r/g, '');
}

// eslint-disable-next-line guard-for-in
for (const field in criterias) {
const logValue = log[field];

// eslint-disable-next-line guard-for-in
for (const operator in criterias[field]) {
let criteriaValue = criterias[field][operator];
/**
* Function that applies the criteria of one filter set by the user on each received logValue
* @param {Object} logValue - value of the log field that is to be checked (e.g. message, severity, etc.)
* @param {Object} criteria - object containing the criteria if applied by the user
* @param {string} [separator = ' '] - separator to be applied when filtering based on an array of values; `\n` has to be passed in case of message field
* @return {boolean} - result of the log matching the filter set by user
*/
function isLogMatchingMessageCriteria(logValue, criteria, separator = ' ') {
for (const operator in criteria) {
let criteriaValue = criteria[operator];
// don't apply criterias not set
if (criteriaValue === null) {
continue;
}
const separator = field === 'message' ? '\n' : ' ';
// logValue is sometime required, undefined means test fails and log is rejected
switch (operator) {
case '$in':
case '$in': {
if (logValue === undefined || !criteriaValue.includes(logValue)) {
return false;
}
break;
}
case '$match': {
const criteriaList = criteriaValue.split(separator);
if (criteriaList.length > 1) {
Expand Down Expand Up @@ -259,8 +261,23 @@ export default class LogFilter extends Observable {
continue;
}
}
return true;
}
return true;
/*
* Removes the message from the initial filtering as this puts a lot of stress on the server
* Filtering will be done initially on the small contained fields and only later if still needed on the message
*/
const messageCriteria = criterias.message;
delete criterias.message;

for (const field in criterias) {
if (isLogMatchingMessageCriteria(log[field], criterias[field], ' ')) {
continue
} else {
return false;
}
}
return isLogMatchingMessageCriteria(log['message'], messageCriteria, '\n');
}

const criteriasJSON = JSON.stringify(this.criterias);
Expand Down

0 comments on commit 6063a8a

Please sign in to comment.