Skip to content

add online filter #51

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions node-registrar/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type nodeCfg struct {
twinID uint64
status string
healthy bool
online *bool
lastSeen *int64
Location Location
Resources Resources
Interfaces []Interface
Expand Down Expand Up @@ -100,6 +102,18 @@ func ListNodesWithHealthy() ListNodeOpts {
}
}

func ListNodesWithOnline(online bool) ListNodeOpts {
return func(n *nodeCfg) {
n.online = &online
}
}

func ListNodesWithLastSeen(minutes int64) ListNodeOpts {
return func(n *nodeCfg) {
n.lastSeen = &minutes
}
}

func ListNodesWithTwinID(id uint64) ListNodeOpts {
return func(n *nodeCfg) {
n.twinID = id
Expand Down Expand Up @@ -495,13 +509,15 @@ func (c *RegistrarClient) parseUpdateNodeOpts(node Node, opts []UpdateNodeOpts)

func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
cfg := nodeCfg{
nodeID: 0,
twinID: 0,
farmID: 0,
status: "",
healthy: false,
size: 50,
page: 1,
nodeID: 0,
twinID: 0,
farmID: 0,
status: "",
healthy: false,
online: nil,
lastSeen: nil,
size: 50,
page: 1,
}

for _, opt := range opts {
Expand Down Expand Up @@ -530,6 +546,14 @@ func parseListNodeOpts(opts []ListNodeOpts) map[string]any {
data["healthy"] = cfg.healthy
}

if cfg.online != nil {
data["online"] = *cfg.online
}

if cfg.lastSeen != nil {
data["last_seen"] = *cfg.lastSeen
}

data["size"] = cfg.size
data["page"] = cfg.page

Expand Down
1 change: 1 addition & 0 deletions node-registrar/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Node struct {
Virtualized bool `json:"virtualized"`
SerialNumber string `json:"serial_number"`
UptimeReports []UptimeReport `json:"uptime"`
LastSeen *time.Time `json:"last_seen"`
Approved bool
}

Expand Down
47 changes: 36 additions & 11 deletions node-registrar/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ const docTemplate = `{
"name": "healthy",
"in": "query"
},
{
"type": "boolean",
"description": "Filter by online status (true = online, false = offline)",
"name": "online",
"in": "query"
},
{
"type": "integer",
"description": "Filter nodes last seen within this many minutes",
"name": "last_seen",
"in": "query"
},
{
"type": "integer",
"default": 1,
Expand All @@ -487,11 +499,12 @@ const docTemplate = `{
],
"responses": {
"200": {
"description": "List of nodes",
"description": "List of nodes with online status",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/db.Node"
"type": "object",
"additionalProperties": true
}
}
},
Expand Down Expand Up @@ -592,9 +605,10 @@ const docTemplate = `{
],
"responses": {
"200": {
"description": "Node details",
"description": "Node details with online status and last_seen information",
"schema": {
"$ref": "#/definitions/db.Node"
"type": "object",
"additionalProperties": true
}
},
"400": {
Expand Down Expand Up @@ -894,6 +908,11 @@ const docTemplate = `{
},
"db.Farm": {
"type": "object",
"required": [
"farm_name",
"stellar_address",
"twin_id"
],
"properties": {
"created_at": {
"type": "string"
Expand Down Expand Up @@ -930,7 +949,10 @@ const docTemplate = `{
"type": "object",
"properties": {
"ips": {
"type": "string"
"type": "array",
"items": {
"type": "string"
}
},
"mac": {
"type": "string"
Expand Down Expand Up @@ -976,6 +998,10 @@ const docTemplate = `{
"$ref": "#/definitions/db.Interface"
}
},
"last_seen": {
"description": "Last time the node sent an uptime report",
"type": "string"
},
"location": {
"$ref": "#/definitions/db.Location"
},
Expand Down Expand Up @@ -1139,8 +1165,7 @@ const docTemplate = `{
"maxLength": 40
},
"stellar_address": {
"type": "string",
"maxLength": 56
"type": "string"
}
}
},
Expand Down Expand Up @@ -1200,12 +1225,12 @@ const docTemplate = `{

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Version: "1.0",
Host: "",
BasePath: "",
BasePath: "/v1",
Schemes: []string{},
Title: "",
Description: "",
Title: "Node Registrar API",
Description: "API for managing TFGrid node registration",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
Expand Down
45 changes: 37 additions & 8 deletions node-registrar/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"swagger": "2.0",
"info": {
"contact": {}
"description": "API for managing TFGrid node registration",
"title": "Node Registrar API",
"contact": {},
"version": "1.0"
},
"basePath": "/v1",
"paths": {
"/accounts": {
"get": {
Expand Down Expand Up @@ -459,6 +463,18 @@
"name": "healthy",
"in": "query"
},
{
"type": "boolean",
"description": "Filter by online status (true = online, false = offline)",
"name": "online",
"in": "query"
},
{
"type": "integer",
"description": "Filter nodes last seen within this many minutes",
"name": "last_seen",
"in": "query"
},
{
"type": "integer",
"default": 1,
Expand All @@ -476,11 +492,12 @@
],
"responses": {
"200": {
"description": "List of nodes",
"description": "List of nodes with online status",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/db.Node"
"type": "object",
"additionalProperties": true
}
}
},
Expand Down Expand Up @@ -581,9 +598,10 @@
],
"responses": {
"200": {
"description": "Node details",
"description": "Node details with online status and last_seen information",
"schema": {
"$ref": "#/definitions/db.Node"
"type": "object",
"additionalProperties": true
}
},
"400": {
Expand Down Expand Up @@ -883,6 +901,11 @@
},
"db.Farm": {
"type": "object",
"required": [
"farm_name",
"stellar_address",
"twin_id"
],
"properties": {
"created_at": {
"type": "string"
Expand Down Expand Up @@ -919,7 +942,10 @@
"type": "object",
"properties": {
"ips": {
"type": "string"
"type": "array",
"items": {
"type": "string"
}
},
"mac": {
"type": "string"
Expand Down Expand Up @@ -965,6 +991,10 @@
"$ref": "#/definitions/db.Interface"
}
},
"last_seen": {
"description": "Last time the node sent an uptime report",
"type": "string"
},
"location": {
"$ref": "#/definitions/db.Location"
},
Expand Down Expand Up @@ -1128,8 +1158,7 @@
"maxLength": 40
},
"stellar_address": {
"type": "string",
"maxLength": 56
"type": "string"
}
}
},
Expand Down
34 changes: 28 additions & 6 deletions node-registrar/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
basePath: /v1
definitions:
db.Account:
properties:
Expand Down Expand Up @@ -50,11 +51,17 @@ definitions:
type: integer
updated_at:
type: string
required:
- farm_name
- stellar_address
- twin_id
type: object
db.Interface:
properties:
ips:
type: string
items:
type: string
type: array
mac:
type: string
name:
Expand Down Expand Up @@ -85,6 +92,9 @@ definitions:
items:
$ref: '#/definitions/db.Interface'
type: array
last_seen:
description: Last time the node sent an uptime report
type: string
location:
$ref: '#/definitions/db.Location'
node_id:
Expand Down Expand Up @@ -198,7 +208,6 @@ definitions:
maxLength: 40
type: string
stellar_address:
maxLength: 56
type: string
type: object
server.UpdateNodeRequest:
Expand Down Expand Up @@ -238,6 +247,9 @@ definitions:
type: object
info:
contact: {}
description: API for managing TFGrid node registration
title: Node Registrar API
version: "1.0"
paths:
/accounts:
get:
Expand Down Expand Up @@ -544,6 +556,14 @@ paths:
in: query
name: healthy
type: boolean
- description: Filter by online status (true = online, false = offline)
in: query
name: online
type: boolean
- description: Filter nodes last seen within this many minutes
in: query
name: last_seen
type: integer
- default: 1
description: Page number
in: query
Expand All @@ -558,10 +578,11 @@ paths:
- application/json
responses:
"200":
description: List of nodes
description: List of nodes with online status
schema:
items:
$ref: '#/definitions/db.Node'
additionalProperties: true
type: object
type: array
"400":
description: Bad request
Expand Down Expand Up @@ -629,9 +650,10 @@ paths:
- application/json
responses:
"200":
description: Node details
description: Node details with online status and last_seen information
schema:
$ref: '#/definitions/db.Node'
additionalProperties: true
type: object
"400":
description: Invalid node ID
schema:
Expand Down
Loading
Loading