2019-10-16 19:08:33 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-12-18 12:27:45 +00:00
|
|
|
"storj.io/common/uuid"
|
2021-04-22 10:07:18 +01:00
|
|
|
"storj.io/storj/satellite/metabase/metaloop"
|
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 {
|
2021-02-18 15:26:27 +00:00
|
|
|
ObjectCount int64
|
2019-10-16 19:08:33 +01:00
|
|
|
RemoteDependent int64
|
2021-02-18 15:26:27 +00:00
|
|
|
|
|
|
|
checkObjectRemoteness uuid.UUID
|
2019-10-16 19:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewCounter instantiates a new counter to be subscribed to the metainfo loop.
|
|
|
|
func NewCounter() *Counter {
|
|
|
|
return &Counter{}
|
|
|
|
}
|
|
|
|
|
2021-04-01 11:56:39 +01:00
|
|
|
// LoopStarted is called at each start of a loop.
|
|
|
|
func (counter *Counter) LoopStarted(context.Context, metaloop.LoopInfo) (err error) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-18 12:27:45 +00:00
|
|
|
// Object increments the count for total objects and for inline objects in case the object has no segments.
|
2021-03-23 12:14:38 +00:00
|
|
|
func (counter *Counter) Object(ctx context.Context, object *metaloop.Object) (err error) {
|
2020-12-18 12:27:45 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2021-02-18 15:26:27 +00:00
|
|
|
counter.ObjectCount++
|
|
|
|
counter.checkObjectRemoteness = object.StreamID
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-18 12:27:45 +00:00
|
|
|
// RemoteSegment increments the count for objects with remote segments.
|
2021-03-23 12:14:38 +00:00
|
|
|
func (counter *Counter) RemoteSegment(ctx context.Context, segment *metaloop.Segment) (err error) {
|
2020-12-18 12:27:45 +00:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2021-02-18 15:26:27 +00:00
|
|
|
if counter.checkObjectRemoteness == segment.StreamID {
|
|
|
|
counter.RemoteDependent++
|
|
|
|
// we need to count this only once
|
|
|
|
counter.checkObjectRemoteness = uuid.UUID{}
|
2020-12-18 12:27:45 +00:00
|
|
|
}
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-18 12:27:45 +00:00
|
|
|
// InlineSegment increments the count for inline objects.
|
2021-03-23 12:14:38 +00:00
|
|
|
func (counter *Counter) InlineSegment(ctx context.Context, segment *metaloop.Segment) (err error) {
|
2019-10-16 19:08:33 +01:00
|
|
|
return nil
|
|
|
|
}
|
2021-02-18 15:26:27 +00:00
|
|
|
|
|
|
|
// InlineObjectCount returns the count of objects that are inline only.
|
|
|
|
func (counter *Counter) InlineObjectCount() int64 {
|
|
|
|
return counter.ObjectCount - counter.RemoteDependent
|
|
|
|
}
|