storj/satellite/metrics/counter.go
Egon Elbre 8093c666a6 satellite/metrics: allow for multipart objects
We have multipart objects so we may get multiple inline segments
sequences or no segments at all for objects.

Change-Id: Ic19150efe2ca2b1c60ddd5d30b1317922221c221
2021-02-18 20:04:41 +02:00

58 lines
1.6 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package metrics
import (
"context"
"storj.io/common/uuid"
"storj.io/storj/satellite/metainfo"
)
// Counter implements the metainfo loop observer interface for data science metrics collection.
//
// architecture: Observer
type Counter struct {
ObjectCount int64
RemoteDependent int64
checkObjectRemoteness uuid.UUID
}
// NewCounter instantiates a new counter to be subscribed to the metainfo loop.
func NewCounter() *Counter {
return &Counter{}
}
// Object increments the count for total objects and for inline objects in case the object has no segments.
func (counter *Counter) Object(ctx context.Context, object *metainfo.Object) (err error) {
defer mon.Task()(&ctx)(&err)
counter.ObjectCount++
counter.checkObjectRemoteness = object.StreamID
return nil
}
// RemoteSegment increments the count for objects with remote segments.
func (counter *Counter) RemoteSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
defer mon.Task()(&ctx)(&err)
if counter.checkObjectRemoteness == segment.StreamID {
counter.RemoteDependent++
// we need to count this only once
counter.checkObjectRemoteness = uuid.UUID{}
}
return nil
}
// InlineSegment increments the count for inline objects.
func (counter *Counter) InlineSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
return nil
}
// InlineObjectCount returns the count of objects that are inline only.
func (counter *Counter) InlineObjectCount() int64 {
return counter.ObjectCount - counter.RemoteDependent
}