{cmd/satellite/reports, satellite/attribution}: type and variable name adjustments
Change-Id: I553b7ed9cb702479911baaf54d77d8f2662faaa2
This commit is contained in:
parent
175d1e694c
commit
dd6ab25cbd
@ -31,9 +31,11 @@ var headers = []string{
|
||||
"gbEgress",
|
||||
}
|
||||
|
||||
// UserAgentAttributions is a map of attribution totals per user agent.
|
||||
type UserAgentAttributions map[string]attributionTotal
|
||||
type attributionTotal struct {
|
||||
// AttributionTotals is a map of attribution totals per user agent.
|
||||
type AttributionTotals map[string]Total
|
||||
|
||||
// Total is the total attributable usage for a user agent over a period of time.
|
||||
type Total struct {
|
||||
ByteHours float64
|
||||
SegmentHours float64
|
||||
ObjectHours float64
|
||||
@ -96,8 +98,8 @@ func GenerateAttributionCSV(ctx context.Context, database string, start time.Tim
|
||||
}
|
||||
|
||||
// SumAttributionByUserAgent sums all bucket attribution by the first entry in the user agent.
|
||||
func SumAttributionByUserAgent(rows []*attribution.BucketAttribution, log *zap.Logger) UserAgentAttributions {
|
||||
partnerAttributionTotals := make(map[string]attributionTotal)
|
||||
func SumAttributionByUserAgent(rows []*attribution.BucketUsage, log *zap.Logger) AttributionTotals {
|
||||
attributionTotals := make(map[string]Total)
|
||||
userAgentParseFailures := make(map[string]bool)
|
||||
|
||||
for _, row := range rows {
|
||||
@ -114,8 +116,8 @@ func SumAttributionByUserAgent(rows []*attribution.BucketAttribution, log *zap.L
|
||||
|
||||
userAgent := strings.ToLower(userAgentEntries[0].Product)
|
||||
|
||||
if _, ok := partnerAttributionTotals[userAgent]; !ok {
|
||||
partnerAttributionTotals[userAgent] = attributionTotal{
|
||||
if _, ok := attributionTotals[userAgent]; !ok {
|
||||
attributionTotals[userAgent] = Total{
|
||||
ByteHours: row.ByteHours,
|
||||
SegmentHours: row.SegmentHours,
|
||||
ObjectHours: row.ObjectHours,
|
||||
@ -123,7 +125,7 @@ func SumAttributionByUserAgent(rows []*attribution.BucketAttribution, log *zap.L
|
||||
BytesEgress: row.EgressData,
|
||||
}
|
||||
} else {
|
||||
partnerTotal := partnerAttributionTotals[userAgent]
|
||||
partnerTotal := attributionTotals[userAgent]
|
||||
|
||||
partnerTotal.ByteHours += row.ByteHours
|
||||
partnerTotal.SegmentHours += row.SegmentHours
|
||||
@ -131,8 +133,8 @@ func SumAttributionByUserAgent(rows []*attribution.BucketAttribution, log *zap.L
|
||||
partnerTotal.BucketHours += float64(row.Hours)
|
||||
partnerTotal.BytesEgress += row.EgressData
|
||||
|
||||
partnerAttributionTotals[userAgent] = partnerTotal
|
||||
attributionTotals[userAgent] = partnerTotal
|
||||
}
|
||||
}
|
||||
return partnerAttributionTotals
|
||||
return attributionTotals
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
func TestSumAttributionByUserAgent(t *testing.T) {
|
||||
log := zaptest.NewLogger(t)
|
||||
// test empty user agents
|
||||
attributions := []*attribution.BucketAttribution{
|
||||
attributions := []*attribution.BucketUsage{
|
||||
{
|
||||
UserAgent: []byte{},
|
||||
ByteHours: 1,
|
||||
@ -38,7 +38,7 @@ func TestSumAttributionByUserAgent(t *testing.T) {
|
||||
|
||||
// test user agent with additional entries and uppercase letters is summed with
|
||||
// the first one
|
||||
attributions = []*attribution.BucketAttribution{
|
||||
attributions = []*attribution.BucketUsage{
|
||||
{
|
||||
UserAgent: []byte("teststorj"),
|
||||
ByteHours: 1,
|
||||
@ -65,7 +65,7 @@ func TestSumAttributionByUserAgent(t *testing.T) {
|
||||
require.Equal(t, int64(2), totals["teststorj"].BytesEgress)
|
||||
|
||||
// test two user agents are summed separately
|
||||
attributions = []*attribution.BucketAttribution{
|
||||
attributions = []*attribution.BucketUsage{
|
||||
{
|
||||
UserAgent: []byte("teststorj1"),
|
||||
ByteHours: 1,
|
||||
|
@ -25,8 +25,8 @@ type Info struct {
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// BucketAttribution is attribution data for a single bucket.
|
||||
type BucketAttribution struct {
|
||||
// BucketUsage is the usage data for a single bucket.
|
||||
type BucketUsage struct {
|
||||
PartnerID []byte
|
||||
UserAgent []byte
|
||||
ProjectID []byte
|
||||
@ -47,7 +47,7 @@ type DB interface {
|
||||
// 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)
|
||||
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)
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ func (keys *attributionDB) Insert(ctx context.Context, info *attribution.Info) (
|
||||
}
|
||||
|
||||
// QueryAttribution queries partner bucket attribution data.
|
||||
func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) (_ []*attribution.BucketAttribution, err error) {
|
||||
func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) (_ []*attribution.BucketUsage, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
rows, err := keys.db.DB.QueryContext(ctx, keys.db.Rebind(valueAttrQuery), partnerID[:], userAgent, start.UTC(), end.UTC(), partnerID[:], userAgent, start.UTC(), end.UTC())
|
||||
@ -292,9 +292,9 @@ func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.
|
||||
}
|
||||
defer func() { err = errs.Combine(err, rows.Close()) }()
|
||||
|
||||
results := []*attribution.BucketAttribution{}
|
||||
results := []*attribution.BucketUsage{}
|
||||
for rows.Next() {
|
||||
r := &attribution.BucketAttribution{}
|
||||
r := &attribution.BucketUsage{}
|
||||
var inline, remote float64
|
||||
err := rows.Scan(&r.PartnerID, &r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
||||
if err != nil {
|
||||
@ -311,7 +311,7 @@ func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.
|
||||
}
|
||||
|
||||
// QueryAllAttribution queries all partner bucket attribution data.
|
||||
func (keys *attributionDB) QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) (_ []*attribution.BucketAttribution, err error) {
|
||||
func (keys *attributionDB) QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) (_ []*attribution.BucketUsage, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
rows, err := keys.db.DB.QueryContext(ctx, keys.db.Rebind(allValueAttrQuery), start.UTC(), end.UTC())
|
||||
@ -320,9 +320,9 @@ func (keys *attributionDB) QueryAllAttribution(ctx context.Context, start time.T
|
||||
}
|
||||
defer func() { err = errs.Combine(err, rows.Close()) }()
|
||||
|
||||
results := []*attribution.BucketAttribution{}
|
||||
results := []*attribution.BucketUsage{}
|
||||
for rows.Next() {
|
||||
r := &attribution.BucketAttribution{}
|
||||
r := &attribution.BucketUsage{}
|
||||
var inline, remote float64
|
||||
err := rows.Scan(&r.PartnerID, &r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user