-
Notifications
You must be signed in to change notification settings - Fork 95
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
Support regex filter #387
Support regex filter #387
Conversation
2966f91
to
d781594
Compare
f2503ed
to
b544253
Compare
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.
Thank you for your PR! This mostly looks good to me, I've left a one comment. Once that is addressed this should be good to merge.
|
||
impl Filter for RegexBytes { | ||
fn read(&self, ctx: ReadContext) -> Option<ReadResponse> { | ||
let re = Regex::new(self.regex_expression.as_str()).unwrap(); |
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.
The Regex
type should be created in create_filter
, stored, and re-used here. This implementation will compile the Regex for each packet.
Hey, this PR is still under WIP and I’ll address your mentioned concern
before making it ready for review
… ***@***.**** approved this pull request.
Thank you for your PR! This mostly looks good to me, I've left a one
comment. Once that is addressed this should be good to merge.
------------------------------
In src/filters/regex_bytes.rs
<#387 (comment)>
:
> +
+impl RegexBytes {
+ fn new(base: &Logger, config: Config, metrics: Metrics) -> Self {
+ RegexBytes {
+ log: base.new(o!("source" => "extensions::RegexBytes")),
+ //capture: config.strategy.as_capture(),
+ metrics,
+ regex_expression: Arc::new(config.regex_expression),
+ //metadata_key: Arc::new(config.metadata_key),
+ }
+ }
+}
+
+impl Filter for RegexBytes {
+ fn read(&self, ctx: ReadContext) -> Option<ReadResponse> {
+ let re = Regex::new(self.regex_expression.as_str()).unwrap();
The Regex type should be created in create_filter, stored, and re-used
here. This implementation will compile the Regex for each packet.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#387 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXAGUV2HT6DOPNOXEGSFMDT7RSURANCNFSM5DCXD2JQ>
.
|
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.
Thanks for the PR! We have a capture bytes that does something pretty similar to this from what I can tell, could we enhance that filter with a new regex Strategy
instead of implementing this as a new filter? https://github.com/googleforgames/quilkin/blob/main/src/filters/capture_bytes/capture.rs#L2-L7
So that we get pinged when PRs are up for review
Co-authored-by: Mark Mandel <[email protected]>
I was looking at this as well first, but realised pretty soon that the description/idea of how this regex should work differs from what CaptureBytes does today. It will also introduce complexity to configuration, e.g different supporting properties, errors/unsupported combinations. Example
vs
We probably could try to align and merge logic of these two filters, for example PREFIX/SUFFIX drops today as default if size req is not met, but for the rest it is different. I see this more as regex filter utilises capture as a partial feature but also has support for pass. An idea on how we could align these two filters to one is to support a configuration like this
Required properties throws validation errors on startup if missing to set strategy, wdyt? |
Ah I see, yeah the only difference I can seems to be the # prefix
config:
metadataKey: myapp.com/myownkey
prefix: # deserialization ensures that exactly one of prefix,suffix,regex is provided
size: 3
remove: false or # regex
config:
metadataKey: myapp.com/myownkey
regex:
expression: ".*"
remove: false
capture: true # or maybe e.g `passthrough: true` since capturing the bytes makes more sense as a default given the filter name For the |
I just came here to say that I like this idea 👍🏻 |
Co-authored-by: Mark Mandel <[email protected]>
* Update custom filter example and add CI Update the custom filter example to the new API surface, and also setup CI so that it ensures that it always compiles against dev Quilkin, and therefore will stay in sync going forward. Next I want to block out pieces of code and inject them into our docs via mdbook when updating https://googleforgames.github.io/quilkin/main/book/filters/writing_custom_filters.html as well, rather than have them copy pasted. Work on googleforgames#373 * Review updates.
* Exit on SIGTERM we currently only listen for SIGINT while k8s sends a SIGTERM to shutdown a process, so we need to listen for that too * shutdown logging Co-authored-by: Mark Mandel <[email protected]>
* Use hostname as default proxy id If we don't provide a default proxy id this falls back to using the hostname instead of uuid (and if that fails, then we use a uuid). For environments like kubernetes, we would like the proxy's id to match the pod id so that the management server can easily find pod information for the proxy that is connected to it (the proxy passes its ID when it connects to the server) * use hostname only on linux Co-authored-by: Mark Mandel <[email protected]>
If we hit connectivity issues, make sure we retry until the server comes back up. Co-authored-by: Mark Mandel <[email protected]>
* Docs: Updated Custom Filters Updates the custom filter documentation to the latest API changes. This also includes using mdbook's `include` preprocessor to inject the example code into the documentation. Note: Because of the use of `include` preprocessor I had to remove the Markdown lists, as they wouldn't format correctly (See: rust-lang/mdBook#1564). Closes googleforgames#373 * Fix CI build * Review Updates.
Just checking in to see if you need / want a hand in any way? |
Remove old stuff left from initial impl
Build Failed 😭 Build Id: c7c2d223-6237-4246-9901-0c93d2a8a59a Status: FAILURE To get permission to view the Cloud Build view, join the quilkin-discuss Google Group. |
Thanks @markmandel, tbh I've been swamped at work and private latley. However, I'm now in a state where I'm fighting the language more than anything. Two initial things I'd like your help with
Last but not least, feel free to contribute if you think it is taking too much time... It is totally understandable. Rust is a new language for me and this turned out to be bigger than I anticipated in the first place! 😅 |
Hi @devharis!
I think the simpler route would be have to all three strategies implement the struct Suffix {
remove: bool,
size: usize,
}
struct Regex {
regex: Regex,
remove: bool,
}
impl Capture for Suffix {}
impl Capture for Regex {}
struct CaptureBytes {
log: Logger,
capture: Box<dyn Capture>,
metadata_key: Arc<String>,
}
impl Filter for CaptureBytes {
fn read(&self) {
// I think this part works largely the same
...
// Except no extra parameters needed in the `capture()` call
// since the `self.capture` implementation already has all the
// needed configuration.
let token = self.capture.capture(ctx.contents)
...
}
}
the let strategy: Strategy = match protoconfig.strategy {
ProtoStrategy::Suffix => {
Strategy::Suffix {
size: protoconfig.size,
...
}
},
} (also sorry about the delayed feedback) |
Since this has bitrotted with little activity, and I wanted to add support for regex to test something, I've continued this work in #458 and am going to close this, I'll be sure to add you as a coauthor to it. Thank you again for your PR! |
No description provided.