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

Fix(ostor): int(32) overflow #29

Merged
merged 1 commit into from
Oct 8, 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
2 changes: 1 addition & 1 deletion cmd/tenant-usage/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

Check warning on line 1 in cmd/tenant-usage/main.go

View workflow job for this annotation

GitHub Actions / revive

should have a package comment

import (
"fmt"
Expand Down Expand Up @@ -73,7 +73,7 @@
app.Name,
app.Type,
usages.Name,
utils.PrettyByteSize(int(math.Round(usages.AbsoluteValue))),
utils.PrettyByteSize(int64(math.Round(usages.AbsoluteValue))),
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
)

type stat struct {
Put int
Get int
List int
Other int
Downloaded int
Uploaded int
Put int64
Get int64
List int64
Other int64
Downloaded int64
Uploaded int64
}

// show stats is really expensive, it will (attempt to) crawl the entire `?ostor-usage` endpoint
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Users(cCtx *cli.Context) error {

for _, u := range users.Users {
if cCtx.Bool("usage") {
tbl.AddRow(u.Email, u.ID, u.State, utils.PrettyByteSize(int(u.Space.Current)))
tbl.AddRow(u.Email, u.ID, u.State, utils.PrettyByteSize(u.Space.Current))
} else {
tbl.AddRow(u.Email, u.ID, u.State)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package utils

Check warning on line 1 in internal/utils/utils.go

View workflow job for this annotation

GitHub Actions / revive

should have a package comment

import (
"fmt"
)

// credit:

Check warning on line 7 in internal/utils/utils.go

View workflow job for this annotation

GitHub Actions / revive

comment on exported function PrettyByteSize should be of the form "PrettyByteSize ..."
// https://gist.github.com/anikitenko/b41206a49727b83a530142c76b1cb82d?permalink_comment_id=4467913#gistcomment-4467913
func PrettyByteSize(bytes int) string {
func PrettyByteSize(bytes int64) string {
const (
KB = 1024
MB = KB * 1024
GB = MB * 1024
TB = GB * 1024
KB int64 = 1024
MB = KB * 1024
GB = MB * 1024
TB = GB * 1024
)

switch {
Expand Down
20 changes: 10 additions & 10 deletions pkg/ostor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ type ItemKey struct {
}

type ItemCountersOps struct {
Put int `json:"put"`
Get int `json:"get"`
List int `json:"list"`
Other int `json:"other"`
Put int64 `json:"put"`
Get int64 `json:"get"`
List int64 `json:"list"`
Other int64 `json:"other"`
}

type ItemCountersNet struct {
Uploaded int `json:"uploaded"`
Downloaded int `json:"downloaded"`
Uploaded int64 `json:"uploaded"`
Downloaded int64 `json:"downloaded"`
}

// { "Users":[
Expand Down Expand Up @@ -156,10 +156,10 @@ type OstorUserLimits struct {
// } },

type BucketSize struct {
Current int `json:"current"`
HMax int `json:"hmax"`
HIntegral int `json:"h_integral"`
LastTS int `json:"last_ts"`
Current int64 `json:"current"`
HMax int64 `json:"hmax"`
HIntegral int64 `json:"h_integral"`
LastTS int64 `json:"last_ts"`
}

type Bucket struct {
Expand Down
Loading