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

let user function invoke before event skip due to not matching conten… #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export const prefilterOnEventTypes = (rules) =>
export const filterOnContent = (rule, uow) => {
/* istanbul ignore else */
if (rule.filters) {
return rule.filters.reduce((a, c) => a && c(uow, rule), true);
const isSuccess = rule.filters.reduce((a, c) => a && c(uow, rule), true);
// Invoke custom function incase of filter conditions are not statisfied
// For example to create cloudwatch metric in case of failure
if (!isSuccess && rule.errorFilter) {
rule.errorFilter(uow);
}
return isSuccess;
} else {
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion test/unit/filters/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ describe('filters/index.js', () => {
});

it('should filter on compound content', () => {
const errorFilter = (uow) => { uow.isSkipped = true; };
const rule = {
filters: [
(uow, r) => uow.event.tags.f1 === r.value,
(uow, r) => uow.event.tags.f2 === r.value,
],
errorFilter,
value: 'v1',
};

expect(filterOnContent(rule, { event: { tags: { f1: 'v1', f2: 'v1' } } })).to.be.true;
expect(filterOnContent(rule, { event: { tags: { f1: 'v2', f2: 'v1' } } })).to.be.false;
const event = { event: { tags: { f1: 'v2', f2: 'v1' } } };
expect(filterOnContent(rule, event)).to.be.false;
expect(event.isSkipped).to.be.true;
expect(filterOnContent(rule, { event: { tags: { f1: 'v1', f2: 'v2' } } })).to.be.false;
});
});