2019-10-16 19:08:33 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-10-27 06:59:14 +00:00
|
|
|
"storj.io/storj/satellite/metainfo"
|
2019-10-16 19:08:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Counter implements the metainfo loop observer interface for data science metrics collection.
|
|
|
|
//
|
|
|
|
// architecture: Observer
|
|
|
|
type Counter struct {
|
|
|
|
RemoteDependent int64
|
|
|
|
Inline int64
|
|
|
|
Total int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewCounter instantiates a new counter to be subscribed to the metainfo loop.
|
|
|
|
func NewCounter() *Counter {
|
|
|
|
return &Counter{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object increments counts for inline objects and remote dependent objects.
|
2020-10-27 06:59:14 +00:00
|
|
|
func (counter *Counter) Object(ctx context.Context, object *metainfo.Object) (err error) {
|
|
|
|
if object.SegmentCount == 1 && object.LastSegment.Inline {
|
2019-10-16 19:08:33 +01:00
|
|
|
counter.Inline++
|
|
|
|
} else {
|
|
|
|
counter.RemoteDependent++
|
|
|
|
}
|
|
|
|
counter.Total++
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoteSegment returns nil because counter does not interact with remote segments this way for now.
|
2020-10-27 06:59:14 +00:00
|
|
|
func (counter *Counter) RemoteSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// InlineSegment returns nil because counter does not interact with inline segments this way for now.
|
2020-10-27 06:59:14 +00:00
|
|
|
func (counter *Counter) InlineSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|