-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(python_adapter): add test for ArroyoDelegate in rust #200
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
Open
bmckerry
wants to merge
7
commits into
main
Choose a base branch
from
ben/fix-rust-step-gen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
811b716
fix(python_adapter): retrieve messages as Sequence
bmckerry 3a6f3cd
better in/out transformers
bmckerry 6af3a32
port python code over to python
bmckerry d2e113c
AI fixes everything
bmckerry e0e3d92
Merge branch 'main' into ben/fix-rust-step-gen
bmckerry 991c53f
Merge branch 'main' into ben/fix-rust-step-gen
bmckerry 516f9e1
clean up cursor
bmckerry 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
62 changes: 62 additions & 0 deletions
62
sentry_streams/sentry_streams/adapters/arroyo/test_delegate.py
This file contains hidden or 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,62 @@ | ||
| from datetime import datetime | ||
| from typing import Tuple, Union | ||
|
|
||
| from arroyo.processing.strategies.run_task import RunTask | ||
| from arroyo.types import FilteredPayload | ||
| from arroyo.types import Message as ArroyoMessage | ||
| from arroyo.types import Partition, Topic, Value | ||
|
|
||
| from sentry_streams.adapters.arroyo.rust_step import ( | ||
| ArroyoStrategyDelegate, | ||
| Committable, | ||
| OutputRetriever, | ||
| RustOperatorFactory, | ||
| ) | ||
| from sentry_streams.pipeline.message import RustMessage | ||
|
|
||
|
|
||
| def rust_to_arroyo_msg( | ||
| message: RustMessage, committable: Committable | ||
| ) -> ArroyoMessage[RustMessage]: | ||
| arroyo_committable = { | ||
| Partition(Topic(partition[0]), partition[1]): offset | ||
| for partition, offset in committable.items() | ||
| } | ||
| return ArroyoMessage( | ||
| Value( | ||
| message, | ||
| arroyo_committable, | ||
| datetime.fromtimestamp(message.timestamp) if message.timestamp else None, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def arroyo_msg_to_rust( | ||
| message: ArroyoMessage[Union[FilteredPayload, RustMessage]], | ||
| ) -> Tuple[RustMessage, Committable] | None: | ||
| if isinstance(message.payload, FilteredPayload): | ||
| return None | ||
| committable = { | ||
| (partition.topic.name, partition.index): offset | ||
| for partition, offset in message.committable.items() | ||
| } | ||
| return (message.payload, committable) | ||
|
|
||
|
|
||
| def noop( | ||
| msg: ArroyoMessage[Union[FilteredPayload, RustMessage]], | ||
| ) -> Union[FilteredPayload, RustMessage]: | ||
| return msg.payload | ||
|
|
||
|
|
||
| class TestDelegateFactory(RustOperatorFactory): | ||
| """ | ||
| A delegate used in rust_streams tests for the PythonAdapter step. | ||
| """ | ||
|
|
||
| def build( | ||
| self, | ||
| ) -> ArroyoStrategyDelegate[FilteredPayload | RustMessage, FilteredPayload | RustMessage]: | ||
| retriever = OutputRetriever(out_transformer=arroyo_msg_to_rust) | ||
| inner = RunTask(noop, retriever) | ||
| return ArroyoStrategyDelegate(inner, rust_to_arroyo_msg, retriever) | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -283,6 +283,7 @@ mod tests { | |
| use crate::testutils::build_routed_value; | ||
| use crate::testutils::make_committable; | ||
| use pyo3::ffi::c_str; | ||
| use pyo3::BoundObject; | ||
| use pyo3::IntoPyObjectExt; | ||
| use sentry_arroyo::processing::strategies::noop::Noop; | ||
| use std::collections::{BTreeMap, HashMap}; | ||
|
|
@@ -521,4 +522,33 @@ class RustOperatorDelegateFactory: | |
| } // Unlock the MutexGuard around `actual_messages` | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_arroyo_python_delegate() { | ||
| crate::testutils::initialize_python(); | ||
| traced_with_gil!(|py| { | ||
| let delegate = c_str!( | ||
| r#" | ||
| from sentry_streams.adapters.arroyo.test_delegate import TestDelegateFactory | ||
| "# | ||
| ); | ||
| let scope = PyModule::new(py, "test_scope").unwrap(); | ||
| py.run(delegate, Some(&scope.dict()), None).unwrap(); | ||
| let operator = scope.getattr("TestDelegateFactory").unwrap(); | ||
| let instance = operator.call0().unwrap(); | ||
|
|
||
| let mut operator = PythonAdapter::new( | ||
| Route::new("source1".to_string(), vec!["waypoint1".to_string()]), | ||
| instance.unbind(), | ||
| Box::new(Noop {}), | ||
| ); | ||
|
|
||
| let message = make_msg(py, "ok"); | ||
| let res = operator.submit(message); | ||
| assert!(res.is_ok()); | ||
|
|
||
| let commit_request = operator.poll(); | ||
| assert!(commit_request.is_ok()); | ||
|
Collaborator
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. How is this returning OK now that your fix has not been merged yet ?
Member
Author
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. no idea |
||
| }) | ||
| } | ||
| } | ||
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.
These seem unnecessary.
They seem 95% copies of these https://github.com/getsentry/streams/blob/main/sentry_streams/sentry_streams/adapters/arroyo/multi_process_delegate.py#L46-L91
The difference seems toi be that your
RunTaskop takes RustMessage and return RustMessage rather than taking and returning a PyAnyMessage.If you make your function take and return a PyAnyMessage you should be able to avoid these methods entirely and actually test the real logic we run in production instead, which would be recommended.
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.
I tried originally doing what you're suggesting, but spent >30 min wrestling with mypy to make it happy regarding the
TMapIn/TMapOutgenerics in the ArroyoStrategyDelegate.I can spend more time on this to get the typing right, it was just a nightmare.