storj/satellite/metrics/counter.go
Kaloyan Raev 92a2be2abd satellite/metainfo: get away from using pb.Pointer in Metainfo Loop
As part of the Metainfo Refactoring, we need to make the Metainfo Loop
working with both the current PointerDB and the new Metabase. Thus, the
Metainfo Loop should pass to the Observer interface more specific Object
and Segment types instead of pb.Pointer.

After this change, there are still a couple of use cases that require
access to the pb.Pointer (hence we have it as a field in the
metainfo.Segment type):
1. Expired Deletion Service
2. Repair Service

It would require additional refactoring in these two services before we
are able to clean this.

Change-Id: Ib3eb6b7507ed89d5ba745ffbb6b37524ef10ed9f
2020-10-27 13:06:47 +00:00

47 lines
1.2 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package metrics
import (
"context"
"storj.io/storj/satellite/metainfo"
)
// 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.
func (counter *Counter) Object(ctx context.Context, object *metainfo.Object) (err error) {
if object.SegmentCount == 1 && object.LastSegment.Inline {
counter.Inline++
} else {
counter.RemoteDependent++
}
counter.Total++
return nil
}
// RemoteSegment returns nil because counter does not interact with remote segments this way for now.
func (counter *Counter) RemoteSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
return nil
}
// InlineSegment returns nil because counter does not interact with inline segments this way for now.
func (counter *Counter) InlineSegment(ctx context.Context, segment *metainfo.Segment) (err error) {
return nil
}