-
Notifications
You must be signed in to change notification settings - Fork 94
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
ref(relay): Use DateTime
instead of Instant
for start_time
#4184
Conversation
DateTime
instead of Instant
for start_time
/// Returns the [`ReceivedAt`] corresponding to provided timestamp. | ||
pub fn from_timestamp_millis(timestamp: i64) -> Self { | ||
let datetime = DateTime::<Utc>::from_timestamp_millis(timestamp).unwrap_or_else(Utc::now); | ||
|
||
Self(datetime) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed.
fn start_time_from_timestamp() { | ||
let elapsed = Duration::from_secs(10); | ||
let now = Utc::now(); | ||
let past = now - chrono::Duration::from_std(elapsed).unwrap(); | ||
let start_time = ReceivedAt::from_timestamp_millis(past.timestamp_millis()).into_inner(); | ||
|
||
// Check that the difference between the now and generated start_time is about 10s | ||
let diff = now - start_time; | ||
let diff_duration = diff.to_std().unwrap(); | ||
assert!(diff_duration < elapsed + Duration::from_millis(50)); | ||
assert!(diff_duration > elapsed - Duration::from_millis(50)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was changed with the same logic.
@@ -26,7 +29,7 @@ pub async fn metrics(mut request: Request, next: Next) -> Response { | |||
let response = next.run(request).await; | |||
|
|||
relay_statsd::metric!( | |||
timer(RelayTimers::RequestsDuration) = start_time.into_inner().elapsed(), | |||
timer(RelayTimers::RequestsDuration) = request_start.elapsed(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now use received_at
as DateTime
I wanted to still use an Instant
for monitoring the request duration.
sent_at, | ||
source, | ||
} = message; | ||
|
||
let received_timestamp = UnixTimestamp::from_instant(start_time); | ||
let received_timestamp = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deemed the unwrap_or
as a safe operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by this? Why wouldn't it be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By safe I meant semantically, meaning if it makes sense to default to now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, defaulting to 1970-01-01 (UnixTimestamp::from_secs(0)
) would make sense semantically, because from_datetime
returns None
only if the datetime is less than that. Either way it's a programming error or data corruption if it happens, since we control received_at
ourselves.
This PR changes the
start_time
field of several components within Relay from typeInstant
toDateTime<Utc>
and renames it toreceived_at
.Closes: https://github.com/getsentry/team-ingest/issues/564