endlessm / azafea

Service to track device activations and usage metrics
Mozilla Public License 2.0
10 stars 2 forks source link

Use the server’s clock when it’s obviously better than the client’s #162

Closed liZe closed 3 years ago

liZe commented 3 years ago

This is the last part of the timestamp algorithm: https://azafea.readthedocs.io/en/latest/timestamp-algorithm.html#server-side

"When the server receives a network request, it will first examine the network request absolute time to see if it varies significantly from its own (trusted) clock. If it does, some special action will be taken with that request, such as putting it in its own special table or attempting to correct the timestamp in some fashion."

Our "attempt to correct the timestamp" happens when:

~https://phabricator.endlessm.com/T29275~ https://phabricator.endlessm.com/T32195

wjt commented 3 years ago

Wrong ticket, I think https://phabricator.endlessm.com/T32195 is the one, and the linked one can track the existence of the problem for existing v2 data.

@dbnicholson could you take a look here?

liZe commented 3 years ago

It fixes ~10% of the events we will receive. For the record, interesting stats are here: https://phabricator.endlessm.com/T31727#884096.

liZe commented 3 years ago

Looks good. I don't know how the test was passing before, but this makes more sense.

When the difference is big, we keep the server time, no matter how big the difference is. The difference was huge with the previous code, it’s now just an hour, but the result is the same and the test passes in both cases.