-
Notifications
You must be signed in to change notification settings - Fork 98
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
Refactor and break out top-level filter module. #286
Conversation
This comment has been minimized.
This comment has been minimized.
eae3adc
to
8092b39
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
LGTM! Please let's replace the current wildcard prelude::*
imports with the actual items used in each file
CreateFilterArgs, Filter, FilterRegistry, ReadContext, ReadResponse, WriteContext, | ||
WriteResponse, | ||
}; | ||
use crate::filters::{prelude::*, FilterRegistry}; |
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.
Let's replace the wildcard import with the items themselves?
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.
Hmm, I'm not sure. I think this is a case where a wildcard is beneficial. It's convention that you wildcard import prelude
modules. The prelude also has a pretty tight scope, it's FilterFactory
, and every type in its type signature or used to implement the traits, and you do have to import a lot of types to implement these traits, and we already have a lot of filters, and the number will only grow. For something so common reducing the boilerplate to one-line here is worth it I think.
use quilkin::filters::prelude::*;
struct A;
struct AFactory;
impl FilterFactory for AFactory {
fn name(&self) -> String {
// ...
}
fn create_filter(&self, args: CreateFilterArgs) -> Result<Box<dyn Filter>, Error> {
// …
}
}
impl Filter for A {
fn read(&self, ctx: ReadContext) -> Option<ReadResponse> {
// …
}
fn write(&self, ctx: WriteContext) -> Option<WriteResponse> {
// …
}
}
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.
Discussed on Slack.
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.
Discussed on Slack.
Can you expand here please? Let's please avoid hidden/obfuscated communication channels where possible - or where they take place, take some notes and make sure they are attached to the appropriate place here in Github for an audit trail and historical decision making.
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.
Can you expand here please? Let's please avoid hidden/obfuscated communication channels where possible - or where they take place, take some notes and make sure they are attached to the appropriate place here in Github for an audit trail and historical decision making.
Sure, and I understand that concern. There wasn't actually much of a discussion though more of just a thumbs up, I'll make that more clear next time.
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.
Awesome. Thanks so much!
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.
extensions
is now namedfilters
andextensions::filters
is nowfilters::extensions
🤔 I expect we'll have other pluggable extension points in the future. Originally I would have seen them sit under the extensions
module? I guess, now, not so much? We flip that around to being <thing>/extensions
where <thing>
has the core logic?
src/filters/mod.rs
Outdated
@@ -0,0 +1,75 @@ | |||
/* | |||
* Copyright 2020 Google LLC All Rights Reserved. |
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.
Should this be src/filters.rs
?
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.
Yep, just kept it this way till the switch was merged.
This comment has been minimized.
This comment has been minimized.
Ah right, the idea was that |
Admittedly, this was also a copy of the Envoy package format: |
Well to be honest I'm not sure Extensions in Rust are typically separate crates like if you think about for example |
This comment has been minimized.
This comment has been minimized.
Makes sense to me! I'd be happy to drop the extensions part entirely |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3419a7d
to
bd0a8a1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Build Succeeded 🥳 Build Id: c7363b01-7f2c-4f19-94f7-18d46521a13e To build this version:
|
docs/extensions/filters/filters.md
Outdated
@@ -45,7 +45,7 @@ There are a few things we note here: | |||
### Configuration Examples ### | |||
|
|||
```rust | |||
# // Wrap this example within an async main function since the | |||
# // Wrap this example within an agync main function since the |
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.
# // Wrap this example within an agync main function since the | |
# // Wrap this example within an async main function since the |
Nit: introduced a typo
use crate::filters::{ConfigType, Error, Filter}; | ||
|
||
/// An owned pointer to a dynamic [`FilterFactory`] instance. | ||
pub type DynFilterFactory = Box<dyn FilterFactory>; |
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.
Nice touch 👍🏻
LGTM, just a small nit, and want to capture that decision that was come to offline. That and now we have proc macros, we have a stack of conflicts to resolve 👍🏻 |
Build Succeeded 🥳 Build Id: c41970fe-b7dc-42fe-a582-4e3fdf47e032 To build this version:
|
Build Succeeded 🥳 Build Id: 01c5f0bb-7a83-413e-a7a5-550c8434d18e To build this version:
|
LGTM. @iffyio if you are also good to go, please feel free to merge 👍🏻 |
Build Succeeded 🥳 Build Id: c8e1e582-e64d-4cb5-ba6a-76f234108ac9 To build this version:
|
This is built on-top and replaces the changes in #265 and represents and attempt to split up the
filter_registry.rs
file into more digestible chunks, and easier to search.Changes
filter_registry.rs
's data structures have been split up intoset.rs
,factory.rs
,filters.rs
,config.rs
.filter_chain.rs
renamedchain.rs
.FilterSet
type which acts as the data structure that ensures we have a unique read-only set of filter factories.filters::prelude
, which is a prelude that contains everything you need to implementFilter
andFilterFactory
.extensions
is now namedfilters
andextensions::filters
is nowfilters::extensions
.filters::extensions
besides fixing their imports, those improvements can come in a followup PR.There is no public changes in this PR, other than the addition of the
FilterSet
type, and theprelude
module, all other changes are internal.