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

ReDap Catalog as data source #8321

Merged
merged 17 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5636,6 +5636,7 @@ dependencies = [
"re_smart_channel",
"re_tracing",
"re_ws_comms",
"url",
]

[[package]]
Expand Down Expand Up @@ -5789,6 +5790,7 @@ dependencies = [
"tokio-stream",
"tonic",
"tonic-web-wasm-client",
"url",
"wasm-bindgen-futures",
]

Expand Down
1 change: 1 addition & 0 deletions crates/store/re_data_source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ re_ws_comms = { workspace = true, features = ["client"] }
anyhow.workspace = true
itertools.workspace = true
rayon.workspace = true
url.workspace = true

# Optional dependencies:
re_grpc_client = { workspace = true, optional = true }
Expand Down
21 changes: 18 additions & 3 deletions crates/store/re_data_source/src/data_source.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::FileContents;
use re_log_types::LogMsg;
use re_smart_channel::{Receiver, SmartChannelSource, SmartMessageSource};

use crate::FileContents;

#[cfg(not(target_arch = "wasm32"))]
use anyhow::Context as _;

Expand Down Expand Up @@ -35,6 +34,10 @@ pub enum DataSource {
/// A file on a Rerun Data Platform server, over `rerun://` gRPC interface.
#[cfg(feature = "grpc")]
RerunGrpcUrl { url: String },

/// A catalog containing metadata information about recordings stored on Rerun Data Platform.
#[cfg(feature = "grpc")]
RerunGrpcCatalog { url: String },
zehiko marked this conversation as resolved.
Show resolved Hide resolved
}

