Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some context about the
time_adjusted
functionThe
time_adjusted
function returns a value calculated for a minute. Itreceived two values, for which it calculates the delta first. Then,
using the
time_difference_ns
value (the time in which these valueswere measured), it calculates the value as it would be for a full
minute.
When the
time_difference_ns
is 59 seconds or 61 seconds it returns thevalue as it would be for 60 seconds instead. This helps account for
small drift within the time at which the metrics were measured.
The problem
The previous implementation of the time_adjusted function would multiple
the delta value by the real time (30 seconds) and divide that value by
60 seconds.
The problem here was that it would not return the value for 60 seconds,
but instead that for 15 seconds, half of 30 seconds.
5.0 being half of 10.0 (the delta), half of 30 seconds.
The fix
Instead of multiplying the delta by
time_difference_ns
we shoulddivide the delta by the
time_difference_ns
to get the value pernanosecond (ns). Then we multiply that 1 nanosecond value by 60 seconds.
This will return the average value for 60 seconds.
20.0 being double of 10.0 (the delta), double of 30 seconds.