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

Refactor and break out top-level filter module. #286

Merged
merged 3 commits into from
Jun 17, 2021
Merged

Conversation

XAMPPRocky
Copy link
Collaborator

@XAMPPRocky XAMPPRocky commented Jun 2, 2021

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 into set.rs, factory.rs, filters.rs, config.rs.
  • filter_chain.rs renamed chain.rs.
  • Added the FilterSet type which acts as the data structure that ensures we have a unique read-only set of filter factories.
  • Added a new filters::prelude, which is a prelude that contains everything you need to implement Filter and FilterFactory.
  • extensions is now named filters and extensions::filters is now filters::extensions.
    • I've deliberately not touched anything in 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 the prelude module, all other changes are internal.

@XAMPPRocky XAMPPRocky requested review from markmandel and iffyio June 2, 2021 09:35
@google-cla google-cla bot added the cla: yes label Jun 2, 2021
@quilkin-bot

This comment has been minimized.

@XAMPPRocky XAMPPRocky force-pushed the filter-reorg branch 2 times, most recently from eae3adc to 8092b39 Compare June 2, 2021 11:17
@quilkin-bot

This comment has been minimized.

@quilkin-bot

This comment has been minimized.

Copy link
Collaborator

@iffyio iffyio left a 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};
Copy link
Collaborator

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?

Copy link
Collaborator Author

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> {
        // …
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussed on Slack.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Screenshot 2021-06-16 at 08 29 17

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome. Thanks so much!

src/filters/factory.rs Show resolved Hide resolved
Copy link
Contributor

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

  • extensions is now named filters and extensions::filters is now filters::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/extensions.rs Show resolved Hide resolved
@@ -0,0 +1,75 @@
/*
* Copyright 2020 Google LLC All Rights Reserved.
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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.

@quilkin-bot

This comment has been minimized.

@iffyio
Copy link
Collaborator

iffyio commented Jun 2, 2021

  • extensions is now named filters and extensions::filters is now filters::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?

Ah right, the idea was that filters is an extension to quilkin rather, coming to think of it then 'filters/extensions' won't make as much sense - the current 'filters/extensions' contains the actual filters themselves which makes the extensions part redundant. maybe we can keep 'extensions/filters' if we think there'll be more kinds of extensions to quilkin in the future, or we can get rid of 'extensions' entirely and just say filters?

@markmandel
Copy link
Contributor

  • extensions is now named filters and extensions::filters is now filters::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?

Ah right, the idea was that filters is an extension to quilkin rather, coming to think of it then 'filters/extensions' won't make as much sense - the current 'filters/extensions' contains the actual filters themselves which makes the extensions part redundant. maybe we can keep 'extensions/filters' if we think there'll be more kinds of extensions to quilkin in the future, or we can get rid of 'extensions' entirely and just say filters?

Admittedly, this was also a copy of the Envoy package format:
https://github.com/envoyproxy/envoy/tree/main/source/extensions

@XAMPPRocky
Copy link
Collaborator Author

XAMPPRocky commented Jun 3, 2021

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 /extensions where has the core logic?

Well to be honest I'm not sure extensions makes sense as part of the module structure at all in Rust, not that we can't have other pluggable points in the future, I just don't feel like they need to prefixed with extensions. "Extension" implies to me that's it somehow opt-in and separate from the core logic, where as these are the defaults and you have to opt out of them. Especially the filter traits, these feel core to quilkin, as it's not like you can opt-out of the filter traits when using quilkin as a library.

Extensions in Rust are typically separate crates like if you think about for example serde is a set of traits and serde-json is an implementation of those traits. If someone wrote a quilkin-dtls or quilkin-load-balancer crate that implements the Filter traits, that would be a filter extension in my mind.

@quilkin-bot

This comment has been minimized.

@iffyio
Copy link
Collaborator

iffyio commented Jun 3, 2021

Well to be honest I'm not sure extensions makes sense as part of the module structure at all in Rust, not that we can't have other pluggable points in the future, I just don't feel like they need to prefixed with extensions

Makes sense to me! I'd be happy to drop the extensions part entirely

@quilkin-bot

This comment has been minimized.

@quilkin-bot

This comment has been minimized.

@quilkin-bot

This comment has been minimized.

@XAMPPRocky XAMPPRocky requested review from markmandel and iffyio June 4, 2021 15:20
@XAMPPRocky XAMPPRocky force-pushed the filter-reorg branch 2 times, most recently from 3419a7d to bd0a8a1 Compare June 14, 2021 08:33
@quilkin-bot

This comment has been minimized.

@quilkin-bot

This comment has been minimized.

@quilkin-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: c7363b01-7f2c-4f19-94f7-18d46521a13e

To build this version:

git fetch git@github.com:googleforgames/quilkin.git pull/286/head:pr_286 && git checkout pr_286
cargo build

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# // 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>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice touch 👍🏻

@markmandel
Copy link
Contributor

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 👍🏻

@quilkin-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: c41970fe-b7dc-42fe-a582-4e3fdf47e032

To build this version:

git fetch git@github.com:googleforgames/quilkin.git pull/286/head:pr_286 && git checkout pr_286
cargo build

@quilkin-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: 01c5f0bb-7a83-413e-a7a5-550c8434d18e

To build this version:

git fetch git@github.com:googleforgames/quilkin.git pull/286/head:pr_286 && git checkout pr_286
cargo build

@markmandel
Copy link
Contributor

LGTM. @iffyio if you are also good to go, please feel free to merge 👍🏻

@quilkin-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: c8e1e582-e64d-4cb5-ba6a-76f234108ac9

To build this version:

git fetch git@github.com:googleforgames/quilkin.git pull/286/head:pr_286 && git checkout pr_286
cargo build

@XAMPPRocky XAMPPRocky merged commit 426aa60 into main Jun 17, 2021
@XAMPPRocky XAMPPRocky deleted the filter-reorg branch June 17, 2021 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants