-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
bring back last_seen in database #2579
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -409,6 +409,10 @@ func (h *Headscale) updateNodeOnlineStatus(online bool, node *types.Node) { | |
| change.LastSeen = &now | ||
| } | ||
|
|
||
| if node.LastSeen != nil { | ||
| h.db.SetLastSeen(node.ID, *node.LastSeen) | ||
| } | ||
|
Comment on lines
+412
to
+414
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
| ctx := types.NotifyCtx(context.Background(), "poll-nodeupdate-onlinestatus", node.Hostname) | ||
| h.nodeNotifier.NotifyWithIgnore(ctx, types.UpdatePeerPatch(change), node.ID) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,11 +98,7 @@ type Node struct { | |
|
|
||
| // LastSeen is when the node was last in contact with | ||
| // headscale. It is best effort and not persisted. | ||
| LastSeen *time.Time `gorm:"-"` | ||
|
|
||
| // DEPRECATED: Use the ApprovedRoutes field instead. | ||
| // TODO(kradalby): remove when ApprovedRoutes is used all over the code. | ||
| // Routes []Route `gorm:"constraint:OnDelete:CASCADE;"` | ||
| LastSeen *time.Time `gorm:"column:last_seen"` | ||
|
Comment on lines
98
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
| // ApprovedRoutes is a list of routes that the node is allowed to announce | ||
| // as a subnet router. They are not necessarily the routes that the node | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
|
|
||
| "slices" | ||
|
|
||
| v1 "github.com/juanfont/headscale/gen/go/headscale/v1" | ||
| "github.com/juanfont/headscale/integration/hsic" | ||
| "github.com/juanfont/headscale/integration/tsic" | ||
| "github.com/samber/lo" | ||
|
|
@@ -44,6 +45,9 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { | |
| allClients, err := scenario.ListTailscaleClients() | ||
| assertNoErrListClients(t, err) | ||
|
|
||
| allIps, err := scenario.ListTailscaleClientsIPs() | ||
| assertNoErrListClientIPs(t, err) | ||
|
|
||
| err = scenario.WaitForTailscaleSync() | ||
| assertNoErrSync(t, err) | ||
|
|
||
|
|
@@ -66,6 +70,10 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { | |
| nodeCountBeforeLogout := len(listNodes) | ||
| t.Logf("node count before logout: %d", nodeCountBeforeLogout) | ||
|
|
||
| for _, node := range listNodes { | ||
| assertLastSeenSet(t, node) | ||
| } | ||
|
|
||
| for _, client := range allClients { | ||
| err := client.Logout() | ||
| if err != nil { | ||
|
|
@@ -78,6 +86,13 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { | |
|
|
||
| t.Logf("all clients logged out") | ||
|
|
||
| listNodes, err = headscale.ListNodes() | ||
| require.Equal(t, nodeCountBeforeLogout, len(listNodes)) | ||
|
|
||
| for _, node := range listNodes { | ||
| assertLastSeenSet(t, node) | ||
| } | ||
|
|
||
| // if the server is not running with HTTPS, we have to wait a bit before | ||
| // reconnection as the newest Tailscale client has a measure that will only | ||
| // reconnect over HTTPS if they saw a noise connection previously. | ||
|
Comment on lines
96
to
98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
@@ -105,8 +120,9 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { | |
| listNodes, err = headscale.ListNodes() | ||
| require.Equal(t, nodeCountBeforeLogout, len(listNodes)) | ||
|
|
||
| allIps, err := scenario.ListTailscaleClientsIPs() | ||
| assertNoErrListClientIPs(t, err) | ||
| for _, node := range listNodes { | ||
| assertLastSeenSet(t, node) | ||
| } | ||
|
|
||
| allAddrs := lo.Map(allIps, func(x netip.Addr, index int) string { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
| return x.String() | ||
|
|
@@ -137,8 +153,20 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| listNodes, err = headscale.ListNodes() | ||
| require.Equal(t, nodeCountBeforeLogout, len(listNodes)) | ||
| for _, node := range listNodes { | ||
| assertLastSeenSet(t, node) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| func assertLastSeenSet(t *testing.T, node *v1.Node) { | ||
| assert.NotNil(t, node) | ||
| assert.NotNil(t, node.LastSeen) | ||
| } | ||
|
|
||
| // This test will first log in two sets of nodes to two sets of users, then | ||
|
|
||
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.
In
hscontrol/db/node.go, you have duplicated documentation comments for theSetLastSeenfunction. Consider removing the redundancy to maintain cleaner code.