-
Notifications
You must be signed in to change notification settings - Fork 99
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
Add StaticFilter
trait
#515
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
3f7680f
to
173acca
Compare
This comment was marked as outdated.
This comment was marked as outdated.
173acca
to
11f7649
Compare
This comment was marked as outdated.
This comment was marked as outdated.
11f7649
to
0a643a9
Compare
This comment was marked as outdated.
This comment was marked as outdated.
0a643a9
to
0db0622
Compare
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice refactor!!!
The "writing a customer filter" documentation needs a once over to update to this new architecture though (you may well have been waiting to do that post initial review).
Static: serde::Serialize | ||
+ for<'de> serde::Deserialize<'de> | ||
+ TryFrom<Dynamic, Error = ConvertProtoConfigError>, | ||
BinaryConfiguration: prost::Message + Default, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a nice renaming 👍🏻
+ for<'de> serde::Deserialize<'de> | ||
+ TryFrom<Dynamic, Error = ConvertProtoConfigError>, | ||
BinaryConfiguration: prost::Message + Default, | ||
TextConfiguration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringConfiguration
? (Rather than TextConfiguration
)?
Just a possible suggestion, non-blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose Text
over String
because String
is a specific type in Rust as opposed to just "human readable", and it's shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a nice way to implement filters!
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
1 similar comment
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
783c27e
to
8032d4d
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
Co-authored-by: Mark Mandel <[email protected]>
8032d4d
to
f967415
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
f967415
to
6f02988
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice documentation update, I think it's great to have the fully working code example in examples
and making the implementation details clearer. Also nice with example on how to test the filter with nc
!
6f02988
to
7d78528
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
7d78528
to
1235a9b
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
1235a9b
to
49adc6a
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
49adc6a
to
8f19986
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
8f19986
to
524afa6
Compare
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
Build Succeeded 🥳 Build Id: 65b0ff9a-f7a0-49d3-86e5-5588731e0a74 To build this version:
|
This PR is borne out of initially an effort to pull the
yaml_to_protobuf
changes toFilterFactory
from #506 into a separate PR, and also add aprotobuf_to_yaml
method. However adding another new method was pretty tedious, and when thinking more holistically about the problem of converting configuration back and forth from YAML and Protobuf, I realised that we needed a more generic solution that would allow us to statically only define the types and have the same dynamic behaviour.This thought process led me to this PR which adds a new
StaticFilter
trait which does exactly that. Now if you're writing a filter in Rust you no longer have to define aFilterFactory
to construct it, you only implementStaticFilter
andFilter
, and then Quilkin will automatically at compile-time generate a virtual table safe version ofStaticFilter
(still calledFilterFactory
for the sake of not changing everything all at once).This new trait design effectively eliminates all boilerplate needed when defining your own filter. For example; this is entire definition for the
Compress
as a filter (excluding the actualFilter
impl). As shown, nearly everything is defined statically with types and constants, the only behaviour needed to be implemented is converting from anOption<Self::Configuration>
into aSelf
.It's hard to understate how much this single abstraction saves in terms of time and effort. The seperation provides two key things, the most obvious of which is mostly type-based API that is verified at compile-time for getting access to a filter and its configuration. The second benefit is that having a seperate trait allows us to split the dynamic dispatch
FilterFactory
functionality, this means that changes toFilterFactory
have no affect onStaticFilter
definitions. This is how this PR is able to add two safely add newFilterFactory
methods which allow you to dynamically transcode the configuration format, and for it to still be net negative in terms of code added.Breaking Changes
StaticFilter::NAME
.factory
free function, useStaticFilter::factory
to achieve the same effect.