Skip to content

Commit

Permalink
[RAM] Rule event log - Fix incorrect results when filtering by messag…
Browse files Browse the repository at this point in the history
…e and outcome simultaneously (#143119)

* Fix event log message filtering

* Fix tests

* Fix tests

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
JiaweiWu and kibanamachine authored Oct 20, 2022
1 parent 2eea2c2 commit ad665b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ import { getFilter } from './get_filter';
describe('getFilter', () => {
test('should return message filter', () => {
expect(getFilter({ message: 'test message' })).toEqual([
'message: "test message" OR error.message: "test message"',
'(message: "test message" OR error.message: "test message")',
]);
});

test('should return outcome filter', () => {
expect(getFilter({ outcomeFilter: ['failure', 'warning', 'success', 'unknown'] })).toEqual([
'event.outcome: failure OR kibana.alerting.outcome: warning OR kibana.alerting.outcome:success OR (event.outcome: success AND NOT kibana.alerting.outcome:*) OR event.outcome: unknown',
'(event.outcome: failure OR kibana.alerting.outcome: warning OR kibana.alerting.outcome:success OR (event.outcome: success AND NOT kibana.alerting.outcome:*) OR event.outcome: unknown)',
]);
});

test('should return runId filter', () => {
expect(getFilter({ runId: 'test' })).toEqual(['kibana.alert.rule.execution.uuid: test']);
});

test('should return filter for both message and outcome', () => {
expect(getFilter({ message: 'test message', outcomeFilter: ['failure', 'warning'] })).toEqual([
'(message: "test message" OR error.message: "test message")',
'(event.outcome: failure OR kibana.alerting.outcome: warning)',
]);
});

test('should not return filter if outcome filter is invalid', () => {
expect(getFilter({ outcomeFilter: ['doesntexist'] })).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ export const getFilter = ({

if (message) {
const escapedMessage = message.replace(/([\)\(\<\>\}\{\"\:\\])/gm, '\\$&');
filter.push(`message: "${escapedMessage}" OR error.message: "${escapedMessage}"`);
filter.push(`(message: "${escapedMessage}" OR error.message: "${escapedMessage}")`);
}

if (outcomeFilter && outcomeFilter.length) {
filter.push(getOutcomeFilter(outcomeFilter));
const outcomeFilterKQL = getOutcomeFilter(outcomeFilter);
if (outcomeFilterKQL) {
filter.push(`(${outcomeFilterKQL})`);
}
}

if (runId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('loadActionErrorLog', () => {
"query": Object {
"date_end": "2022-03-23T16:17:53.482Z",
"date_start": "2022-03-23T16:17:53.482Z",
"filter": "message: \\"test\\" OR error.message: \\"test\\" and kibana.alert.rule.execution.uuid: 123",
"filter": "(message: \\"test\\" OR error.message: \\"test\\") and kibana.alert.rule.execution.uuid: 123",
"page": 1,
"per_page": 10,
"sort": "[{\\"@timestamp\\":{\\"order\\":\\"asc\\"}}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ describe('loadExecutionLogAggregations', () => {
id: 'test-id',
dateStart: '2022-03-23T16:17:53.482Z',
dateEnd: '2022-03-23T16:17:53.482Z',
outcomeFilter: ['success'],
outcomeFilter: ['success', 'warning'],
message: 'test-message',
perPage: 10,
page: 0,
sort: [sortTimestamp],
Expand Down Expand Up @@ -84,7 +85,7 @@ describe('loadExecutionLogAggregations', () => {
"query": Object {
"date_end": "2022-03-23T16:17:53.482Z",
"date_start": "2022-03-23T16:17:53.482Z",
"filter": "kibana.alerting.outcome:success OR (event.outcome: success AND NOT kibana.alerting.outcome:*)",
"filter": "(message: \\"test-message\\" OR error.message: \\"test-message\\") and (kibana.alerting.outcome:success OR (event.outcome: success AND NOT kibana.alerting.outcome:*) OR kibana.alerting.outcome: warning)",
"page": 1,
"per_page": 10,
"sort": "[{\\"timestamp\\":{\\"order\\":\\"asc\\"}}]",
Expand Down

0 comments on commit ad665b1

Please sign in to comment.