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

fix(store): Apply clock drift correction based on received_at #580

Merged
merged 1 commit into from
May 18, 2020

Conversation

jan-auer
Copy link
Member

@jan-auer jan-auer commented May 15, 2020

Moves clock drift correction into its own processor. The clock drift is now defined as received_at - sent_at, where the two components are defined as:

  • sent_at: The timestamp of the client at which the request was sent to the server.
  • received_at: The timestamp when the request reached the Relay endpoint.

Both timestamps are propagated into the store normalizer, where they are applied by a new ClockDriftProcessor. The event's timestamp is no longer used, since event submission may be delayed. The minimum drift is 55 minutes; anything lower will skip clock drift correction.

Fixes #534
Fixes #535

@jan-auer jan-auer requested a review from a team May 15, 2020 15:15
@jan-auer jan-auer self-assigned this May 15, 2020
@@ -31,6 +32,8 @@ pub struct StoreConfig {
pub protocol_version: Option<String>,
pub grouping_config: Option<Value>,
pub user_agent: Option<String>,
pub received_at: Option<DateTime<Utc>>,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is only optional to retain Default for StoreConfig. Effectively, it is always set in the event processor. Internally, StoreProcessor defaults to Utc::now if we ever choose to not pass a value here.

@@ -519,6 +520,7 @@ impl EventProcessor {
remove_other: Some(true),
normalize_user_agent: Some(true),
sent_at: envelope.sent_at(),
received_at: Some(relay_common::instant_to_date_time(start_time)),
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 convert from Instant to DateTime as close as possible to normalization to ensure we have an accurate clock.

@jan-auer jan-auer requested a review from HazAT May 15, 2020 15:18
Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

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

Logically LGTM I can't really judge the implementation.
The only thing I see is that the unit tests only test event.timestamp, event.start_timestamp and not breadcrumbs/spans. I suppose this is tested somewhere else.

@dashed
Copy link
Member

dashed commented May 18, 2020

@jan-auer What was the reason for choosing 55 minutes as the minimum threshold for deciding a clock drift occurred?

use crate::protocol::Event;
use crate::types::{Error, ErrorKind, Meta, ProcessingResult, Timestamp};

/// The minimum clock drift for correction to apply.
Copy link
Member

Choose a reason for hiding this comment

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

Would add the reasoning here or move the processor's docstring to the module-level

Copy link
Member Author

Choose a reason for hiding this comment

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

This is already on the doc-string ClockDriftProcessor, which will be exported in a later PR (so that it can be used by non-processing Relays).

@dashed you can find the reasoning in that same docstring:

/// There is a minimum clock drift of _55 minutes_ to compensate for network latency and small clock
/// drift on the sender's machine, but allow to detect timezone differences. For differences lower
/// than that, no correction is performed.

Let me know if you'd like me to clarify.

relay-common/Cargo.toml Show resolved Hide resolved
let timestamp_meta = event.timestamp.meta_mut();
timestamp_meta.add_error(Error::with(ErrorKind::InvalidData, |e| {
let reason = format!(
"clock drift: all timestamps adjusted by {}",
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge fan of producing error messages here, we might want to refactor _meta to emit reason codes (not related to this PR in particular, just for the future)

Copy link
Member Author

Choose a reason for hiding this comment

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

The ErrorKind you saw is such a reason code, but I didn't want to touch Sentry for this now. If you like, we can follow up with a new error kind and then teach Sentry about it.

@HazAT
Copy link
Member

HazAT commented May 18, 2020

@dashed https://github.com/getsentry/relay/pull/580/files#diff-ad89addad454e6fa19b045a03bd12a1fR61-R63

@jan-auer jan-auer merged commit 4d531ff into master May 18, 2020
@jan-auer jan-auer deleted the fix/clock-drift-correciton branch May 18, 2020 11:00
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.

TransactionsProcessor modifies event timestamps by default Fragile clock drift correction
4 participants