Fix storage and object_count calculations on console (#2081)
This commit is contained in:
parent
5062436846
commit
79a0085103
@ -35,7 +35,7 @@ type BucketUsage struct {
|
||||
|
||||
Storage float64
|
||||
Egress float64
|
||||
ObjectCount float64
|
||||
ObjectCount int64
|
||||
|
||||
Since time.Time
|
||||
Before time.Time
|
||||
|
@ -5,6 +5,7 @@ package satellitedb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
@ -257,7 +258,11 @@ func (db *usagerollups) GetBucketTotals(ctx context.Context, projectID uuid.UUID
|
||||
WHERE project_id = ? AND bucket_name = ? AND interval_start >= ? AND interval_start <= ?
|
||||
GROUP BY action`)
|
||||
|
||||
storageQuery := db.db.All_BucketStorageTally_By_ProjectId_And_BucketName_And_IntervalStart_GreaterOrEqual_And_IntervalStart_LessOrEqual_OrderBy_Desc_IntervalStart
|
||||
storageQuery := db.db.Rebind(`SELECT inline, remote, object_count
|
||||
FROM bucket_storage_tallies
|
||||
WHERE project_id = ? AND bucket_name = ? AND interval_start >= ? AND interval_start <= ?
|
||||
ORDER BY interval_start DESC
|
||||
LIMIT 1`)
|
||||
|
||||
var bucketUsages []console.BucketUsage
|
||||
for _, bucket := range buckets {
|
||||
@ -293,28 +298,22 @@ func (db *usagerollups) GetBucketTotals(ctx context.Context, projectID uuid.UUID
|
||||
|
||||
bucketUsage.Egress = memory.Size(totalEgress).GB()
|
||||
|
||||
bucketStorageTallies, err := storageQuery(ctx,
|
||||
dbx.BucketStorageTally_ProjectId([]byte(projectID.String())),
|
||||
dbx.BucketStorageTally_BucketName([]byte(bucket)),
|
||||
dbx.BucketStorageTally_IntervalStart(since),
|
||||
dbx.BucketStorageTally_IntervalStart(before))
|
||||
|
||||
storageRow := db.db.QueryRowContext(ctx, storageQuery, []byte(projectID.String()), []byte(bucket), since, before)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// fill metadata, objects and stored data
|
||||
// hours calculated from previous tallies,
|
||||
// so we skip the most recent one
|
||||
for i := len(bucketStorageTallies) - 1; i > 0; i-- {
|
||||
current := bucketStorageTallies[i]
|
||||
|
||||
hours := bucketStorageTallies[i-1].IntervalStart.Sub(current.IntervalStart).Hours()
|
||||
|
||||
bucketUsage.Storage += memory.Size(current.Remote).GB() * hours
|
||||
bucketUsage.Storage += memory.Size(current.Inline).GB() * hours
|
||||
bucketUsage.ObjectCount += float64(current.ObjectCount) * hours
|
||||
var inline, remote, objectCount int64
|
||||
err = storageRow.Scan(&inline, &remote, &objectCount)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// fill storage and object count
|
||||
bucketUsage.Storage = memory.Size(inline + remote).GB()
|
||||
bucketUsage.ObjectCount = objectCount
|
||||
|
||||
bucketUsages = append(bucketUsages, bucketUsage)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
return (this as any).bucket.egress.toFixed(4);
|
||||
},
|
||||
objectCount: function (): string {
|
||||
return (this as any).bucket.objectCount.toFixed(4);
|
||||
return (this as any).bucket.objectCount.toString();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user