-
Notifications
You must be signed in to change notification settings - Fork 13
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
WIP - Feature/smart module filter #159
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d00de39
initial spike of feature
bencleary e527c3f
updated docs and worked through sample more
bencleary 13dbb59
tidied up python interface and added test
bencleary 6f61458
PR comments fix
bencleary 821ad83
rust changes implemented from PR feedback
bencleary a3f8c0b
Merge branch 'main' into feature/smart-module-filter
simlay be426fd
better error handling for consumerconfigwrapper
bencleary 6f60a5d
fixed linting errors
bencleary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
exclude = .git,.tox | ||
max-line-length = 119 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,22 @@ use fluvio::{ | |
Offset, | ||
consumer::Record, | ||
}; | ||
use std::io::{Read, Error}; | ||
use flate2::bufread::GzEncoder; | ||
use flate2::Compression; | ||
use fluvio_future::{ | ||
task::run_block_on, | ||
io::{ | ||
Stream, | ||
StreamExt, | ||
}, | ||
}; | ||
use fluvio::consumer::{ | ||
SmartModuleInvocation, | ||
SmartModuleInvocationWasm, | ||
SmartModuleKind, | ||
ConsumerConfig | ||
}; | ||
use std::pin::Pin; | ||
|
||
mod _Fluvio { | ||
|
@@ -52,6 +61,28 @@ foreign_class!(class Fluvio { | |
}); | ||
|
||
|
||
pub struct ConsumerConfigWrapper { | ||
wasm_module: Vec<u8>, | ||
} | ||
|
||
impl ConsumerConfigWrapper { | ||
fn new_config_with_wasm_filter(file: &str) -> Result<ConsumerConfigWrapper, std::io::Error> { | ||
let raw_buffer = match std::fs::read(file) { | ||
Ok(b) => b, | ||
Err(error) => return Err(error) | ||
}; | ||
let mut encoder = GzEncoder::new(raw_buffer.as_slice(), Compression::default()); | ||
let mut buffer = Vec::with_capacity(raw_buffer.len()); | ||
match encoder.read_to_end(&mut buffer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
Ok(encoder) => encoder, | ||
Err(error) => return Err(error) | ||
}; | ||
Ok(ConsumerConfigWrapper { | ||
wasm_module: buffer, | ||
}) | ||
} | ||
} | ||
|
||
mod _PartitionConsumer { | ||
use super::*; | ||
pub fn stream( | ||
|
@@ -62,13 +93,34 @@ mod _PartitionConsumer { | |
inner: Box::pin(run_block_on(consumer.stream(offset.clone()))?) | ||
}) | ||
} | ||
pub fn stream_with_config( | ||
consumer: &PartitionConsumer, | ||
offset: &Offset, | ||
wasm_module_path: &str | ||
) -> Result<PartitionConsumerStream, FluvioError> { | ||
let config_wrapper = match ConsumerConfigWrapper::new_config_with_wasm_filter(wasm_module_path) { | ||
Ok(config) => config, | ||
Err(error) => return Err(FluvioError::Other(error.to_string())) | ||
}; | ||
let mut builder = ConsumerConfig::builder(); | ||
builder.smartmodule(Some(SmartModuleInvocation { | ||
wasm: SmartModuleInvocationWasm::AdHoc(config_wrapper.wasm_module), | ||
kind: SmartModuleKind::Filter, | ||
params: Default::default() | ||
})); | ||
let config = builder.build().map_err(|err| FluvioError::Other(err.to_string()))?; | ||
run_block_on(consumer.stream_with_config(offset.clone(), config)).map(|stream| PartitionConsumerStream { inner: Box::pin(stream) }) | ||
} | ||
} | ||
foreign_class!(class PartitionConsumer { | ||
self_type PartitionConsumer; | ||
private constructor = empty; | ||
fn _PartitionConsumer::stream( | ||
&self, _: &Offset | ||
) -> Result<PartitionConsumerStream, FluvioError>; | ||
fn _PartitionConsumer::stream_with_config( | ||
&self, _: &Offset, _: &str | ||
) -> Result<PartitionConsumerStream, FluvioError>; | ||
}); | ||
|
||
type PartitionConsumerIteratorInner = | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
not a show stopper. this could be reduced to
raw_buffer = read(file)?