Repository navigation
lib/ur: Don't report uptime if start time is in the past (fixes #7698) - #8996
Conversation
0f1b9df to
3b8ead4
Compare
|
I'm not 100% sure about this one. If a device has got no RTC clock and time hasn't been set manually (or synced via the Internet), it will start with time set to 1 January 1970, right? But then, if Syncthing gets started, its start time will already be later than the device start time. Is this correct? If yes, then this approach is wrong because it assumes that the Syncthing start time will be equal to the device start time, which will never happen. I'm considering using the Syncthing initial release date instead (which is supposedly December 15, 2013) and dropping everything older than that. |
|
|
||
| func (*Service) UptimeS() int { | ||
| return int(time.Since(StartTime).Seconds()) | ||
| if int(time.Since(StartTime).Seconds()) != int(time.Now().Unix()) { |
There was a problem hiding this comment.
This is somewhat fragile (comparison between two Now()s (one implicit in Since) with some time in between). How about something like if StartTime.Year() < 2023 { return 0 } since it's impossible for this code written now to see a start time in the past?
There was a problem hiding this comment.
(we should maybe also filter unrealistic values in the usage report receiver)
There was a problem hiding this comment.
(we should maybe also filter unrealistic values in the usage report receiver)
Good point because people may of course still be running older versions that will keep reporting those wrong uptime stats 🙃. I'll see what I can do about it.
There was a problem hiding this comment.
This is somewhat fragile (comparison between two
Now()s (one implicit inSince) with some time in between). How about something likeif StartTime.Year() < 2023 { return 0 }since it's impossible for this code written now to see a start time in the past?
Done! Force-pushed to fix the commit title and message.
I'm not sure how to proceed with filtering on the receiving side though. Do you mean https://github.com/syncthing/syncthing/tree/main/cmd/ursrv? Is there any way to test the code changes done there locally?
…hing#7698) Currently, because of devices with unset RTC clock, the 100% percentile for Uptime on [1] is calculated since the Unix epoch which is useless as far as usage statistics are concerned. Thus, if the Syncthing start time is set to a past date, assume that the clock is wrong and do not even try to report the uptime. [1] https://data.syncthing.net Signed-off-by: Tomasz Wilczyński <[email protected]>
3b8ead4 to
74a9b2e
Compare
|
As for devices without an RTC: From my experience with Raspberry PI and similar, the operating system saves the last known timestamp to a file during shutdown if possible. This gets used to initialize the clock during next boot. So the clock shouldn't be jumping backwards, and definitely not back to UNIX epoch. As long as this mechanism works, of course. |
* main: gui: Remove Twitter link from footer (syncthing#9000) gui, man, authors: Update docs, translations, and contributors lib/ur: Don't report uptime if start time is in the past (fixes syncthing#7698) (syncthing#8996) lib/model: use WARN for "Unexpected folder" messages (syncthing#8998) lib/osutil: Skip setLowPriority in Windows if already lower (fixes syncthing#6597) (syncthing#8993) all: replace empty slice literal with `var` (syncthing#8990) all: fix unused method receiver (syncthing#8988) all: unused parameter should be replaced by underscore (syncthing#8989) gui, man, authors: Update docs, translations, and contributors cmd/syncthing: Mention STVERSIONEXTRA in --help output (ref syncthing#8980) gui, lib/api: Add possibility to feed through extra version information (syncthing#8980) cmd/ursrv: Update map tile URL cmd/strelaypoolsrv: Update map tile URL (syncthing#8985) cmd/stcrashreceiver: Correct parsing of current version string
* main: gui: Remove Twitter link from footer (syncthing#9000) gui, man, authors: Update docs, translations, and contributors lib/ur: Don't report uptime if start time is in the past (fixes syncthing#7698) (syncthing#8996) lib/model: use WARN for "Unexpected folder" messages (syncthing#8998) lib/osutil: Skip setLowPriority in Windows if already lower (fixes syncthing#6597) (syncthing#8993) all: replace empty slice literal with `var` (syncthing#8990) all: fix unused method receiver (syncthing#8988) all: unused parameter should be replaced by underscore (syncthing#8989)
lib/ur: Don't report uptime if start time is in the past (fixes #7698)
Currently, because of devices with unset RTC clock, the 100% percentile
for Uptime on [1] is calculated since the Unix epoch which is useless as
far as usage statistics are concerned. Thus, if the Syncthing start time
is set to a past date, assume that the clock is wrong and do not even
try to report the uptime.
[1] https://data.syncthing.net
Signed-off-by: Tomasz Wilczyński [email protected]