Skip to content

Commit

Permalink
Fix uint64 to float64 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ioppermann committed Nov 5, 2024
1 parent 0d57a85 commit 74607db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
6 changes: 2 additions & 4 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7413,8 +7413,7 @@ const docTemplate = `{
"type": "object",
"properties": {
"avg": {
"type": "integer",
"format": "uint64"
"type": "number"
},
"cur": {
"type": "integer",
Expand Down Expand Up @@ -7451,8 +7450,7 @@ const docTemplate = `{
"type": "object",
"properties": {
"avg": {
"type": "integer",
"format": "uint64"
"type": "number"
},
"cur": {
"type": "integer",
Expand Down
6 changes: 2 additions & 4 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7406,8 +7406,7 @@
"type": "object",
"properties": {
"avg": {
"type": "integer",
"format": "uint64"
"type": "number"
},
"cur": {
"type": "integer",
Expand Down Expand Up @@ -7444,8 +7443,7 @@
"type": "object",
"properties": {
"avg": {
"type": "integer",
"format": "uint64"
"type": "number"
},
"cur": {
"type": "integer",
Expand Down
6 changes: 2 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,7 @@ definitions:
api.ProcessUsageGPUMemory:
properties:
avg:
format: uint64
type: integer
type: number
cur:
format: uint64
type: integer
Expand All @@ -1612,8 +1611,7 @@ definitions:
api.ProcessUsageMemory:
properties:
avg:
format: uint64
type: integer
type: number
cur:
format: uint64
type: integer
Expand Down
30 changes: 18 additions & 12 deletions http/api/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,52 +431,58 @@ func (p *ProcessUsageCPU) Marshal() app.ProcessUsageCPU {
}

type ProcessUsageMemory struct {
Current uint64 `json:"cur" format:"uint64"`
Average uint64 `json:"avg" format:"uint64"`
Max uint64 `json:"max" format:"uint64"`
Limit uint64 `json:"limit" format:"uint64"`
Current uint64 `json:"cur" format:"uint64"`
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
Max uint64 `json:"max" format:"uint64"`
Limit uint64 `json:"limit" format:"uint64"`
}

func (p *ProcessUsageMemory) Unmarshal(pp *app.ProcessUsageMemory) {
p.Current = pp.Current
p.Average = pp.Average
p.Average = json.ToNumber(float64(pp.Average))
p.Max = pp.Max
p.Limit = pp.Limit
}

func (p *ProcessUsageMemory) Marshal() app.ProcessUsageMemory {
pp := app.ProcessUsageMemory{
Current: p.Current,
Average: p.Average,
Max: p.Max,
Limit: p.Limit,
}

if x, err := p.Average.Float64(); err == nil {
pp.Average = uint64(x)
}

return pp
}

type ProcessUsageGPUMemory struct {
Current uint64 `json:"cur" format:"uint64"`
Average uint64 `json:"avg" format:"uint64"`
Max uint64 `json:"max" format:"uint64"`
Limit uint64 `json:"limit" format:"uint64"`
Current uint64 `json:"cur" format:"uint64"`
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
Max uint64 `json:"max" format:"uint64"`
Limit uint64 `json:"limit" format:"uint64"`
}

func (p *ProcessUsageGPUMemory) Unmarshal(pp *app.ProcessUsageGPUMemory) {
p.Current = pp.Current
p.Average = pp.Average
p.Average = json.ToNumber(float64(pp.Average))
p.Max = pp.Max
p.Limit = pp.Limit
}

func (p *ProcessUsageGPUMemory) Marshal() app.ProcessUsageGPUMemory {
pp := app.ProcessUsageGPUMemory{
Current: p.Current,
Average: p.Average,
Max: p.Max,
Limit: p.Limit,
}

if x, err := p.Average.Float64(); err == nil {
pp.Average = uint64(x)
}

return pp
}

Expand Down

0 comments on commit 74607db

Please sign in to comment.