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

crypto: Include event timestamp in decryption failure logs #3194

Merged
merged 7 commits into from
Mar 11, 2024

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Mar 7, 2024

Turns out this is quite useful information when analysing decryption failures.

@richvdh richvdh requested a review from a team as a code owner March 7, 2024 13:11
@richvdh richvdh requested review from bnjbvr and removed request for a team March 7, 2024 13:11
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Sweet, just want a small API tweak and this can be merged!

// a max year of 285427, so this can overflow for very large timestamps. (The
// Y10K problem!)
match OffsetDateTime::from_unix_timestamp_nanos(nanos_since_epoch) {
Err(_) => "<out of range>".to_owned(),
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 bad API smell that the utility function decides what to do in case of errors. Instead, could we have this method return Option<String>, and in this branch it could return None?

(or more concisely:

OffsetDateTime::from_unix_timestamp_nanos(nanos_since_epoch).ok()?.format(&...)

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 take your point, but I feel like that is somewhat in conflict with its intended use; if we use this function in several span.record calls, each of them is going to end up with an identical .unwrap_or("<out_of_range>) incantation and pretty soon we'll want another utility function to reduce the duplication.

Maybe the duplication is ok though?

Copy link
Member

Choose a reason for hiding this comment

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

I think the duplication would be OK, I also get the function is an internal utility. But having it return Option could also make it so that we avoid the unwrap below, so I'm tempted to insist just a bit on returning an Option here, even though overall I don't have a very strong opinion.

// Y10K problem!)
match OffsetDateTime::from_unix_timestamp_nanos(nanos_since_epoch) {
Err(_) => "<out of range>".to_owned(),
Ok(dt) => dt.format(&Iso8601::<ISO8601_WITH_MILLIS>).unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

We try to avoid unwrap() without a SAFETY: comment that explains why it's safe to unwrap here. Can you add that? (Or consider returning None instead incase of error/none?)

@bnjbvr bnjbvr changed the title Include event timestamp in decryption failure logs crypto: Include event timestamp in decryption failure logs Mar 7, 2024
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 83.83%. Comparing base (8e64341) to head (b6ededa).
Report is 26 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk-crypto/src/machine.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3194      +/-   ##
==========================================
- Coverage   83.84%   83.83%   -0.01%     
==========================================
  Files         232      232              
  Lines       23919    23925       +6     
==========================================
+ Hits        20054    20058       +4     
- Misses       3865     3867       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richvdh richvdh requested a review from bnjbvr March 7, 2024 17:45
@richvdh
Copy link
Member Author

richvdh commented Mar 7, 2024

Have hopefully addressed the review comments.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

lgtm!

crates/matrix-sdk-crypto/src/machine.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto/src/machine.rs Outdated Show resolved Hide resolved
richvdh and others added 2 commits March 7, 2024 18:02
Co-authored-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Richard van der Hoff <[email protected]>
@poljar poljar merged commit 1ea1632 into main Mar 11, 2024
34 checks passed
@poljar poljar deleted the rav/event_ts_in_logs branch March 11, 2024 12:16
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.

3 participants