2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-26 21:49:55 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
2018-12-12 21:24:08 +00:00
|
|
|
"context"
|
2018-12-14 14:27:21 +00:00
|
|
|
"time"
|
2018-12-12 21:24:08 +00:00
|
|
|
|
2019-04-02 19:21:18 +01:00
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
2018-12-18 17:18:42 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-12-07 14:46:42 +00:00
|
|
|
)
|
2018-12-05 14:03:23 +00:00
|
|
|
|
2019-04-04 16:20:59 +01:00
|
|
|
// RollupStats is a convenience alias
|
2019-01-16 19:30:33 +00:00
|
|
|
type RollupStats map[time.Time]map[storj.NodeID]*Rollup
|
|
|
|
|
2019-04-04 16:20:59 +01:00
|
|
|
// Raw mirrors dbx.AccountingRaw, allowing us to use that struct without leaking dbx
|
2019-01-16 19:30:33 +00:00
|
|
|
type Raw struct {
|
|
|
|
ID int64
|
|
|
|
NodeID storj.NodeID
|
|
|
|
IntervalEndTime time.Time
|
|
|
|
DataTotal float64
|
|
|
|
DataType int
|
|
|
|
CreatedAt time.Time
|
|
|
|
}
|
|
|
|
|
2019-04-04 16:20:59 +01:00
|
|
|
// StoragenodeBandwidthRollup mirrors dbx.StoragenodeBandwidthRollup, allowing us to use the struct without leaking dbx
|
|
|
|
type StoragenodeBandwidthRollup struct {
|
|
|
|
NodeID storj.NodeID
|
|
|
|
IntervalStart time.Time
|
|
|
|
Action uint
|
|
|
|
Settled uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rollup mirrors dbx.AccountingRollup, allowing us to use that struct without leaking dbx
|
2019-01-16 19:30:33 +00:00
|
|
|
type Rollup struct {
|
|
|
|
ID int64
|
|
|
|
NodeID storj.NodeID
|
|
|
|
StartTime time.Time
|
|
|
|
PutTotal int64
|
|
|
|
GetTotal int64
|
|
|
|
GetAuditTotal int64
|
|
|
|
GetRepairTotal int64
|
|
|
|
PutRepairTotal int64
|
|
|
|
AtRestTotal float64
|
|
|
|
}
|
2019-01-10 11:41:57 +00:00
|
|
|
|
2019-04-02 19:21:18 +01:00
|
|
|
// DB stores information about bandwidth and storage usage
|
2018-12-14 14:27:21 +00:00
|
|
|
type DB interface {
|
2019-02-01 18:50:12 +00:00
|
|
|
// LastTimestamp records the latest last tallied time.
|
|
|
|
LastTimestamp(ctx context.Context, timestampType string) (time.Time, error)
|
2019-01-02 17:53:27 +00:00
|
|
|
// SaveAtRestRaw records raw tallies of at-rest-data.
|
2019-02-07 04:16:24 +00:00
|
|
|
SaveAtRestRaw(ctx context.Context, latestTally time.Time, created time.Time, nodeData map[storj.NodeID]float64) error
|
2019-01-16 19:30:33 +00:00
|
|
|
// GetRaw retrieves all raw tallies
|
|
|
|
GetRaw(ctx context.Context) ([]*Raw, error)
|
2019-04-04 16:20:59 +01:00
|
|
|
// GetRawSince retrieves all raw tallies since latestRollup
|
2019-01-16 19:30:33 +00:00
|
|
|
GetRawSince(ctx context.Context, latestRollup time.Time) ([]*Raw, error)
|
2019-04-04 16:20:59 +01:00
|
|
|
// GetStoragenodeBandwidthSince retrieves all storagenode_bandwidth_rollup entires since latestRollup
|
|
|
|
GetStoragenodeBandwidthSince(ctx context.Context, latestRollup time.Time) ([]*StoragenodeBandwidthRollup, error)
|
2019-01-16 19:30:33 +00:00
|
|
|
// SaveRollup records raw tallies of at rest data to the database
|
2019-02-01 18:50:12 +00:00
|
|
|
SaveRollup(ctx context.Context, latestTally time.Time, stats RollupStats) error
|
2019-04-01 14:42:17 +01:00
|
|
|
// SaveBucketTallies saves the latest bucket info
|
|
|
|
SaveBucketTallies(ctx context.Context, intervalStart time.Time, bucketTallies map[string]*BucketTally) error
|
2019-03-25 22:25:09 +00:00
|
|
|
// QueryPaymentInfo queries Overlay, Accounting Rollup on nodeID
|
2019-01-17 18:34:13 +00:00
|
|
|
QueryPaymentInfo(ctx context.Context, start time.Time, end time.Time) ([]*CSVRow, error)
|
2019-03-12 13:08:23 +00:00
|
|
|
// DeleteRawBefore deletes all raw tallies prior to some time
|
2019-03-14 21:12:47 +00:00
|
|
|
DeleteRawBefore(ctx context.Context, latestRollup time.Time) error
|
2019-04-02 19:21:18 +01:00
|
|
|
// CreateBucketStorageTally creates a record for BucketStorageTally in the accounting DB table
|
|
|
|
CreateBucketStorageTally(ctx context.Context, tally BucketStorageTally) error
|
|
|
|
// ProjectBandwidthTotal returns the sum of GET bandwidth usage for a projectID in the past time frame
|
|
|
|
ProjectBandwidthTotal(ctx context.Context, bucketID []byte, from time.Time) (int64, error)
|
|
|
|
// ProjectStorageTotals returns the current inline and remote storage usage for a projectID
|
|
|
|
ProjectStorageTotals(ctx context.Context, projectID uuid.UUID) (int64, int64, error)
|
2018-11-26 21:49:55 +00:00
|
|
|
}
|