48fb3e947c
Attribution is attached to bucket usage, but that's more granular than necessary for the attribution report. This change iterates over the bucket attributions, parses the user agent, converts the first entry to lower case, and uses that as the key to a map which holds the attribution totals for each unique user agent. Change-Id: Ib2962ba0f57daa8a7298f11fcb1ac44a8bb97875
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
// 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"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"storj.io/common/uuid"
|
|
)
|
|
|
|
// ErrBucketNotAttributed is returned if a requested bucket not attributed(entry not found).
|
|
var ErrBucketNotAttributed = errs.Class("bucket not attributed")
|
|
|
|
// Info describing value attribution from partner to bucket.
|
|
type Info struct {
|
|
ProjectID uuid.UUID
|
|
BucketName []byte
|
|
PartnerID uuid.UUID
|
|
UserAgent []byte
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// BucketAttribution is attribution data for a single bucket.
|
|
type BucketAttribution struct {
|
|
PartnerID []byte
|
|
UserAgent []byte
|
|
ProjectID []byte
|
|
BucketName []byte
|
|
ByteHours float64
|
|
SegmentHours float64
|
|
ObjectHours float64
|
|
EgressData int64
|
|
Hours int
|
|
}
|
|
|
|
// DB implements the database for value attribution table.
|
|
//
|
|
// architecture: Database
|
|
type DB interface {
|
|
// Get retrieves attribution info using project id and bucket name.
|
|
Get(ctx context.Context, projectID uuid.UUID, bucketName []byte) (*Info, error)
|
|
// Insert creates and stores new Info.
|
|
Insert(ctx context.Context, info *Info) (*Info, error)
|
|
// QueryAttribution queries partner bucket attribution data.
|
|
QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) ([]*BucketAttribution, error)
|
|
// QueryAllAttribution queries all partner bucket attribution data.
|
|
QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) ([]*BucketAttribution, error)
|
|
}
|