storj/pkg/accounting/bucketusage.go
Jess G d51bdf14df
project usage limiting (#1561)
* reorg uplink cmd files for consistency

* init implementation of usage limiting

* Revert "reorg uplink cmd files for consistency"

This reverts commit 91ced7639bf36fc8af1db237b01e233ca92f1890.

* add changes per CR comments

* fix custom query to use rebind

* updates per convo about what to limit on

* changes per comments

* fix syntax and comments

* add integration test, add db methods for test

* update migration, add rebind to query

* update testdata for psql

* remove unneeded drop index statement

* fix migrations, fix calculate usage limit

* fix comment

* add audit test back

* change methods to use bucketName/projectID, fix tests

* add changes per CR comments

* add test for uplink upload and err ssg

* changes per CR comments

* check get/put limit separately
2019-04-02 11:21:18 -07:00

91 lines
1.8 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package accounting
import (
"context"
"time"
"github.com/skyrings/skyring-common/tools/uuid"
)
// BucketUsage is bucket usage rollup repository
type BucketUsage interface {
Get(ctx context.Context, id uuid.UUID) (*BucketRollup, error)
GetPaged(ctx context.Context, cursor *BucketRollupCursor) ([]BucketRollup, error)
Create(ctx context.Context, rollup BucketRollup) (*BucketRollup, error)
Delete(ctx context.Context, id uuid.UUID) error
}
// Order is sorting order can be asc or desc
type Order string
const (
// Asc ascending sort order
Asc Order = "asc"
// Desc descending sort order
Desc Order = "desc"
)
// BucketRollupCursor encapsulates cursor based page
type BucketRollupCursor struct {
BucketID uuid.UUID
Before time.Time
After time.Time
Order Order
PageSize int
Next *BucketRollupCursor
}
// BucketRollup holds usage rollup info
type BucketRollup struct {
ID uuid.UUID
BucketID uuid.UUID
RollupEndTime time.Time
RemoteStoredData uint64
InlineStoredData uint64
RemoteSegments uint
InlineSegments uint
Objects uint
MetadataSize uint64
RepairEgress uint64
GetEgress uint64
AuditEgress uint64
}
// BucketBandwidthRollup contains data about bandwidth rollup
type BucketBandwidthRollup struct {
BucketName string
ProjectID uuid.UUID
IntervalStart time.Time
IntervalSeconds uint
Action uint
Inline uint64
Allocated uint64
Settled uint64
}
// BucketStorageTally holds data about a bucket tally
type BucketStorageTally struct {
BucketName string
ProjectID uuid.UUID
IntervalStart time.Time
InlineSegmentCount int64
RemoteSegmentCount int64
ObjectCount int64
InlineBytes int64
RemoteBytes int64
MetadataSize int64
}