impl DataSource {
Expand Down Expand Up @@ -92,6 +95,9 @@ impl DataSource {

#[cfg(feature = "grpc")]
if uri.starts_with("rerun://") {
if uri.ends_with("/catalog") {
return Self::RerunGrpcCatalog { url: uri };
}
return Self::RerunGrpcUrl { url: uri };
}

Expand Down Expand Up @@ -137,7 +143,7 @@ impl DataSource {
#[cfg(not(target_arch = "wasm32"))]
Self::Stdin => None,
#[cfg(feature = "grpc")]
Self::RerunGrpcUrl { .. } => None, // TODO(jleibs): This needs to come from the server.
Self::RerunGrpcUrl { .. } | Self::RerunGrpcCatalog { .. } => None, // TODO(jleibs): This needs to come from the server.
}
}

Expand Down Expand Up @@ -247,8 +253,17 @@ impl DataSource {

#[cfg(feature = "grpc")]
Self::RerunGrpcUrl { url } => {
let url =
url::Url::parse(&url).with_context(|| format!("Invalid gRPC URL: {url}"))?;
re_grpc_client::stream_recording(url, on_msg).map_err(|err| err.into())
}

#[cfg(feature = "grpc")]
Self::RerunGrpcCatalog { url } => {
let url =
url::Url::parse(&url).with_context(|| format!("Invalid gRPC URL: {url}"))?;
re_grpc_client::stream_catalog(url, on_msg).map_err(|err| err.into())
zehiko marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/store/re_grpc_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ re_smart_channel.workspace = true

thiserror.workspace = true
tokio-stream.workspace = true
url.workspace = true

# Native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
116 changes: 81 additions & 35 deletions crates/store/re_grpc_client/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,111 @@
use url::Url;

/// The given url is not a valid Rerun storage node URL.
#[derive(thiserror::Error, Debug)]
#[error("URL {url:?} should follow rerun://addr:port/recording/12345")]
pub struct InvalidAddressError {
url: String,
#[error("URL {url:?} should follow rerun://addr:port/recording/12345 for recording or rerun://addr:port/catalog for catalog")]
pub struct InvalidRedapAddress {
url: Url,
msg: String,
}

/// Parsed `rerun://addr:port/recording/12345`
pub struct Address {
pub addr_port: String,
pub struct RecordingAddress {
zehiko marked this conversation as resolved.
Show resolved Hide resolved
pub redap_endpoint: Url,
pub recording_id: String,
}

impl std::fmt::Display for Address {
impl std::fmt::Display for RecordingAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"rerun://{}/recording/{}",
self.addr_port, self.recording_id
"RecordingAddress {{ redap_endpoint: {}, recording_id: {} }}",
zehiko marked this conversation as resolved.
Show resolved Hide resolved
self.redap_endpoint, self.recording_id
)
}
}

impl std::str::FromStr for Address {
type Err = InvalidAddressError;
impl TryFrom<Url> for RecordingAddress {
type Error = InvalidRedapAddress;

fn from_str(url: &str) -> Result<Self, Self::Err> {
let Some(stripped_url) = url.strip_prefix("rerun://") else {
return Err(InvalidAddressError {
url: url.to_owned(),
msg: "Missing rerun://".to_owned(),
fn try_from(url: Url) -> Result<Self, Self::Error> {
if url.scheme() != "rerun" {
return Err(InvalidRedapAddress {
url: url.clone(),
msg: "Invalid scheme, expected 'rerun'".to_owned(),
});
};
}

let parts = stripped_url.split('/').collect::<Vec<_>>();
if parts.len() < 3 {
return Err(InvalidAddressError {
url: url.to_owned(),
msg: "Too few slashes".to_owned(),
let redap_endpoint = get_redap_endpoint(&url)?;

let path_segments: Vec<&str> = url.path_segments().map(|s| s.collect()).unwrap_or_default();
if path_segments.len() != 2 || path_segments[0] != "recording" {
return Err(InvalidRedapAddress {
url: url.clone(),
msg: "Invalid path, expected '/recording/{id}'".to_owned(),
});
}
if parts.len() > 3 {
return Err(InvalidAddressError {
url: url.to_owned(),
msg: "Too many slashes".to_owned(),

Ok(Self {
redap_endpoint,
recording_id: path_segments[1].to_owned(),
})
}
}

/// Parsed `rerun://addr:port/catalog`
pub struct CatalogAddress {
pub redap_endpoint: Url,
}

impl std::fmt::Display for CatalogAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ReDap endpoint {}", self.redap_endpoint)
}
}

impl TryFrom<Url> for CatalogAddress {
type Error = InvalidRedapAddress;

fn try_from(url: Url) -> Result<Self, Self::Error> {
if url.scheme() != "rerun" {
return Err(InvalidRedapAddress {
url: url.clone(),
msg: "Invalid scheme, expected 'rerun'".to_owned(),
});
}

if parts[1] != "recording" {
return Err(InvalidAddressError {
url: url.to_owned(),
msg: "Not a recording".to_owned(),
let redap_endpoint = get_redap_endpoint(&url)?;

let path_segments: Vec<&str> = url.path_segments().map(|s| s.collect()).unwrap_or_default();
if path_segments.len() != 1 || path_segments[0] != "catalog" {
return Err(InvalidRedapAddress {
url: url.clone(),
msg: "Invalid path, expected '/catalog'".to_owned(),
});
}

let addr_port = parts[0].to_owned();
let recording_id = parts[2].to_owned();
Ok(Self { redap_endpoint })
}
}

/// Small helper to extract host and port from the Rerun Data Platform URL.
fn get_redap_endpoint(url: &Url) -> Result<Url, InvalidRedapAddress> {
let host = url.host_str().ok_or_else(|| InvalidRedapAddress {
url: url.clone(),
msg: "Missing host".to_owned(),
})?;

Ok(Self {
addr_port,
recording_id,
})
if host == "0.0.0.0" {
re_log::warn!("Using 0.0.0.0 as Rerun Data Platform host will often fail. You might want to try using 127.0.0.0.");
}

let port = url.port().ok_or_else(|| InvalidRedapAddress {
url: url.clone(),
msg: "Missing port".to_owned(),
})?;

#[allow(clippy::unwrap_used)]
let redap_endpoint = Url::parse(&format!("http://{host}:{port}")).unwrap();

Ok(redap_endpoint)
}
Loading
Loading