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

Bump qlog to 0.9.0 #1454

Merged
merged 5 commits into from
Oct 13, 2023
Merged

Bump qlog to 0.9.0 #1454

merged 5 commits into from
Oct 13, 2023

Conversation

LPardue
Copy link
Contributor

@LPardue LPardue commented Jul 22, 2023

Later versions of the qlog crate provided a serializer that uses the JSON-SEQ streaming format, which uses a .sqlog file extension. The format helps the crate avoid needing to "lock" and "unlock" while writing events with frames. That clunkiness could make it hard for apps and might lead to mangled logs.

Later versions of the qlog crate also changed the data model, making it easier to interact directly with events and their data. This obviated the need for helper functions, so they were all removed and this PR needs to do the work to replace them.

@@ -698,7 +698,7 @@ fn client(
fn qlog_new(args: &Args, hostname: &str, cid: &ConnectionId) -> Res<NeqoQlog> {
if let Some(qlog_dir) = &args.qlog_dir {
let mut qlog_path = qlog_dir.to_path_buf();
let filename = format!("{}-{}.qlog", hostname, cid);
let filename = format!("{}-{}.sqlog", hostname, cid);
Copy link
Member

Choose a reason for hiding this comment

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

HmmSuspectGIF

early_data_enabled: None,
tls_cipher: None,
aead_tag_length: None,
original_destination_connection_id: remote
Copy link
Member

Choose a reason for hiding this comment

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

Do you implement Default for TransportParametersSet? Because then you could use ..Default::default() rather than providing all these None-valued arguments.

/// If logging enabled, closure may generate an event to be logged.
pub fn add_event_data<F>(&mut self, f: F)
where
F: FnOnce() -> Option<qlog::events::EventData>,
Copy link
Member

Choose a reason for hiding this comment

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

I can't see any places where an instance of F returns None. So maybe you can just do:

Suggested change
F: FnOnce() -> Option<qlog::events::EventData>,
F: FnOnce() -> qlog::events::EventData,

let mut pacing_rate: Option<u64> = None;

for metric in updated_metrics {
match metric {
QlogMetric::MinRtt(v) => min_rtt = Some(u64::try_from(v.as_millis()).unwrap()),
QlogMetric::MinRtt(v) => min_rtt = Some(v.as_secs_f32() * 1000.0),
Copy link
Member

Choose a reason for hiding this comment

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

Feature request for you: can you take these as Duration rather than f32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The qlog spec data model defines the value as float32; see https://quicwg.org/qlog/draft-ietf-quic-qlog-quic-events.html#section-7.2

The qlog crate data model tries to be as close to the spec as possible. I don't see much value in e.g. turning the crate to support enum foo(spec_def(f32), my_own_thing(Duration) because it would have to be converted to f32 on way or another.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I get that, but Rust native time types are more ergonomic.

You could maybe double-dip by implementing a trait:

trait IntoQlogTime {
  fn into_qlog_time(self) -> f32;
}
impl IntoQlogTime for f32 { ... }
impl IntoQlogTime for Duration { ... }

Though that helps more with if you also provide functions for instantiating the objects rather than making the fields public as you do (because then you can do x: impl IntoQlogTime arguments).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ta, I'm happy to add some syntactic sugar as a feature request

@martinthomson
Copy link
Member

I'll leave that last build/clippy error to you unless you would prefer that I fix it...

error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
   --> neqo-common/src/qlog.rs:136:22

@LPardue
Copy link
Contributor Author

LPardue commented Jul 23, 2023

I'll leave that last build/clippy error to you unless you would prefer that I fix it...

error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
   --> neqo-common/src/qlog.rs:136:22

Yeah saw this, I don't really have an opinion on solving it, do you?

datetime
.format(&time::format_description::well_known::Rfc3339)
.ok() // This is expected to never fail.
Some(datetime.unix_timestamp() as f64)
Copy link
Member

@martinthomson martinthomson Jul 24, 2023

Choose a reason for hiding this comment

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

Suggested change
Some(datetime.unix_timestamp() as f64)
Some(f64::try_from(datetime.unix_timestamp()).unwrap())

This probably works well enough.

Or, if you prefer:

Suggested change
Some(datetime.unix_timestamp() as f64)
let mask = -1 >> (i64::BITS - f64::MANTISSA_DIGITS);
Some(f64::try_from(datetime.unix_timestamp() & mask).unwrap())

@martinthomson martinthomson marked this pull request as ready for review October 13, 2023 00:49
@martinthomson martinthomson merged commit 892a84a into mozilla:main Oct 13, 2023
3 checks passed
@LPardue
Copy link
Contributor Author

LPardue commented Oct 13, 2023

Thanks for pushing this over the line. The suggestions for qlog changes are still on my todos list

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.

2 participants