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

provide total/free/used_ips sorting params on farms #1199

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion grid-proxy/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion grid-proxy/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@
"name",
"farm_id",
"twin_id",
"public_ips",
"free_ips",
"total_ips",
"used_ips",
"dedicated"
],
"type": "string",
Expand Down Expand Up @@ -1610,6 +1612,9 @@
"items": {
"$ref": "#/definitions/types.Processor"
}
},
"updatedAt": {
"type": "integer"
}
}
},
Expand Down Expand Up @@ -1706,6 +1711,12 @@
"farmingPolicyId": {
"type": "integer"
},
"gpus": {
"type": "array",
"items": {
"$ref": "#/definitions/types.NodeGPU"
}
},
"gridVersion": {
"type": "integer"
},
Expand Down Expand Up @@ -1895,6 +1906,12 @@
"farmingPolicyId": {
"type": "integer"
},
"gpus": {
"type": "array",
"items": {
"$ref": "#/definitions/types.NodeGPU"
}
},
"gridVersion": {
"type": "integer"
},
Expand Down Expand Up @@ -2019,6 +2036,9 @@
"node_twin_id": {
"type": "integer"
},
"updatedAt": {
"type": "integer"
},
"upload": {
"description": "in bit/sec",
"type": "number"
Expand Down
16 changes: 15 additions & 1 deletion grid-proxy/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ definitions:
items:
$ref: '#/definitions/types.Processor'
type: array
updatedAt:
type: integer
type: object
types.Farm:
properties:
Expand Down Expand Up @@ -153,6 +155,10 @@ definitions:
type: string
farmingPolicyId:
type: integer
gpus:
items:
$ref: '#/definitions/types.NodeGPU'
type: array
gridVersion:
type: integer
healthy:
Expand Down Expand Up @@ -277,6 +283,10 @@ definitions:
type: string
farmingPolicyId:
type: integer
gpus:
items:
$ref: '#/definitions/types.NodeGPU'
type: array
gridVersion:
type: integer
healthy:
Expand Down Expand Up @@ -359,6 +369,8 @@ definitions:
type: number
node_twin_id:
type: integer
updatedAt:
type: integer
upload:
description: in bit/sec
type: number
Expand Down Expand Up @@ -629,7 +641,9 @@ paths:
- name
- farm_id
- twin_id
- public_ips
- free_ips
- total_ips
- used_ips
- dedicated
in: query
name: sort_by
Expand Down
12 changes: 11 additions & 1 deletion grid-proxy/internal/explorer/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,17 @@ func (d *PostgresDatabase) GetFarms(ctx context.Context, filter types.FarmFilter
if strings.EqualFold(string(limit.SortOrder), string(types.SortOrderDesc)) {
order = types.SortOrderDesc
}
q = q.Order(fmt.Sprintf("%s %s", limit.SortBy, order))

switch limit.SortBy {
case "free_ips":
q = q.Order(fmt.Sprintf("public_ips_cache.free_ips %s", order))
case "total_ips":
q = q.Order(fmt.Sprintf("public_ips_cache.total_ips %s", order))
case "used_ips":
q = q.Order(fmt.Sprintf("public_ips_cache.total_ips-public_ips_cache.free_ips %s", order))
default:
q = q.Order(fmt.Sprintf("%s %s", limit.SortBy, order))
}
} else {
q = q.Order("farm.farm_id")
}
Expand Down
2 changes: 1 addition & 1 deletion grid-proxy/internal/explorer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// @Param size query int false "Max result per page"
// @Param ret_count query bool false "Set farms' count on headers based on filter"
// @Param randomize query bool false "Get random patch of farms"
// @Param sort_by query string false "Sort by specific farm field" Enums(name, farm_id, twin_id, public_ips, dedicated)
// @Param sort_by query string false "Sort by specific farm field" Enums(name, farm_id, twin_id, free_ips, total_ips, used_ips, dedicated)
// @Param sort_order query string false "The sorting order, default is 'asc'" Enums(desc, asc)
// @Param free_ips query int false "Min number of free ips in the farm"
// @Param total_ips query int false "Min number of total ips in the farm"
Expand Down
4 changes: 4 additions & 0 deletions grid-proxy/pkg/types/farms.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type Farm struct {
StellarAddress string `json:"stellarAddress"`
Dedicated bool `json:"dedicated" sort:"dedicated"`
PublicIps []PublicIP `json:"publicIps" sort:"public_ips"`
// TODO: maybe separate the sorting params in a different struct
_ string `sort:"free_ips"`
_ string `sort:"total_ips"`
_ string `sort:"used_ips"`
}

// PublicIP info about public ip in the farm
Expand Down
Loading