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

Add matches filter #447

Merged
merged 10 commits into from
Feb 4, 2022
Merged

Add matches filter #447

merged 10 commits into from
Feb 4, 2022

Conversation

XAMPPRocky
Copy link
Collaborator

@XAMPPRocky XAMPPRocky commented Nov 29, 2021

Adds a minimal version of the quilkin matches filter discussed in #401.

I believe closes #401, #412

Breaking Changes

  • ConfigType::Static now accepts serde_yaml::Value by value instead of by reference.

@google-cla google-cla bot added the cla: yes label Nov 29, 2021
@XAMPPRocky XAMPPRocky force-pushed the matches-filter branch 2 times, most recently from 8ef0f9f to ac6d900 Compare November 30, 2021 09:35
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/metadata.rs Show resolved Hide resolved
src/proxy/health.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Show resolved Hide resolved
src/filters/matches.rs Show resolved Hide resolved
tests/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/set.rs Show resolved Hide resolved
src/proxy/health.rs Outdated Show resolved Hide resolved
src/metadata.rs Outdated Show resolved Hide resolved
@XAMPPRocky
Copy link
Collaborator Author

I've updated the tests, and add one new feature to the Matches filter, which is the addition of fallthrough, which behaves like fallthrough in programming languages, except you have the options for "drop" for dropping packets if none match, "pass" for allowing passthrough, and "filter" which allows you to run a specific filter when nothing matches.

I've not added a test for the write side of the filter because currently the only filter we have that populates easily populates metadata is CaptureBytes and that does not support capturing from the write side (maybe it should?), when we have something that does, I can add it in a followup PR.

@XAMPPRocky XAMPPRocky force-pushed the matches-filter branch 2 times, most recently from b36acbe to c5f4bbe Compare December 13, 2021 10:48
src/config/config_type.rs Show resolved Hide resolved
config.ok_or_else(|| Error::MissingConfig(self.name()))
}
}

/// Arguments needed to create a new filter.
pub struct CreateFilterArgs<'a> {
pub struct CreateFilterArgs {
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 call out in the PR description that is a breaking change, so its visible in the release docs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added the label, which I believe is what @markmandel is using.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we need the label too! What I meant was in this case the label isn't enough since the breakage isn't obvious at all from the PR - usually with a release folks will go through the breaking PRs (which is where the label comes in) and it should be clear what broke. Here that won't be possible at all without reading the code which would be harsh, so let's mention that this PR does in fact contain a breaking change since adding a Matches filter isn't breaking in itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please - add a note about this in the description, so when i write the release notes I won't forget 👍🏻

src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
src/filters/matches.rs Outdated Show resolved Hide resolved
/// The filter specified in `filter` will be called.
Filter {
filter: String,
config: Option<ConfigType>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can be Option<serde_yaml::Value> rather than a full config type or? since this is only used for the yaml config? in which case it probably allows us to avoid the custom serde we have for fallthrough? (same for Branch)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is needed since someone can send a Fallthrough::Filter through xDS/protobuf, not just in the static configuration

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah so iiuc its not necessarily it being used through xds but rather that to use deserialize we need to be able to convert from proto to yaml and there isn't a reasonable way to do that for the transparent filter config field? We don't have to use deserialize since its only a helper function, we can call the convert function ourselves and instantiate the filter i.e

fn create_filter(&self, args: CreateFilterArgs) -> Result<FilterInstance, Error> {
  let (config_json, on_read, on_write) = match args {
    ConfigType::Static(config) => {
      // Instantiate sub filters from static config
    },
    ConfigType::Dynamic(config) => {
      // Instantiate sub filters from dynamic config
    }
  }

  let filter = Matches::new(on_read, on_write)?;
  Ok(FilterInstance::new(
    config_json,
    Box::new(filter) as Box<dyn Filter>,
  ))
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, though I'm not sure what that provides over the current approach.

@XAMPPRocky XAMPPRocky added the kind/breaking Changes to functionality, API, etc. label Dec 14, 2021
@XAMPPRocky XAMPPRocky force-pushed the matches-filter branch 2 times, most recently from f38d9d7 to a0debc8 Compare December 21, 2021 11:50
docs/src/filters/matches.md Outdated Show resolved Hide resolved

View the [Matches](./matches.md) filter documentation for more details.

### [Configuration Options](../../api/quilkin/filters/matches/struct.Config.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the documentation like we have it currently for filters. It means for users that don't know Rust they have to work it out from the Rust code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How are you generating that? Is there a specific format I should be following?

on_read:
metadataKey: myapp.com/token
branches:
- value: abc
Copy link
Contributor

Choose a reason for hiding this comment

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

From digging into the code, value can't be a base64 byte array, correct? It has be one of the Value types such as String or Int? (bool?). This makes sense, since the dynamic metadata could come from anywhere, and as such, should be a Value.

(Just making sure my understanding is correct).

If so, we might want to make that extra clear in the documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's not base64, it's a string.

Copy link
Contributor

Choose a reason for hiding this comment

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

nods that makes total sense -- I think we should be clear in that in the docs with a comment somewhere, as I could see people assuming it was a byte array and attempting to fill it as such.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well I mean it should be documented but that's also valid to do that. That's why the PartialEq of Value compares the value between strings and bytes, so that you can set a string here and use it to match the bytes, since a lot of marker values in my experience are at least string friendly if not human-readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

100% agree.

config.ok_or_else(|| Error::MissingConfig(self.name()))
}
}

/// Arguments needed to create a new filter.
pub struct CreateFilterArgs<'a> {
pub struct CreateFilterArgs {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please - add a note about this in the description, so when i write the release notes I won't forget 👍🏻

@XAMPPRocky
Copy link
Collaborator Author

@markmandel Now with #478, do we want to merge this in, and I can add the configuration schema in that?

XAMPPRocky and others added 9 commits February 1, 2022 10:10
Co-authored-by: Ifeanyi Ubah <ifeanyi.ubah@embark-studios.com>
Co-authored-by: Ifeanyi Ubah <ifeanyi.ubah@embark-studios.com>
Co-authored-by: Ifeanyi Ubah <ifeanyi.ubah@embark-studios.com>
@markmandel
Copy link
Contributor

@markmandel Now with #478, do we want to merge this in, and I can add the configuration schema in that?

I like it! Also good to get this in for 0.3.0 👍🏻

@quilkin-bot
Copy link
Collaborator

Build Succeeded 🥳

Build Id: 76e917c6-c950-4a53-bc44-9683c1dc1b84

To build this version:

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

@XAMPPRocky XAMPPRocky merged commit 2fdc8ac into main Feb 4, 2022
@XAMPPRocky XAMPPRocky deleted the matches-filter branch February 14, 2022 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes kind/breaking Changes to functionality, API, etc. size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for version based packet processing
4 participants