satellite/storageusage: Group accounting rollups at_rest_total by day
When investigating a gap in storage usage data in the SN dashboard, I noticed that there were 2 entries in the accounting_rollups table on the date of the gap. This change accounts for multiple entries in the accounting_rollups table for a given day. Change-Id: Ibf2b5d0455117cb0417163e8fcfb7e509d594171
This commit is contained in:
parent
7552ff26ec
commit
ab1d0f097d
@ -134,6 +134,48 @@ func TestStorageNodeUsage(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// There can be more than one rollup in a day. Test that the sums are grouped by day.
|
||||
func TestStorageNodeUsage_TwoRollupsInADay(t *testing.T) {
|
||||
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
||||
now := time.Now().UTC()
|
||||
|
||||
nodeID := testrand.NodeID()
|
||||
|
||||
accountingDB := db.StoragenodeAccounting()
|
||||
|
||||
// create last rollup timestamp
|
||||
_, err := accountingDB.LastTimestamp(ctx, accounting.LastRollup)
|
||||
require.NoError(t, err)
|
||||
|
||||
t1 := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
t2 := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, now.Location())
|
||||
rollups := make(accounting.RollupStats)
|
||||
|
||||
rollups[t1] = make(map[storj.NodeID]*accounting.Rollup)
|
||||
rollups[t2] = make(map[storj.NodeID]*accounting.Rollup)
|
||||
|
||||
rollups[t1][nodeID] = &accounting.Rollup{
|
||||
NodeID: nodeID,
|
||||
AtRestTotal: 1000,
|
||||
}
|
||||
rollups[t2][nodeID] = &accounting.Rollup{
|
||||
NodeID: nodeID,
|
||||
AtRestTotal: 500,
|
||||
}
|
||||
// save rollup
|
||||
err = accountingDB.SaveRollup(ctx, now.Add(time.Hour*-24), rollups)
|
||||
require.NoError(t, err)
|
||||
|
||||
nodeStorageUsages, err := accountingDB.QueryStorageNodeUsage(ctx, nodeID, time.Time{}, now)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, nodeStorageUsages)
|
||||
require.Equal(t, 1, len(nodeStorageUsages))
|
||||
|
||||
require.Equal(t, nodeID, nodeStorageUsages[0].NodeID)
|
||||
require.EqualValues(t, 1500, nodeStorageUsages[0].StorageUsed)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProjectLimits(t *testing.T) {
|
||||
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
||||
proj, err := db.Console().Projects().Insert(ctx, &console.Project{Name: "test", OwnerID: testrand.UUID()})
|
||||
|
@ -289,10 +289,11 @@ func (db *StoragenodeAccounting) QueryStorageNodeUsage(ctx context.Context, node
|
||||
start, end = start.UTC(), end.UTC()
|
||||
|
||||
query := `
|
||||
SELECT at_rest_total, (start_time at time zone 'UTC')::date as start_time
|
||||
SELECT SUM(at_rest_total), (start_time at time zone 'UTC')::date as start_time
|
||||
FROM accounting_rollups
|
||||
WHERE node_id = $1
|
||||
AND $2 <= start_time AND start_time <= $3
|
||||
GROUP BY (start_time at time zone 'UTC')::date
|
||||
UNION
|
||||
SELECT SUM(data_total) AS at_rest_total, (interval_end_time at time zone 'UTC')::date AS start_time
|
||||
FROM storagenode_storage_tallies
|
||||
|
Loading…
Reference in New Issue
Block a user