Skip to content

lib/ur: Don't report uptime if start time is in the past (fixes #7698) - #8996

Merged
calmh merged 4 commits into
syncthing:mainfrom
tomasz1986:tomasz86/lib/ur/ignore-unix-epoch-uptime
Jul 22, 2023
Merged

calmh merged 4 commits into
syncthing:mainfrom
tomasz1986:tomasz86/lib/ur/ignore-unix-epoch-uptime

Conversation

@tomasz1986

@tomasz1986 tomasz1986 commented Jul 21, 2023 •

Copy link
Copy Markdown
Member

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]

@tomasz1986
tomasz1986 force-pushed the tomasz86/lib/ur/ignore-unix-epoch-uptime branch from 0f1b9df to 3b8ead4 Compare July 21, 2023 18:13
@tomasz1986

tomasz1986 commented Jul 21, 2023 •

Copy link
Copy Markdown
Member Author

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.

Comment thread lib/ur/usage_report.go Outdated

func (*Service) UptimeS() int {
return int(time.Since(StartTime).Seconds())
if int(time.Since(StartTime).Seconds()) != int(time.Now().Unix()) {

@calmh calmh Jul 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(we should maybe also filter unrealistic values in the usage report receiver)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

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]>
@tomasz1986
tomasz1986 force-pushed the tomasz86/lib/ur/ignore-unix-epoch-uptime branch from 3b8ead4 to 74a9b2e Compare July 21, 2023 22:16
@tomasz1986 tomasz1986 changed the title lib/ur: Don't report uptime if equal to Unix epoch (fixes #7698) lib/ur: Don't report uptime if start time is in the past (fixes #7698) Jul 21, 2023
@acolomb

acolomb commented Jul 21, 2023

Copy link
Copy Markdown
Member

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.

Comment thread lib/ur/usage_report.go Resolved
Comment thread lib/ur/usage_report.go Resolved
Comment thread lib/ur/usage_report.go Resolved
@calmh
calmh enabled auto-merge (squash) July 22, 2023 21:09
@calmh
calmh merged commit f42f041 into syncthing:main Jul 22, 2023
calmh added a commit to calmh/syncthing that referenced this pull request Jul 25, 2023
* 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
calmh added a commit to calmh/syncthing that referenced this pull request Jul 25, 2023
* 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)
@calmh calmh added this to the v1.23.7 milestone Jul 31, 2023
@tomasz1986
tomasz1986 deleted the tomasz86/lib/ur/ignore-unix-epoch-uptime branch September 12, 2023 18:40
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jul 22, 2024
@syncthing syncthing locked and limited conversation to collaborators Jul 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ursrv: unrealistic uptime data, likely due to unset RTC (1970-01-01)

4 participants