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

Add the device.changed_api_heartbeat_state_on__date term to the model #1343

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

thgreasi
Copy link
Member

@thgreasi thgreasi commented May 9, 2023

@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch 2 times, most recently from 61eb4da to 8796748 Compare May 9, 2023 13:17
@thgreasi thgreasi requested a review from Page- May 9, 2023 13:44
body,
body: {
...baseBody,
last_api_heartbeat_state_change_event: Date.now(),
Copy link
Member Author

Choose a reason for hiding this comment

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

I originally added this as a hook, but at the end I preferred moving it here

  • so that we can avoid the extra .get() request to confirm that the value has indeed changed, or blindly setting last_api_heartbeat_state_change_event whenever values.api_heartbeat_state != null.
  • since this is the only place that we should be updating the heartbeat anyway.

Let me know though if you prefer to switch it back to hooks.

@thgreasi thgreasi marked this pull request as ready for review May 9, 2023 13:49
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 8796748 to f9d82ef Compare May 16, 2023 14:52
@flowzone-app flowzone-app bot enabled auto-merge May 16, 2023 14:53
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from f9d82ef to 2475c4f Compare May 16, 2023 14:54
@thgreasi thgreasi changed the title Add last_api_heartbeat_state_change_event to the device model Add last_changed_api_heartbeat_state_on__date to the device model May 16, 2023
@thgreasi thgreasi requested a review from fisehara May 16, 2023 14:55
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 2475c4f to 1f0fb21 Compare May 16, 2023 14:55
Copy link
Contributor

@fisehara fisehara left a comment

Choose a reason for hiding this comment

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

Unfortunately I don't understand properly what this added property adds to the device state information?
Do we want to convey the last proper heartbeat time or do we want to surface all changes of heartbeat event states?
Eg. when it's set to online over and over again, it would be of interest when the last time the heartbeat was set to online, or am I mixing things up?

Comment on lines 260 to 272
body: {
...baseBody,
last_changed_api_heartbeat_state_on__date: Date.now(),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if last_changed_api_heartbeat_state_on__date should only be updated when called via: await this.updateDeviceModel(deviceId, DeviceOnlineStates.Online);
and not when patching it to timeout or offline? As these events are internal events that do not show the device are heartbeating anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

The intention here is to track when the heartbeat was changes both for any reason (both from state-GETs and from heartbeat changes b/c of the heartbeat mechanism). Knowing then the device switched to Timeout/Offline is probably more useful than knowing since when the device originally started heartbeating.

Comment on lines 301 to 309
await expectResourceToMatch(
getActor(),
'device',
getDevice().id,
{
api_heartbeat_state: DeviceOnlineStates.Timeout,
last_changed_api_heartbeat_state_on__date:
thatIsDateStringAfter(stateUpdatedAfter),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

When we use the last_changed_api_heartbeat_state_on__date what do we want to convey? Do we want to convey when the device was last seen with a proper heartbeat or when the heartbeat status changes from online, to timeout, to offline?
How will we use the timeout and offline timestamps, eg as indicator in the UI?

Copy link
Member Author

Choose a reason for hiding this comment

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

We want to convey when the heartbeat status changed in general for all possible transitions.
Similarly to how UI atm uses the last vpn even to show

  • online since
  • offline since

with this field it can show

  • heartbeating since
  • heartbeat timeout since
  • heartbeat offline since

On top of that this also allows us t compute the last heartbeat if needed on read time:

Given this field, with a simple computation using the device's poll interval, a client/computed term could easily compute even more useful information on read time, eg: compute the last heartbeat for a non-Online device.

@thgreasi
Copy link
Member Author

thgreasi commented May 17, 2023

Unfortunately I don't understand properly what this added property adds to the device state information?
Do we want to convey the last proper heartbeat time or do we want to surface all changes of heartbeat event states?
Eg. when it's set to online over and over again, it would be of interest when the last time the heartbeat was set to online, or am I mixing things up?

@fisehara in an ideal world we would add a device has last heartbeat on date, but that would tons of load on the writer, effectively making all state GETs do DB writes. This is exactly why we had to add the heartbeat update cache mechanism in the heartbeat implementation, so that we can reduce the writer load.

Given that we can't do the above, we started thinking what fact related to heartbeat we could store that would come with low DB load impact, and that's how we ended up with last_changed_api_heartbeat_state_on__date in that arch call since:

  • it doesn't add extra DB load, since we do the write along with the operation that changes the heartbeat (and PG rewrites the whole row anyway)
  • we can compute more interesting information on read based on this

Part of the reasoning in the arch call was that we atm have no additional info about the heartbeat, so adding any kind of free field is better than the no info that we atm have.

Even w/o extra computations, being able to surface when a device last switched to Online/Timeout/Offline does have some value, especially when compared w/ how atm we have no more info about the heartbeat (and we have to dive into Redis to get more).

Given this field, with a simple computation using the device's poll interval, a client/computed term could easily compute even more useful information on read time, eg: compute the last heartbeat for a non-Online device.

@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch 2 times, most recently from cb7b927 to 3cf1097 Compare June 14, 2023 19:46
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 3cf1097 to 6adb950 Compare July 17, 2023 09:19
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 6adb950 to 31ff1bd Compare August 30, 2023 06:58
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 31ff1bd to f4251ac Compare September 28, 2023 07:13
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from f4251ac to bcc5701 Compare October 30, 2023 07:15
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch 3 times, most recently from 72f0293 to e1a0271 Compare December 15, 2023 15:50
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from e1a0271 to 934e78a Compare February 6, 2024 15:57
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 934e78a to e604777 Compare March 13, 2024 16:45
@thgreasi
Copy link
Member Author

Thank you @fisehara I will make this part of the next cycle, so that we confirm the name again ❤️

@thgreasi thgreasi marked this pull request as draft April 3, 2024 12:56
auto-merge was automatically disabled April 3, 2024 12:56

Pull request was converted to draft

@dfunckt
Copy link
Member

dfunckt commented Jul 23, 2024

@thgreasi I wonder if having a “state last modified date” instead would be sufficient, ie the date the device last switched between Online, Downloading, etc. states.

That would allow us to show eg. “Downloading” and “for 10 minutes”, or something similar.

It would also be useful to filter/order by this field in the device list and check if I, as a fleet operator, need to intervene—3 days in Downloading state clearly means something is off.

cc @shaunmulligan

@thgreasi
Copy link
Member Author

@dfunckt the device.state is whatever the supervisor reports & is not changing based on the vpn.
The device.overall_status is computed term that depends on the heartbeat state on the other hand has different definitions between v6 & v7, so in order to capture the change date of the overall_status we would need to be computing & storing the value for both versions (or ignore v6 for example).

That's why we ended up deciding (years back) that storing the change date of the most primitive value is probably better, since the data is still usable even if we change how overall_status gets computed.

@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from e604777 to 27720a4 Compare August 5, 2024 14:45
@thgreasi thgreasi changed the title Add last_changed_api_heartbeat_state_on__date to the device model Add the device.last_api_heartbeat_change_date term to the model Aug 5, 2024
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch 4 times, most recently from d7ad4de to 01ab2c8 Compare August 7, 2024 05:17
@thgreasi thgreasi changed the title Add the device.last_api_heartbeat_change_date term to the model Add the device.changed_api_heartbeat_state_on__date term to the model Aug 7, 2024
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch 2 times, most recently from 0945082 to 9576f4a Compare September 4, 2024 10:49
@thgreasi thgreasi force-pushed the 644-last_api_heartbeat_state_change_event branch from 9576f4a to a28dfa8 Compare September 5, 2024 16:41
@thgreasi thgreasi marked this pull request as ready for review September 6, 2024 08:14
@thgreasi thgreasi merged commit 09dfb35 into master Sep 6, 2024
50 checks passed
@thgreasi thgreasi deleted the 644-last_api_heartbeat_state_change_event branch September 6, 2024 08:14
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.

Should store the last the heartbeat changed (last api heartbeat state change event?)
3 participants