From dab4288899f580dff70e9cb9e9dc4a03bdc2e551 Mon Sep 17 00:00:00 2001 From: Clement Sam Date: Wed, 3 May 2023 16:56:43 +0000 Subject: [PATCH] web/multinode: fix used space graph showing 0 Resolves https://github.com/storj/storj/issues/5566 Change-Id: Ib9c81fa2c92ed71ccf07e7a0c9b6f61c46294f09 --- multinode/storage/service.go | 34 ++++++++++++++++++++++------------ multinode/storage/storage.go | 20 ++++++++++++-------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/multinode/storage/service.go b/multinode/storage/service.go index 083a4b9aa..147f399f0 100644 --- a/multinode/storage/service.go +++ b/multinode/storage/service.go @@ -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 } diff --git a/multinode/storage/storage.go b/multinode/storage/storage.go index 2ed54f737..b128e1a19 100644 --- a/multinode/storage/storage.go +++ b/multinode/storage/storage.go @@ -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, } }