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

filters: fix event type filters #404

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

willfindlay
Copy link
Contributor

CONTAINS CHANGES TO PROTOBUF API, see first commit.

Our EventType enum numbers were being kept in sync with opcodes from the BPF side, but we
were only using these to implement event type filters on tyhe protobuf side which we were
matching against protobuf events anyway. We used to do this by converting to an opcode
using a switch statement but this was not ideal because it was error prone and required the
person adding a new event type to go into filters.go and edit the switch statement.

A follow up patch (1755bc3) attempted to simplify this by using reflection but the
approach was fundamentally flawed because the reflected type would always match
tetragon.EventType, meaning the filters would _never_ match.

Here I propose a much simpler approach. First, we change the event type enum numbers to
match their oneof counterpart in the GetEventsResponse. A follow-up patch will then use
these numbers to determine whether the event type actually matches.

Signed-off-by: William Findlay <[email protected]>
The previous commit in this series explained how our current approach to event type
filtering was totally broken. This commit rectifies the bug by simply using protobuf
numbers to determine event type for filtering.

Signed-off-by: William Findlay <[email protected]>
Our event type filters were broken for two months and nobody noticed, probably because we
didn't really have a unit test for it. This commit adds a some simple unit tests to make
sure event type filters work.

Signed-off-by: William Findlay <[email protected]>
@willfindlay willfindlay requested a review from a team as a code owner September 13, 2022 16:49
@willfindlay willfindlay marked this pull request as draft September 14, 2022 17:13
@willfindlay
Copy link
Contributor Author

Converting to draft while I discuss with some folks offline whether the breaking changes are worth it.

@willfindlay willfindlay marked this pull request as ready for review September 14, 2022 17:22
This commit introduces two new field filters for GetEventsRequest. These allow the user to
optionally specify a set of paths that should be included/excluded from the
GetEventsResponse where exclusion takes precedence over inclusion. Leaving the filters
empty will keep the default behaviour of including all fields in the GetEventsResponse.
Filters are specified using period-separated names as they appear in protobuf JSON (i.e.
lower snake case).

This new filtering mechanism has several use cases, for example filtering out unwanted
noisy fields from events in a customer environment or implementing functionality that
transforms events for further processing (for example an event recorder that filters out
noise).

Signed-off-by: William Findlay <[email protected]>
@willfindlay willfindlay merged commit 89404bc into main Sep 15, 2022
@willfindlay willfindlay deleted the pr/willfindlay/fix-event-type-filter branch September 15, 2022 18:22
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.

3 participants