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

ref: Use Duration to compute breakdowns and span durations [INGEST-1131] #1260

Merged
merged 5 commits into from
May 4, 2022

Conversation

jan-auer
Copy link
Member

@jan-auer jan-auer commented May 4, 2022

Instead of using raw f64, this PR switches to using Duration for computing span durations and breakdowns. This allows to pass the values around without the additional knowledge in which unit they are. Currently, this was only described in comments.

As part of this refactor, I'm simplifying the actual computation algorithm. There are two repeated changes:

  • Remove redundant code. Especially in time_spent, there were redundant allocations when collecting spans.
  • When converting durations to float milliseconds, do not drop the sub-millisecond part.
  • Use interval clamping rather than a series of comparisons.

It was actually not necessary to perform this refactor just for introducing custom units because breakdowns are always created as milliseconds within Relay.

This is a follow-up to #1256
#skip-changelog

@jan-auer jan-auer requested a review from a team May 4, 2022 12:56
@jan-auer jan-auer self-assigned this May 4, 2022
Some(get_duration_millis(start_timestamp, end_timestamp))
}
SatisfactionMetric::Duration => Some(relay_common::signed_duration_to_millis(
end_timestamp - start_timestamp,
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 this was intentionally a saturating_sub. But this sort of normalization behavior I do think we want to have in a centralized function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Check the doc comment and implementation of signed_duration_to_millis. It has that normalization behavior now, so we no longer need to perform a saturating sub here.

Copy link
Member

Choose a reason for hiding this comment

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

ah okay. hmm. it kinda does mean that the duration can underflow now before it is clamped. I am not sure how this is handled by chrono but probably not likely enough

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 subtraction is Sub<DateTime<Utc>> for DateTime<Utc> which is runs signed_duration_since internally. That method is documented with:

This does not overflow or underflow at all.

relay-common/src/time.rs Show resolved Hide resolved
(delta / 1_000_000.00).abs()
pub fn duration(&self) -> Duration {
// Cannot fail since durations are ordered in the constructor
(self.end - self.start).to_std().unwrap_or_default()
Copy link
Member

Choose a reason for hiding this comment

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

nit: We could also make TimeWindowSpan store a timestamp and a duration to make the unwrap here unnecessary.

@jan-auer jan-auer enabled auto-merge (squash) May 4, 2022 14:43
@jan-auer jan-auer merged commit 322210f into master May 4, 2022
@jan-auer jan-auer deleted the feat/breakdowns-duration branch May 4, 2022 14:53
jan-auer added a commit that referenced this pull request May 13, 2022
* master:
  feat(sampling): Support custom tags and more contexts (#1268)
  deps: Update symbolic to pull in Unreal parser fixes (#1266)
  Bring in CLA Lite (#1257)
  release: 0.8.11
  ref(profiling): Normalize all profiles (#1250)
  feat(profiling): Add a profile data category and count profiles in an envelope to apply rate limits (#1259)
  fix: Raise a new InvalidCompression Outcome for invalid Unreal compression (#1237)
  chore: Update logo for dark or light theme (#1262)
  ref: Use Duration to compute breakdowns and span durations (#1260)
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