Filtering and Sampling
Events are like eyebrows, sometimes it’s best to just get rid of them. Filtering events in Wombat is both easy and
flexible, this cookbook demonstrates a few different types of filtering you can do. All of these examples make use of
the mapping
processor but shouldn’t require any prior knowledge.
The Basic Filter
Dropping events with Bloblang is done by mapping the function deleted()
to the root
of the
mapped document. To remove all events indiscriminately you can simply do:
But that’s most likely not what you want. We can instead only delete an event under certain conditions with a
match
or if
expression:
The above config removes any events where:
- The metadata field
topic
is equal tofoo
- The event field
doc.type
(a string) is equal tobar
- The event field
doc.urls
(an array) contains the stringhttps://wombat.dev/
Events that do not match any of these conditions will remain unchanged.
Sample Events
Another type of filter we might want is a sampling filter, we can do that with a random number generator:
We can also do this in a deterministic way by hashing events and filtering by that hash value: