storj/satellite/attribution/db.go
ethanadams 0e528bc56e
Add attribution report to the satellite CLI (#2288)
* added satalite partner value attribution report. WIP

* WIP

* basic attribution report test completed. still a WIP

* cleanup

* fixed projectID conversion

* report display cleanup

* cleanup .added more test data

* added partnerID to query results

* fixed lint issues

* fix import order

* suggestions from PR review

* updated doc to reflect implementation

* clarification comments in the report SQL

* Changed based on PR suggestion

* More changes based on PR suggestions

* Changes based on PR suggestions

* reordered tests to make consistant with previous 2

* small comments cleanup

* More PR suggestions

* fixed lint issue and removed printf

* fixed var name

* Updates based on PR suggestions

* fixed message

* fixed test

* changes required after merge from master
2019-06-25 16:58:38 -04:00

45 lines
1.3 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/skyrings/skyring-common/tools/uuid"
"github.com/zeebo/errs"
)
// 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
CreatedAt time.Time
}
// CSVRow represents data from QueryAttribution without exposing dbx
type CSVRow struct {
PartnerID []byte
ProjectID []byte
BucketName []byte
RemoteBytesPerHour float64
InlineBytesPerHour float64
EgressData int64
}
// DB implements the database for value attribution table
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, start time.Time, end time.Time) ([]*CSVRow, error)
}