web/multinode: fix used space graph showing 0

Resolves https://github.com/storj/storj/issues/5566

Change-Id: Ib9c81fa2c92ed71ccf07e7a0c9b6f61c46294f09
This commit is contained in:
Clement Sam 2023-05-03 16:56:43 +00:00 committed by Storj Robot
parent a229feac1e
commit dab4288899
2 changed files with 34 additions and 20 deletions

View File

@ -85,6 +85,7 @@ func (service *Service) TotalUsage(ctx context.Context, from, to time.Time) (_ U
} }
var totalSummary float64 var totalSummary float64
var totalSummaryBytes float64
cache := make(UsageStampDailyCache) cache := make(UsageStampDailyCache)
for _, node := range nodesList { for _, node := range nodesList {
@ -98,6 +99,7 @@ func (service *Service) TotalUsage(ctx context.Context, from, to time.Time) (_ U
} }
totalSummary += usage.Summary totalSummary += usage.Summary
totalSummaryBytes += usage.SummaryBytes
for _, stamp := range usage.Stamps { for _, stamp := range usage.Stamps {
cache.Add(stamp) cache.Add(stamp)
} }
@ -106,6 +108,7 @@ func (service *Service) TotalUsage(ctx context.Context, from, to time.Time) (_ U
return Usage{ return Usage{
Stamps: cache.Sorted(), Stamps: cache.Sorted(),
Summary: totalSummary, Summary: totalSummary,
SummaryBytes: totalSummaryBytes,
}, nil }, nil
} }
@ -119,6 +122,7 @@ func (service *Service) TotalUsageSatellite(ctx context.Context, satelliteID sto
} }
var totalSummary float64 var totalSummary float64
var totalSummaryBytes float64
cache := make(UsageStampDailyCache) cache := make(UsageStampDailyCache)
for _, node := range nodesList { for _, node := range nodesList {
@ -132,6 +136,7 @@ func (service *Service) TotalUsageSatellite(ctx context.Context, satelliteID sto
} }
totalSummary += usage.Summary totalSummary += usage.Summary
totalSummaryBytes += usage.SummaryBytes
for _, stamp := range usage.Stamps { for _, stamp := range usage.Stamps {
cache.Add(stamp) cache.Add(stamp)
} }
@ -140,6 +145,7 @@ func (service *Service) TotalUsageSatellite(ctx context.Context, satelliteID sto
return Usage{ return Usage{
Stamps: cache.Sorted(), Stamps: cache.Sorted(),
Summary: totalSummary, Summary: totalSummary,
SummaryBytes: totalSummaryBytes,
}, nil }, nil
} }
@ -247,6 +253,7 @@ func (service *Service) dialUsage(ctx context.Context, node nodes.Node, from, to
for _, usage := range resp.GetStorageUsage() { for _, usage := range resp.GetStorageUsage() {
stamps = append(stamps, UsageStamp{ stamps = append(stamps, UsageStamp{
AtRestTotal: usage.GetAtRestTotal(), AtRestTotal: usage.GetAtRestTotal(),
AtRestTotalBytes: usage.GetAtRestTotalBytes(),
IntervalStart: usage.GetIntervalStart(), IntervalStart: usage.GetIntervalStart(),
}) })
} }
@ -254,6 +261,7 @@ func (service *Service) dialUsage(ctx context.Context, node nodes.Node, from, to
return Usage{ return Usage{
Stamps: stamps, Stamps: stamps,
Summary: resp.GetSummary(), Summary: resp.GetSummary(),
SummaryBytes: resp.GetAverageUsageBytes(),
}, nil }, nil
} }
@ -291,6 +299,7 @@ func (service *Service) dialUsageSatellite(ctx context.Context, node nodes.Node,
for _, usage := range resp.GetStorageUsage() { for _, usage := range resp.GetStorageUsage() {
stamps = append(stamps, UsageStamp{ stamps = append(stamps, UsageStamp{
AtRestTotal: usage.GetAtRestTotal(), AtRestTotal: usage.GetAtRestTotal(),
AtRestTotalBytes: usage.GetAtRestTotalBytes(),
IntervalStart: usage.GetIntervalStart(), IntervalStart: usage.GetIntervalStart(),
}) })
} }
@ -298,5 +307,6 @@ func (service *Service) dialUsageSatellite(ctx context.Context, node nodes.Node,
return Usage{ return Usage{
Stamps: stamps, Stamps: stamps,
Summary: resp.GetSummary(), Summary: resp.GetSummary(),
SummaryBytes: resp.GetAverageUsageBytes(),
}, nil }, nil
} }

View File

@ -12,11 +12,13 @@ import (
type Usage struct { type Usage struct {
Stamps []UsageStamp `json:"stamps"` Stamps []UsageStamp `json:"stamps"`
Summary float64 `json:"summary"` Summary float64 `json:"summary"`
SummaryBytes float64 `json:"summaryBytes"`
} }
// UsageStamp holds data at rest total for an interval beginning at interval start. // UsageStamp holds data at rest total for an interval beginning at interval start.
type UsageStamp struct { type UsageStamp struct {
AtRestTotal float64 `json:"atRestTotal"` AtRestTotal float64 `json:"atRestTotal"`
AtRestTotalBytes float64 `json:"atRestTotalBytes"`
IntervalStart time.Time `json:"intervalStart"` IntervalStart time.Time `json:"intervalStart"`
} }
@ -34,11 +36,13 @@ func (cache *UsageStampDailyCache) Add(stamp UsageStamp) {
if ok { if ok {
cached[intervalStart] = UsageStamp{ cached[intervalStart] = UsageStamp{
AtRestTotal: cacheStamp.AtRestTotal + stamp.AtRestTotal, AtRestTotal: cacheStamp.AtRestTotal + stamp.AtRestTotal,
AtRestTotalBytes: cacheStamp.AtRestTotalBytes + stamp.AtRestTotalBytes,
IntervalStart: intervalStart, IntervalStart: intervalStart,
} }
} else { } else {
cached[intervalStart] = UsageStamp{ cached[intervalStart] = UsageStamp{
AtRestTotal: stamp.AtRestTotal, AtRestTotal: stamp.AtRestTotal,
AtRestTotalBytes: stamp.AtRestTotalBytes,
IntervalStart: intervalStart, IntervalStart: intervalStart,
} }
} }