Skip to content

Commit 2451f1d

Browse files
committed
Merge branch 'development' of https://github.com/threefoldtech/tfgrid-sdk-go into development_gpus
2 parents 8e38028 + 8dd017d commit 2451f1d

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

grid-proxy/charts/gridproxy/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ version: 1.0.0
2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
23-
appVersion: 0.8.3
23+
appVersion: 0.9.0

grid-proxy/internal/explorer/converters.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ func decideNodeStatus(power types.NodePower, updatedAt int64) string {
2626
}
2727
}
2828

29+
// getNumGPUs should be deleted after removing hasGPU
30+
func getNumGPUs(hasGPU bool) int {
31+
if hasGPU {
32+
return 1
33+
}
34+
return 0
35+
}
36+
2937
func nodeFromDBNode(info db.Node) types.Node {
3038
node := types.Node{
3139
ID: info.ID,
@@ -70,7 +78,7 @@ func nodeFromDBNode(info db.Node) types.Node {
7078
RentedByTwinID: uint(info.RentedByTwinID),
7179
SerialNumber: info.SerialNumber,
7280
Power: types.NodePower(info.Power),
73-
HasGPU: info.HasGPU,
81+
NumGPU: getNumGPUs(info.HasGPU),
7482
ExtraFee: info.ExtraFee,
7583
}
7684
node.Status = decideNodeStatus(node.Power, node.UpdatedAt)
@@ -141,7 +149,7 @@ func nodeWithNestedCapacityFromDBNode(info db.Node) types.NodeWithNestedCapacity
141149
RentedByTwinID: uint(info.RentedByTwinID),
142150
SerialNumber: info.SerialNumber,
143151
Power: types.NodePower(info.Power),
144-
HasGPU: info.HasGPU,
152+
NumGPU: getNumGPUs(info.HasGPU),
145153
ExtraFee: info.ExtraFee,
146154
}
147155
node.Status = decideNodeStatus(node.Power, node.UpdatedAt)

grid-proxy/internal/explorer/db/postgres.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ func (d *PostgresDatabase) GetCounters(filter types.StatsFilter) (types.Counters
230230
Select("country, count(node_id) as nodes").Where(condition).Group("country").Scan(&distribution); res.Error != nil {
231231
return counters, errors.Wrap(res.Error, "couldn't get nodes distribution")
232232
}
233+
if res := d.gormDB.Table("node").Where(condition).Where("node.has_gpu = true").Count(&counters.GPUs); res.Error != nil {
234+
return counters, errors.Wrap(res.Error, "couldn't get node with GPU count")
235+
}
233236
nodesDistribution := map[string]int64{}
234237
for _, d := range distribution {
235238
nodesDistribution[d.Country] = d.Nodes

grid-proxy/internal/explorer/server.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,6 @@ func (a *App) getNodeGpus(r *http.Request) (interface{}, mw.Response) {
440440
return nil, errorReply(err)
441441
}
442442

443-
if !node.HasGPU {
444-
return nil, mw.Error(fmt.Errorf("node %d has no GPU support", node.NodeID))
445-
}
446-
447443
if node.Status == "down" || node.Status == "standby" {
448444
return nil, mw.Error(fmt.Errorf("cannot fetch GPU information from node %d with status: %s", node.NodeID, node.Status))
449445
}

grid-proxy/pkg/types/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Counters struct {
2929
Twins int64 `json:"twins"`
3030
Contracts int64 `json:"contracts"`
3131
NodesDistribution map[string]int64 `json:"nodesDistribution" gorm:"-:all"`
32+
GPUs int64 `json:"gpus"`
3233
}
3334

3435
// PublicConfig node public config
@@ -187,7 +188,7 @@ type Node struct {
187188
RentedByTwinID uint `json:"rentedByTwinId"`
188189
SerialNumber string `json:"serialNumber"`
189190
Power NodePower `json:"power"`
190-
HasGPU bool `json:"hasGpu"`
191+
NumGPU int `json:"num_gpu"`
191192
ExtraFee uint64 `json:"extraFee"`
192193
}
193194

@@ -220,7 +221,7 @@ type NodeWithNestedCapacity struct {
220221
RentedByTwinID uint `json:"rentedByTwinId"`
221222
SerialNumber string `json:"serialNumber"`
222223
Power NodePower `json:"power"`
223-
HasGPU bool `json:"hasGpu"`
224+
NumGPU int `json:"num_gpu"`
224225
ExtraFee uint64 `json:"extraFee"`
225226
}
226227

grid-proxy/tests/queries/local_client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,20 @@ func (g *GridProxyClientimpl) Node(nodeID uint32) (res proxytypes.NodeWithNested
343343
State: node.power.State,
344344
Target: node.power.Target,
345345
},
346-
HasGPU: node.HasGPU,
346+
NumGPU: getNumGPUs(node.HasGPU),
347347
ExtraFee: node.ExtraFee,
348348
}
349349
return
350350
}
351351

352+
// getNumGPUs should be deleted after removing hasGPU
353+
func getNumGPUs(hasGPU bool) int {
354+
if hasGPU {
355+
return 1
356+
}
357+
return 0
358+
}
359+
352360
func (g *GridProxyClientimpl) NodeStatus(nodeID uint32) (res proxytypes.NodeStatus, err error) {
353361
node := g.data.nodes[uint64(nodeID)]
354362
res.Status = decideNodeStatus(node.power, node.updated_at)
@@ -363,6 +371,7 @@ func (g *GridProxyClientimpl) Counters(filter proxytypes.StatsFilter) (res proxy
363371
res.Contracts += int64(len(g.data.nodeContracts))
364372
res.Contracts += int64(len(g.data.nameContracts))
365373
distribution := map[string]int64{}
374+
var gpus int64
366375
for _, node := range g.data.nodes {
367376
if filter.Status == nil || (*filter.Status == STATUS_UP && isUp(node.updated_at)) {
368377
res.Nodes++
@@ -377,10 +386,14 @@ func (g *GridProxyClientimpl) Counters(filter proxytypes.StatsFilter) (res proxy
377386
res.Gateways++
378387
}
379388
}
389+
if node.HasGPU {
390+
gpus++
391+
}
380392
}
381393
}
382394
res.Countries = int64(len(distribution))
383395
res.NodesDistribution = distribution
396+
res.GPUs = gpus
384397

385398
return
386399
}

grid-proxy/tests/queries/node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestNode(t *testing.T) {
157157
assert.NoError(t, err)
158158

159159
for _, node := range nodes {
160-
assert.Equal(t, node.HasGPU, hasGPU, "has_gpu filter did not work")
160+
assert.Equal(t, node.NumGPU, 1, "has_gpu filter did not work")
161161
}
162162
})
163163
}

0 commit comments

Comments
 (0)