satellite/metrics: fix metrics for total inline/remote bytes and segments

Change-Id: I567ce127590a4712cab296d28a19838e3a632021
This commit is contained in:
Michał Niewrzał 2021-07-30 17:31:20 +02:00
parent fda316b461
commit 011b944382
4 changed files with 34 additions and 1 deletions

View File

@ -61,6 +61,10 @@ storj.io/storj/satellite/metabase/segmentloop.*Service.RunOnce Task
storj.io/storj/satellite/metainfo."metainfo_rate_limit_exceeded" Event
storj.io/storj/satellite/metainfo/piecedeletion."delete_batch_size" IntVal
storj.io/storj/satellite/metainfo/piecedeletion."deletion_pieces_unhandled_count" IntVal
storj.io/storj/satellite/metrics."total_inline_bytes" IntVal
storj.io/storj/satellite/metrics."total_inline_segments" IntVal
storj.io/storj/satellite/metrics."total_remote_bytes" IntVal
storj.io/storj/satellite/metrics."total_remote_segments" IntVal
storj.io/storj/satellite/orders."download_failed_not_enough_pieces_uplink" Meter
storj.io/storj/satellite/repair/checker."checker_injured_segment_health" FloatVal
storj.io/storj/satellite/repair/checker."checker_segment_age" IntVal

View File

@ -41,7 +41,7 @@ func NewChore(log *zap.Logger, config Config, loop *segmentloop.Service) *Chore
return &Chore{
log: log,
config: config,
// This chore monitors metainfo loop, so it's fine to use very small cycle time.
// This chore monitors segment loop, so it's fine to use very small cycle time.
Loop: sync2.NewCycle(time.Nanosecond),
segmentLoop: loop,
}
@ -64,6 +64,12 @@ func (chore *Chore) Run(ctx context.Context) (err error) {
mon.IntVal("remote_dependent_object_count").Observe(chore.Counter.RemoteObjects)
mon.IntVal("inline_object_count").Observe(chore.Counter.InlineObjects)
mon.IntVal("total_inline_bytes").Observe(chore.Counter.TotalInlineBytes) //mon:locked
mon.IntVal("total_remote_bytes").Observe(chore.Counter.TotalRemoteBytes) //mon:locked
mon.IntVal("total_inline_segments").Observe(chore.Counter.TotalInlineSegments) //mon:locked
mon.IntVal("total_remote_segments").Observe(chore.Counter.TotalRemoteSegments) //mon:locked
// TODO move this metric to a place where objects are iterated e.g. tally
// or drop it completely as we can easily get this value with redash
// mon.IntVal("total_object_count").Observe(chore.Counter.ObjectCount)

View File

@ -19,6 +19,14 @@ type Counter struct {
// number of objects that has all inline segments
InlineObjects int64
// encrypted size
TotalInlineBytes int64
// encrypted size
TotalRemoteBytes int64
TotalInlineSegments int64
TotalRemoteSegments int64
lastStreamID uuid.UUID
onlyInline bool
}
@ -41,6 +49,9 @@ func (counter *Counter) RemoteSegment(ctx context.Context, segment *segmentloop.
counter.onlyInline = false
counter.TotalRemoteBytes += int64(segment.EncryptedSize)
counter.TotalRemoteSegments++
if counter.lastStreamID.Compare(segment.StreamID) != 0 {
counter.RemoteObjects++
@ -52,6 +63,11 @@ func (counter *Counter) RemoteSegment(ctx context.Context, segment *segmentloop.
// InlineSegment increments the count for inline objects.
func (counter *Counter) InlineSegment(ctx context.Context, segment *segmentloop.Segment) (err error) {
defer mon.Task()(&ctx)(&err)
counter.TotalInlineBytes += int64(segment.EncryptedSize)
counter.TotalInlineSegments++
if counter.lastStreamID.Compare(segment.StreamID) != 0 {
if counter.onlyInline {
counter.InlineObjects++

View File

@ -45,6 +45,13 @@ func TestCounterInlineAndRemote(t *testing.T) {
metricsChore.Loop.TriggerWait()
require.EqualValues(t, 2, metricsChore.Counter.InlineObjects)
require.EqualValues(t, 2, metricsChore.Counter.RemoteObjects)
require.EqualValues(t, 2, metricsChore.Counter.TotalInlineSegments)
require.EqualValues(t, 2, metricsChore.Counter.TotalRemoteSegments)
// 2 inline segments * (1024 + encryption overhead)
require.EqualValues(t, 2080, metricsChore.Counter.TotalInlineBytes)
// 2 remote segments * (8192 + encryption overhead)
require.EqualValues(t, 29696, metricsChore.Counter.TotalRemoteBytes)
})
}