Skip to content
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

[RAM] Rule event log - Fix incorrect results when filtering by message and outcome simultaneously #143119

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
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 = ({

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see in this file this line: // TODO (Jiawei): Use node builder instead of strings
Maybe it's good place to fix it?
Or maybe we have separate ticket I do not know about.:-)

Copy link
Contributor Author

@JiaweiWu JiaweiWu Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm maybe you're right, we might as well do it or else it will never get done haha

edit: will create another ticket and do the refactor there

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