From 25f8f678abf46af944526cc2d13ea3240dcda95b Mon Sep 17 00:00:00 2001 From: Clement Sam Date: Mon, 1 Aug 2022 08:52:16 +0000 Subject: [PATCH] storagenode/nodestats: retrieve storage usage starting from last day of previous month For the storagenode usage graph currently, 1. the graph is still likely to contain spikes on the first day of the month for a newly setup storagenode because there's no previous interval_end_time to deduct from. 2. if a node goes offline for too long, say the last usage report in the storageusage cache has an interval_end_time of 2020-07-30 00:00:00+00:00 and later, it comes back online a few days later, it requests for the storage usage from the satellite starting from the current month, say 2021-01-01 00:00:00+00:00, the calculated hours for the first day would be 48 hours and it could be wrong because the cache is missing one day usage report. This PR addresses second issue on the storagenode side by requesting storage usage data, instead of just a month boundary, request for an interval starting from the last day of the previous month to the current day of the current month. The first one will be a tradeoff and wouldn't really matter since it will just be an issue on the first day the storagenode joined the satellite. Updates https://github.com/storj/storj/issues/4178 Change-Id: I041c56c412030ce013dd77dce11b0b5d6550927b --- storagenode/nodestats/cache.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storagenode/nodestats/cache.go b/storagenode/nodestats/cache.go index 611ed4568..2ca93f96c 100644 --- a/storagenode/nodestats/cache.go +++ b/storagenode/nodestats/cache.go @@ -170,6 +170,8 @@ func (cache *Cache) CacheSpaceUsage(ctx context.Context) (err error) { // get current month edges startDate, endDate := date.MonthBoundary(time.Now().UTC()) + // start from last day of previous month + startDate = startDate.AddDate(0, 0, -1) return cache.satelliteLoop(ctx, func(satellite storj.NodeID) error { spaceUsages, err := cache.service.GetDailyStorageUsage(ctx, satellite, startDate, endDate)