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

Rust SDK: introduce MsgSender builder-like interface for logging data #1037

Merged
merged 12 commits into from
Feb 6, 2023

Conversation

teh-cmc
Copy link
Member

@teh-cmc teh-cmc commented Feb 1, 2023

  • Introduce MsgSender, a builder-like API for easily & safely logging components in Rust
    • The "safely" part is the important / tricky one as the Rust SDK has full access to the raw data model
    • Update raw_mesh example to use these new APIs
  • Introduce SerializableComponent trait
  • Add crystal clear (hopefully) nb_components, nb_rows & nb_instances helpers where required

Summary listing of important TODOs for my later self when I'll start opening issues:

// TODO(cmc): remove traces of previous APIs & examples

// TODO(cmc): if this is an InstanceKey and it contains u64::MAX, fire IllegalInstanceKey.

// TODO(cmc): The sanity checks we do in here can (and probably should) be done in
// `MsgBundle` instead so that the python SDK benefits from them too... but one step at a
// time.

// TODO(cmc): The Rust SDK needs a higher-level `init()` method, akin to what the python SDK
// does... which they can probably share.
// This needs to take care of the whole `official_example` thing, and also keeps track of
// whether we're using the rust or python sdk.

// TODO(cmc): arg parsing and arg interpretation helpers
// TODO(cmc): missing flags: save, serve
// TODO(cmc): expose an easy to use async local mode.

@teh-cmc teh-cmc force-pushed the cmc/rust_sdk_msg_builder branch 8 times, most recently from 527eb79 to 6c1b5fc Compare February 5, 2023 22:30
@teh-cmc teh-cmc changed the title rust SDK: builder-like interface for logging data Rust SDK: introduce MsgSender builder-like interface for logging data Feb 6, 2023
@teh-cmc teh-cmc marked this pull request as ready for review February 6, 2023 11:34
@jondo2010 jondo2010 self-requested a review February 6, 2023 13:46
/// .map_err(Into::into)
/// }
/// ```
pub struct MsgSender {
Copy link
Contributor

@jondo2010 jondo2010 Feb 6, 2023

Choose a reason for hiding this comment

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

Maybe MsgBuilder, or LogBuilder?

Copy link
Member Author

Choose a reason for hiding this comment

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

It used to be called that way, but really it cannot give you back a message, all it can do is send one (more than one actually because the message is likely to get splitted into parts internally)


/// All the different timestamps for this message.
///
/// The logging time is automatically inserted during creation ([`Self::new`]).
Copy link
Contributor

@jondo2010 jondo2010 Feb 6, 2023

Choose a reason for hiding this comment

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

Do we want log time set with new(), or send()? What if they create a builder and hang on to it for a while before calling send()?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no go solution besides logging and/or making it configurable; but really in practice this won't matter for the foreseeable future as there's really not any reason to hold on to one of these as I can think of.

}
}

fn bundle_from_iter<'a, C: SerializableComponent>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use ComponentBundle::try_from?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have such an impl and I cannot define it due to orphan rules 😞

I'll leave the commented out impl there for future reference.

examples/raw_mesh/src/main.rs Outdated Show resolved Hide resolved

/// Returns the number of _instances_ for a given `row` in the bundle, i.e. the length of a
/// specific row within the bundle.
pub fn nb_instances(&self, row: usize) -> Option<usize> {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a style bikeshed, but I find num_instances a lot more clear, and my wild guess, with zero data to back it up, is that it is less likely to confuse others.

Copy link
Member

Choose a reason for hiding this comment

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

I'll make a note to unify our code styles here at some point (currently conducting a twitter poll to gauge popular opinion)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah I never actually thought about it until now; it's a very french thing actually 🥲

I'll keep it as-is for now because it's consistent with how I've written it everywhere in the store, but I definitely think this warrants a big s/nb_/num_ PR.

.iter()
.map(|bundle| bundle.name)
.all_unique(),
msg.components.iter().map(|bundle| bundle.name).all_unique(),
Copy link
Member

Choose a reason for hiding this comment

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

it's a bit weird to refer both to msg.components and to its alias bundles

Copy link
Member Author

Choose a reason for hiding this comment

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

TL;DR: this is all in dire need of a terminology pass; at the moment I don't know of any good solution here.

  • msg.components.iter().map(|components| ...) is technically correct but plain confusing.
  • msg.components.iter().map(|component| ...) looks like you'd expect but is plain wrong.
  • msg.components.iter().map(|bundle| ...) looks awful but at least it makes you look twice, which you should because there's more going on than meets the eye.

The root of the issue is that msg.components is too vague: this is in fact an array (component types) of arrays (rows) of actual components (instances/columns).

I guess we'll clean all of this when we implement support for batch insertions.

// TODO(cmc): kind & insert_id need to somehow propagate through the span system.
self.insert_id += 1;

let MsgBundle {
msg_id,
entity_path: ent_path,
time_point,
components,
} = bundle;
components: bundles,
Copy link
Member

Choose a reason for hiding this comment

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

isn't components a more descriptive name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, see above.

@jondo2010 jondo2010 mentioned this pull request Feb 6, 2023
3 tasks
/// If specified, connects and sends the logged data to a remote Rerun viewer.
#[clap(long)]
#[allow(clippy::option_option)]
addr: Option<Option<String>>,
Copy link
Member

Choose a reason for hiding this comment

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

haha, that's… interesting

Copy link
Member Author

Choose a reason for hiding this comment

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

🙃 I guess I should rename it to connect though, that would flow more naturally

Copy link
Member

Choose a reason for hiding this comment

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

yeah, agree

@teh-cmc teh-cmc merged commit f3dc81a into main Feb 6, 2023
@teh-cmc teh-cmc deleted the cmc/rust_sdk_msg_builder branch February 6, 2023 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants