Skip to content

Commit 8e1fd2c

Browse files
authored
Merge pull request #46 from threefoldtech/development-node-last-seen
Introduce node last seen, online status, and filters
2 parents 29796a2 + c8e8840 commit 8e1fd2c

File tree

11 files changed

+543
-207
lines changed

11 files changed

+543
-207
lines changed

node-registrar/client/node.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type nodeCfg struct {
5959
twinID uint64
6060
status string
6161
healthy bool
62+
online *bool
63+
lastSeen *int64
6264
Location Location
6365
Resources Resources
6466
Interfaces []Interface
@@ -100,6 +102,18 @@ func ListNodesWithHealthy() ListNodeOpts {
100102
}
101103
}
102104

105+
func ListNodesWithOnline(online bool) ListNodeOpts {
106+
return func(n *nodeCfg) {
107+
n.online = &online
108+
}
109+
}
110+
111+
func ListNodesWithLastSeen(minutes int64) ListNodeOpts {
112+
return func(n *nodeCfg) {
113+
n.lastSeen = &minutes
114+
}
115+
}
116+
103117
func ListNodesWithTwinID(id uint64) ListNodeOpts {
104118
return func(n *nodeCfg) {
105119
n.twinID = id
@@ -240,7 +254,9 @@ func (c *RegistrarClient) registerNode(
240254
}{}
241255

242256
err = json.NewDecoder(resp.Body).Decode(&result)
243-
257+
if err != nil {
258+
return 0, errors.Wrap(err, "failed to decode response body")
259+
}
244260
c.nodeID = result.NodeID
245261
return result.NodeID, err
246262
}
@@ -495,13 +511,15 @@ func (c *RegistrarClient) parseUpdateNodeOpts(node Node, opts []UpdateNodeOpts)
495511

496512
func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
497513
cfg := nodeCfg{
498-
nodeID: 0,
499-
twinID: 0,
500-
farmID: 0,
501-
status: "",
502-
healthy: false,
503-
size: 50,
504-
page: 1,
514+
nodeID: 0,
515+
twinID: 0,
516+
farmID: 0,
517+
status: "",
518+
healthy: false,
519+
online: nil,
520+
lastSeen: nil,
521+
size: 50,
522+
page: 1,
505523
}
506524

507525
for _, opt := range opts {
@@ -530,6 +548,14 @@ func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
530548
data["healthy"] = cfg.healthy
531549
}
532550

551+
if cfg.online != nil {
552+
data["online"] = *cfg.online
553+
}
554+
555+
if cfg.lastSeen != nil {
556+
data["last_seen"] = *cfg.lastSeen
557+
}
558+
533559
data["size"] = cfg.size
534560
data["page"] = cfg.page
535561

node-registrar/client/node_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ func TestUpdateNode(t *testing.T) {
9999
request = updateNodeSendUptimeReport
100100

101101
report := UptimeReport{
102-
Uptime: 40 * time.Minute,
103-
Timestamp: time.Now(),
102+
Uptime: 40 * 60,
103+
Timestamp: time.Now().Unix(),
104104
}
105105
err = c.ReportUptime(report)
106106
require.NoError(err)

node-registrar/client/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ type Node struct {
3030
Virtualized bool `json:"virtualized"`
3131
SerialNumber string `json:"serial_number"`
3232
UptimeReports []UptimeReport `json:"uptime"`
33+
LastSeen *time.Time `json:"last_seen"`
34+
Online bool `json:"online"`
3335
Approved bool
3436
}
3537

3638
type UptimeReport struct {
37-
Uptime time.Duration `json:"uptime"`
38-
Timestamp time.Time `json:"timestamp"`
39+
Uptime uint64 `json:"uptime"` // in seconds
40+
Timestamp int64 `json:"timestamp"` // in seconds since epoch
3941
}
4042

4143
type ZosVersion struct {

0 commit comments

Comments
 (0)