-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
61eb4da
to
8796748
Compare
body, | ||
body: { | ||
...baseBody, | ||
last_api_heartbeat_state_change_event: Date.now(), |
There was a problem hiding this comment.
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 settinglast_api_heartbeat_state_change_event
whenevervalues.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.
8796748
to
f9d82ef
Compare
f9d82ef
to
2475c4f
Compare
2475c4f
to
1f0fb21
Compare
There was a problem hiding this 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?
body: { | ||
...baseBody, | ||
last_changed_api_heartbeat_state_on__date: Date.now(), | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
test/03_device-state.ts
Outdated
await expectResourceToMatch( | ||
getActor(), | ||
'device', | ||
getDevice().id, | ||
{ | ||
api_heartbeat_state: DeviceOnlineStates.Timeout, | ||
last_changed_api_heartbeat_state_on__date: | ||
thatIsDateStringAfter(stateUpdatedAfter), | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@fisehara in an ideal world we would add a 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
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. |
cb7b927
to
3cf1097
Compare
3cf1097
to
6adb950
Compare
6adb950
to
31ff1bd
Compare
31ff1bd
to
f4251ac
Compare
f4251ac
to
bcc5701
Compare
72f0293
to
e1a0271
Compare
e1a0271
to
934e78a
Compare
934e78a
to
e604777
Compare
Thank you @fisehara I will make this part of the next cycle, so that we confirm the name again ❤️ |
Pull request was converted to draft
@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. |
@dfunckt the 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 |
e604777
to
27720a4
Compare
d7ad4de
to
01ab2c8
Compare
0945082
to
9576f4a
Compare
9576f4a
to
a28dfa8
Compare
Resolves: #644
Change-type: minor
See: https://balena.fibery.io/Work/Project/Start-recording-the-last-timestamp-the-device-heartbeat-changed-254