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

feat(clock-drift): Apply clock drift normalization only if sent_at is defined #3405

Merged
merged 8 commits into from
Apr 12, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Apr 10, 2024

This PR applies clock drift normalization only when sent_at is defined in the envelope headers.

The previous implementation was falling back to event.timestamp if the incoming event was a transaction. That was expected behavior for old SDKs which didn't send sent_at however we do not have anymore SDKs using the /store endpoint, which means that we can assume that sent_at is sent for each envelope. If not sent, we won't perform clock drift normalization instead of using event.timestamp like before.

Closes: #1625

@@ -308,30 +314,30 @@ fn normalize_timestamps(
) {
let received_at = received_at.unwrap_or_else(Utc::now);

let mut sent_at = None;
let mut event_timestamp = None;
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed because I didn't want confusion with the new has_sent_at property.

@iambriccardo iambriccardo force-pushed the riccardo/fix/correctly-apply-clock-drift branch from cd61803 to 4ec8bdc Compare April 10, 2024 13:28
@iambriccardo iambriccardo changed the title feat(clock-drift): Do not apply clock drift normalization if is not sent feat(clock-drift): Remove event.timestamp from clock normalization Apr 10, 2024
@iambriccardo iambriccardo changed the title feat(clock-drift): Remove event.timestamp from clock normalization feat(clock-drift): Apply clock drift normalization only if sent_at is defined Apr 10, 2024
@iambriccardo iambriccardo marked this pull request as ready for review April 10, 2024 14:18
@iambriccardo iambriccardo requested a review from a team as a code owner April 10, 2024 14:18
@iker-barriocanal
Copy link
Contributor

That was expected behavior for old SDKs but now it should not be needed anymore.

What are the SDK versions where this is fixed? Do we have a big event influx from these outdated versions? Bonus points if this is documented in develop docs!

@Dav1dde
Copy link
Member

Dav1dde commented Apr 11, 2024

    // TODO: Temporary workaround before processing. Experimental SDKs relied on a buggy
    // clock drift correction that assumes the event timestamp is the sent_at time. This
    // should be removed as soon as legacy ingestion has been removed.

Curious what this has to do with the legacy ingestion (I assume directly to Sentry).

@iambriccardo
Copy link
Member Author

    // TODO: Temporary workaround before processing. Experimental SDKs relied on a buggy
    // clock drift correction that assumes the event timestamp is the sent_at time. This
    // should be removed as soon as legacy ingestion has been removed.

Curious what this has to do with the legacy ingestion (I assume directly to Sentry).

@jan-auer mentioned this in one of our private discussions. From what I understood, the store endpoint is used by old SDKs that send envelopes without the sent_at header assuming that the event timestamp is the same as the time the envelope is sent. New SDKs, are sending envelopes with the sent_at which differs from event timestamp.

CHANGELOG.md Outdated
- Allow spans with no `exclusive_time`. ([#3385](https://github.com/getsentry/relay/pull/3385))
- Perform clock drift normalization only when `sent_at` is set in the `Envelope` headers. ([#3405](https://github.com/getsentry/relay/pull/3405))
Copy link
Member

Choose a reason for hiding this comment

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

Please move Bug Fixes to above Features, it's the first thing people should read IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, will do.

timeout=1
).get_transaction_event()
error_name, error_metadata = transaction_event["_meta"]["timestamp"][""]["err"][0]
assert error_name == "clock_drift"
Copy link
Member

Choose a reason for hiding this comment

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

Should we also assert on the actual timestamps in the event? (Same for tests below).

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 was considering it, my only problem was that received_at seems to be inferred by Relay on receive time, so I might have to either mock things or freeze time but it seems like this is not possible in an integration test.

Copy link
Member Author

Choose a reason for hiding this comment

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

What I know is that sdk_time will be one_month_ago and server_time will be received_at and the new timestamp is + the difference of the above.

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 opted for a middle ground, I do test for > in the timestamps which should be normalized, and = when the timestamps must remain the same.

Copy link
Member

Choose a reason for hiding this comment

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

The assert could be a much smaller window though, right? transaction_event["timestamp"] > now.timestamp()

Copy link
Member Author

Choose a reason for hiding this comment

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

If there was a way to freeze or hardcode the received_at time, I could compute the exact test expectations.

If we can't, to make the test more precise, we could assert transaction_event["timestamp"] == now within some bounds but I am not super confident to define them since they are dependent on the time it takes for the integration test to run and I would not want to introduce a flaky test.

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't exactly assert, but if you compare to the now value taken at the beginning of the test, that should be good, additionally you could also take another "now" value at the end and check whether the expected value is between those. I wouldn't try to freeze time etc. that will just break at some point. Being within a few seconds should be good enough.

@jjbayer
Copy link
Member

jjbayer commented Apr 11, 2024

@iambriccardo in the PR description, could you elaborate a bit more on why this is now OK? (Transactions no longer sent to /store endpoint...).

@iambriccardo iambriccardo requested a review from jjbayer April 11, 2024 12:11
@Dav1dde
Copy link
Member

Dav1dde commented Apr 11, 2024

Re store endpoint, but these old (broken?) SDKs are still sending data, why can we change it now?

@jan-auer
Copy link
Member

This was used just for beta SDKs while Performance monitoring was experimental. As we launched the first stable version of Performance Monitoring to general availability, we required an SDK upgrade. Hence this is safe to remove.

@Dav1dde
Copy link
Member

Dav1dde commented Apr 11, 2024

Nice, thanks!

timeout=1
).get_transaction_event()
error_name, error_metadata = transaction_event["_meta"]["timestamp"][""]["err"][0]
assert error_name == "clock_drift"
Copy link
Member

Choose a reason for hiding this comment

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

The assert could be a much smaller window though, right? transaction_event["timestamp"] > now.timestamp()

@iambriccardo iambriccardo merged commit 368ec8c into master Apr 12, 2024
20 checks passed
@iambriccardo iambriccardo deleted the riccardo/fix/correctly-apply-clock-drift branch April 12, 2024 06:53
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.

Clock drift correction is applied to envelopes without sent_at
5 participants