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

Implementation of FilterChain #45

Merged
merged 1 commit into from
Apr 28, 2020
Merged

Implementation of FilterChain #45

merged 1 commit into from
Apr 28, 2020

Conversation

markmandel
Copy link
Contributor

This is so we can take a set of Filters and string their execution in the appropriate places.

FilterChain also implements Filter, so it's clear what FilterChain functions match to Filter functions.

Once we have this in place, we can build a FilterChain from the combination of a Config the FilterRegistry on startup of a Quilkin executable.

@markmandel markmandel added the kind/feature New feature or request label Apr 22, 2020
Comment on lines 42 to 58
for filter_config in config.filters.clone() {
match filter_registry.get(&filter_config.name) {
None => {
return Err(Error::new(
ErrorKind::InvalidInput,
format!("Filter '{}' not found", filter_config.name),
));
}
Some(filter) => {
filters.push(filter.clone());
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

filter_config doesn't seem to get moved anywhere here, why is config.filters cloned instead of borrowed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!!! Changed!

}
}

impl Filter for FilterChain {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The FilterChain implementation reads rather weirdly. They always return the last filter of that type in the chain, and looping over the whole vec for each call doesn't feel super nice. I have no better suggestions at the moment though as I'm not familiar enough yet with the rest of the code base.

Or am I reading them wrong ? Thats entirely possible too :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately Not sure I'm following what you mean.

Each filter implementation loops around all the filters stored in the FilterChain, passing the results of each filter to the next in the chain.

Finally it returns the results of data that has gone through each of the filters in the chain.

If any of the Filters in the chain return a None, then the chain is broken, and nothing is returned.

Does that make sense?

(Long term, I expect this API to shift with the Filter trait as we work out more use cases, and/or performance optimisations)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me reread it with this in mind!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I see how it works now. Could we add a big comment in the code somewhere prominent on how this works ? Its not super clear just reading it without comments

@markmandel markmandel force-pushed the feature/filter-chain branch from 342f55e to e9f1403 Compare April 27, 2020 18:06
This is so we can take a set of Filters and string their execution in
the appropriate places.

FilterChain also implements Filter, so it's clear what FilterChain
functions match to Filter functions.

Once we have this in place, we can build a FilterChain
from the combination of a Config the FilterRegistry on startup of a
Quilkin executable.
@markmandel markmandel force-pushed the feature/filter-chain branch from e9f1403 to d5c5d09 Compare April 28, 2020 15:58
@markmandel markmandel merged commit b49bc20 into master Apr 28, 2020
@markmandel markmandel deleted the feature/filter-chain branch April 28, 2020 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants