2019-06-19 13:02:37 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
// Package attribution implements value attribution from docs/design/value-attribution.md
|
|
|
|
package attribution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-06-21 20:14:34 +01:00
|
|
|
"github.com/zeebo/errs"
|
2020-03-30 10:08:50 +01:00
|
|
|
|
|
|
|
"storj.io/common/uuid"
|
2019-06-19 13:02:37 +01:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// ErrBucketNotAttributed is returned if a requested bucket not attributed(entry not found).
|
2019-06-21 20:14:34 +01:00
|
|
|
var ErrBucketNotAttributed = errs.Class("bucket not attributed")
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Info describing value attribution from partner to bucket.
|
2019-06-19 13:02:37 +01:00
|
|
|
type Info struct {
|
|
|
|
ProjectID uuid.UUID
|
|
|
|
BucketName []byte
|
|
|
|
PartnerID uuid.UUID
|
2021-09-23 00:38:18 +01:00
|
|
|
UserAgent []byte
|
2019-06-19 13:02:37 +01:00
|
|
|
CreatedAt time.Time
|
|
|
|
}
|
|
|
|
|
2022-04-25 21:56:11 +01:00
|
|
|
// BucketUsage is the usage data for a single bucket.
|
|
|
|
type BucketUsage struct {
|
2022-04-07 21:14:23 +01:00
|
|
|
PartnerID []byte
|
|
|
|
UserAgent []byte
|
|
|
|
ProjectID []byte
|
|
|
|
BucketName []byte
|
|
|
|
ByteHours float64
|
|
|
|
SegmentHours float64
|
|
|
|
ObjectHours float64
|
|
|
|
EgressData int64
|
|
|
|
Hours int
|
2019-06-25 21:58:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// DB implements the database for value attribution table.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2019-06-19 13:02:37 +01:00
|
|
|
type DB interface {
|
|
|
|
// Get retrieves attribution info using project id and bucket name.
|
|
|
|
Get(ctx context.Context, projectID uuid.UUID, bucketName []byte) (*Info, error)
|
2022-01-20 21:15:13 +00:00
|
|
|
// Insert creates and stores new Info.
|
2019-06-19 13:02:37 +01:00
|
|
|
Insert(ctx context.Context, info *Info) (*Info, error)
|
2022-01-20 21:15:13 +00:00
|
|
|
// QueryAttribution queries partner bucket attribution data.
|
2022-04-25 21:56:11 +01:00
|
|
|
QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) ([]*BucketUsage, error)
|
|
|
|
// QueryAllAttribution queries all partner bucket usage data.
|
|
|
|
QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) ([]*BucketUsage, error)
|
2019-06-19 13:02:37 +01:00
|
|
|
}
|