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

Bug 1751402 - Guarantee getMonotonicNow doesn't return a negative value #1130

Merged
merged 3 commits into from
Jan 28, 2022

Conversation

brizental
Copy link
Contributor

@brizental brizental commented Jan 26, 2022

We were previously extracting the TIME_ORIGIN from Date.now()
in case performance.now was not available in the environment.

That could create negative timestamps, because Date.now is not
guaranteed to be monotonically increasing. (Yeah... it is
contradictiory to have a function called getMonotonicNow, but not
guarantee monotonically increasing timestamps for some platforms.
At least there is a TODO comment to address the incoherence at
some point).

Subtracting the TIME_ORIGIN was essentially pointless and I don't really
know why that was the case before. That function is used by the Timestamp
metric type and for event timestamps which are both about elapsed time,
so the absoulte timestamp should not matter.

EXTRA: Address stray TODO comment on TimespanMetricType test suite.

Pull Request checklist

  • Quality: Make sure this PR builds and runs cleanly.
    • Inside the glean/ folder, run:
      • npm run test Runs all tests
      • npm run lint Runs all linters
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry to CHANGELOG.md or an explanation of why it does not need one
  • Documentation: This PR includes documentation changes, an explanation of why it does not need that or a follow-up bug has been filed to do that work

@auto-assign auto-assign bot requested a review from chutten January 26, 2022 09:57
@brizental brizental requested review from badboy and removed request for chutten January 27, 2022 10:25
@chutten
Copy link
Contributor

chutten commented Jan 27, 2022

Oops, sorry I didn't get to this yesterday as I planned.

Is it the storage that's responsible for setting the first event's timestamp to 0, then?

@brizental
Copy link
Contributor Author

Oops, sorry I didn't get to this yesterday as I planned.

No worries, jan-erik asked about it that is why I marked him as reviewer :D

Is it the storage that's responsible for setting the first event's timestamp to 0, then?

Yeah it is: https://github.com/mozilla/glean.js/blob/main/glean/src/core/metrics/events_database/index.ts#L286

We were previously extracting the TIME_ORIGIN from Date.now()
in case performance.now was not available in the environment.

That could create negative timestamps, because Date.now is not
guaranteed to be monotonically increasing. (Yeah... it is
contradictiory to have a function called getMonotonicNow, but not
guarantee monotonically increasing timestamps for some platforms.
At least there is a TODO comment to address the incoherence at
some point).

Subtracting the TIME_ORIGIN was essentially pointless and I don't really
know why that was the case before. That function is used by the Timestamp
metric type and for event timestamps which are both about elapsed time.

EXTRA: Address stray TODO comment on TimespanMetricType test suite.
@brizental brizental force-pushed the 1751402-event-timestamp-error branch from 0555893 to f90731b Compare January 28, 2022 10:34
@brizental brizental merged commit d85d174 into mozilla:main Jan 28, 2022
@brizental brizental deleted the 1751402-event-timestamp-error branch January 28, 2022 12:51
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