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

View File

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