-
Notifications
You must be signed in to change notification settings - Fork 482
Add serve_grpc
API
#9447
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
Merged
Merged
Add serve_grpc
API
#9447
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
828624d
add grpc server sink to re_sdk
jprochazk 9516f02
expose serve_grpc from `RecordingStream`
jprochazk 44b5223
add python api
jprochazk 2f4437b
add C/C++ api
jprochazk 8b3b0c1
fix sdk compile
jprochazk 9c61bb6
add `--serve-grpc` CLI option
jprochazk d9d7a15
hide grpc server behind feature flag
jprochazk 2ef929c
Merge branch 'main' into jan/spawn-headless
jprochazk bdbe265
use server feature in cpp
jprochazk 79eb24f
fix links
jprochazk 85e0ded
Merge branch 'main' into jan/spawn-headless
jprochazk c6d9a9e
fix lint
jprochazk 0304de9
fix py lint
jprochazk e92cee9
fix links again
jprochazk 452259b
fix lints in rerun_c
jprochazk ec43eaa
add additionally needed windows system library link dependencies
Wumpf 5481ca0
fix python sdk export
jprochazk 243a5dc
update docs
jprochazk d47dea3
add basic cpp sanity check
jprochazk c4be7e9
flush before shutdown
jprochazk cdf7c88
require serve_grpc_opts for setting memory limit
jprochazk 3f5391c
Merge branch 'main' into jan/spawn-headless
jprochazk 256e7ed
update operating mode docs
jprochazk ec63746
update py index
jprochazk ddf8b9b
speculative links
jprochazk b1f440f
improve missing scheme message
jprochazk 5a4cb4a
Merge branch 'main' into jan/spawn-headless
jprochazk 7bdcbc7
improve connect error message
jprochazk 716188d
connection failed message
jprochazk 6907012
Update wording
jprochazk a293330
use DEFAULT_SERVER_PORT
jprochazk 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
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
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,79 @@ | ||
use re_log_types::LogMsg; | ||
|
||
/// A [`crate::sink::LogSink`] tied to a hosted Rerun gRPC server. | ||
/// | ||
/// The hosted gRPC server may be connected to by any SDK or Viewer. | ||
/// | ||
/// All data sent through this sink is immediately redirected to the gRPC server. | ||
pub struct GrpcServerSink { | ||
/// Sender to send messages to the gRPC server. | ||
sender: re_smart_channel::Sender<LogMsg>, | ||
|
||
/// The gRPC server thread. | ||
_server_handle: std::thread::JoinHandle<()>, | ||
|
||
/// Rerun websocket server. | ||
server_shutdown_signal: re_grpc_server::shutdown::Signal, | ||
} | ||
|
||
impl GrpcServerSink { | ||
/// A `bind_ip` of `"0.0.0.0"` is a good default. | ||
pub fn new( | ||
bind_ip: &str, | ||
grpc_port: u16, | ||
server_memory_limit: re_memory::MemoryLimit, | ||
) -> Result<Self, std::net::AddrParseError> { | ||
let (server_shutdown_signal, shutdown) = re_grpc_server::shutdown::shutdown(); | ||
|
||
let grpc_server_addr = format!("{bind_ip}:{grpc_port}").parse()?; | ||
let (channel_tx, channel_rx) = re_smart_channel::smart_channel::<re_log_types::LogMsg>( | ||
re_smart_channel::SmartMessageSource::MessageProxy { | ||
url: format!("rerun+http://{grpc_server_addr}/proxy"), | ||
}, | ||
re_smart_channel::SmartChannelSource::Sdk, | ||
); | ||
let server_handle = std::thread::Builder::new() | ||
.name("message_proxy_server".to_owned()) | ||
.spawn(move || { | ||
let mut builder = tokio::runtime::Builder::new_current_thread(); | ||
builder.enable_all(); | ||
let rt = builder.build().expect("failed to build tokio runtime"); | ||
|
||
rt.block_on(re_grpc_server::serve_from_channel( | ||
grpc_server_addr, | ||
server_memory_limit, | ||
shutdown, | ||
channel_rx, | ||
)); | ||
}) | ||
.expect("failed to spawn thread for message proxy server"); | ||
|
||
Ok(Self { | ||
sender: channel_tx, | ||
_server_handle: server_handle, | ||
server_shutdown_signal, | ||
}) | ||
} | ||
} | ||
|
||
impl crate::sink::LogSink for GrpcServerSink { | ||
fn send(&self, msg: LogMsg) { | ||
if let Err(err) = self.sender.send(msg) { | ||
re_log::error_once!("Failed to send log message to gRPC server: {err}"); | ||
} | ||
} | ||
|
||
#[inline] | ||
fn flush_blocking(&self) { | ||
if let Err(err) = self.sender.flush_blocking() { | ||
re_log::error_once!("Failed to flush: {err}"); | ||
} | ||
} | ||
} | ||
|
||
impl Drop for GrpcServerSink { | ||
fn drop(&mut self) { | ||
self.sender.flush_blocking().ok(); | ||
self.server_shutdown_signal.stop(); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Will this work even if the user already has
#[tokio::main]
on theirfn main
?Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, we're spawning a new thread and using a single-threaded runtime, so anything goes.