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,14 +99,16 @@ 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)
}
}
return Usage{
Stamps: cache.Sorted(),
Summary: totalSummary,
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,14 +136,16 @@ func (service *Service) TotalUsageSatellite(ctx context.Context, satelliteID sto
}
totalSummary += usage.Summary
totalSummaryBytes += usage.SummaryBytes
for _, stamp := range usage.Stamps {
cache.Add(stamp)
}
}
return Usage{
Stamps: cache.Sorted(),
Summary: totalSummary,
Stamps: cache.Sorted(),
Summary: totalSummary,
SummaryBytes: totalSummaryBytes,
}, nil
}
@ -246,14 +252,16 @@ func (service *Service) dialUsage(ctx context.Context, node nodes.Node, from, to
var stamps []UsageStamp
for _, usage := range resp.GetStorageUsage() {
stamps = append(stamps, UsageStamp{
AtRestTotal: usage.GetAtRestTotal(),
IntervalStart: usage.GetIntervalStart(),
AtRestTotal: usage.GetAtRestTotal(),
AtRestTotalBytes: usage.GetAtRestTotalBytes(),
IntervalStart: usage.GetIntervalStart(),
})
}
return Usage{
Stamps: stamps,
Summary: resp.GetSummary(),
Stamps: stamps,
Summary: resp.GetSummary(),
SummaryBytes: resp.GetAverageUsageBytes(),
}, nil
}
@ -290,13 +298,15 @@ func (service *Service) dialUsageSatellite(ctx context.Context, node nodes.Node,
var stamps []UsageStamp
for _, usage := range resp.GetStorageUsage() {
stamps = append(stamps, UsageStamp{
AtRestTotal: usage.GetAtRestTotal(),
IntervalStart: usage.GetIntervalStart(),
AtRestTotal: usage.GetAtRestTotal(),
AtRestTotalBytes: usage.GetAtRestTotalBytes(),
IntervalStart: usage.GetIntervalStart(),
})
}
return Usage{
Stamps: stamps,
Summary: resp.GetSummary(),
Stamps: stamps,
Summary: resp.GetSummary(),
SummaryBytes: resp.GetAverageUsageBytes(),
}, nil
}

View File

@ -10,14 +10,16 @@ import (
// Usage holds storage usage stamps and summary for a particular period.
type Usage struct {
Stamps []UsageStamp `json:"stamps"`
Summary float64 `json:"summary"`
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"`
IntervalStart time.Time `json:"intervalStart"`
AtRestTotal float64 `json:"atRestTotal"`
AtRestTotalBytes float64 `json:"atRestTotalBytes"`
IntervalStart time.Time `json:"intervalStart"`
}
// UsageStampDailyCache caches storage usage stamps by interval date.
@ -33,13 +35,15 @@ func (cache *UsageStampDailyCache) Add(stamp UsageStamp) {
cacheStamp, ok := cached[intervalStart]
if ok {
cached[intervalStart] = UsageStamp{
AtRestTotal: cacheStamp.AtRestTotal + stamp.AtRestTotal,
IntervalStart: intervalStart,
AtRestTotal: cacheStamp.AtRestTotal + stamp.AtRestTotal,
AtRestTotalBytes: cacheStamp.AtRestTotalBytes + stamp.AtRestTotalBytes,
IntervalStart: intervalStart,
}
} else {
cached[intervalStart] = UsageStamp{
AtRestTotal: stamp.AtRestTotal,
IntervalStart: intervalStart,
AtRestTotal: stamp.AtRestTotal,
AtRestTotalBytes: stamp.AtRestTotalBytes,
IntervalStart: intervalStart,
}
}