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

Check rulesets first #1126

Merged
merged 3 commits into from
May 24, 2018
Merged

Check rulesets first #1126

merged 3 commits into from
May 24, 2018

Conversation

mstemm
Copy link
Contributor

@mstemm mstemm commented May 22, 2018

Improve performance for the common use case of iterating over a bunch of rulesets and calling sinsp_evttype_filter::run() for each, by grouping filters by ruleset first. Check the first commit for details on the change.

mstemm added 2 commits May 21, 2018 20:18
Change how rulesets are organized in sinsp_evttype_filter. Previously
the primary index into the set of filters was by event type. For filters
matching an event type, each would be considered to see if they were
relevant for a given ruleset, and if so, the filter would be run.

This ends up being inefficient for the use case of iterating over
rulesets, as you end up traversing the list of filters for a given event
type N times for N rulesets.

Instead, add a new object ruleset_filters which holds the set of filters
for a given ruleset. The lists of filters indexed by evttype/syscall
id move from the main object to the ruleset_filters object.

Also, get rid of the notion of "catchall" filters. If a filter really
should apply for all evttypes/syscalls, it just gets included in every
m_filter_by_{evttype,syscall} list. Catchall filters are highly
discouraged and don't exist for the default falco ruleset, so it's ok to
not have a special case for it. This ends up significantly simplifying
::run(), as you can iterate over a single list instead of two and don't
need to keep track of any order value for a given filter.
While running some tests using valgrind, I noticed that a value from a
node that was removed due to a shorter path matching a value wasn't
being deleted.
@mstemm mstemm requested a review from mattpag May 22, 2018 05:28
Copy link
Contributor

@mattpag mattpag left a comment

Choose a reason for hiding this comment

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

lgtm, great improvement!

Previously, a filter would be added to a rulset when enable was set to
true, but nothing was done if enable was set to false.

Fix this by actually removing the filter via a new method
rulset_filters::remove_filter.
@mstemm
Copy link
Contributor Author

mstemm commented May 23, 2018

Could you take a look at the addl commit from today that properly handles removing filters for a tag/regex?

@mattpag
Copy link
Contributor

mattpag commented May 24, 2018

Looks good.
After disabling a tag/regex it will be possible to safely re-enable it because the wrappers will be still stored in m_filters, right?

On a more general note, why can't we switch the wrappers evttype/syscallID vectors to sets? There would be no need to do a loop of all event types/syscalls every time we need to use them.

@mstemm
Copy link
Contributor Author

mstemm commented May 24, 2018

Right, all the filters ever added are in m_filters, and copies of those pointers are spread amongst the rulesets.

I think m_filter_by_syscall/m_filter_by_evttype need to be vectors so you can efficiently find the right list of filters in sinsp_evttype_filter::ruleset_filters::run. If you mean evttypes_for_ruleset()/syscalls_for_ruleset(), you're right, those could be sets, but it requires changing both falco and the agent to use it properly. So I'm ok with also making that change, but let me do it separately so I can get this merged. I filed falcosecurity/falco#369 to track that.

@mstemm mstemm merged commit b3fe25a into dev May 24, 2018
@mstemm mstemm deleted the check-rulesets-first branch May 24, 2018 18:42
mstemm added a commit to falcosecurity/falco that referenced this pull request Jun 7, 2018
Previously, rules were enabled by default. Some performance improvements
in draios/sysdig#1126 broke this, requiring that
each rule is explicitly enabled or disabled for a given ruleset.

So if enabled is true, explicitly enable the rule for the default ruleset.
mstemm added a commit to falcosecurity/falco that referenced this pull request Jun 8, 2018
* Proactively enable rules instead of only disabling

Previously, rules were enabled by default. Some performance improvements
in draios/sysdig#1126 broke this, requiring that
each rule is explicitly enabled or disabled for a given ruleset.

So if enabled is true, explicitly enable the rule for the default ruleset.

* Get rid of shadowed res variable.

It was used both for the inspector loop and the falco result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants