Skip to content

Commit

Permalink
satellite/metrics: add metric of total segments with expiration set
Browse files Browse the repository at this point in the history
Change-Id: I87c2c9ca0aff94492bab69489bdf4ea2f82de019
  • Loading branch information
mniewrzal committed Jan 3, 2024
1 parent f213b38 commit c30b794
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions monkit.lock
Expand Up @@ -76,6 +76,7 @@ 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/metrics."total_segments_with_expires_at" 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
Expand Down
4 changes: 4 additions & 0 deletions satellite/metrics/metrics.go
Expand Up @@ -22,6 +22,9 @@ type Metrics struct {

// TotalRemoteSegments is the count of remote segments across all objects.
TotalRemoteSegments int64

// TotalSegmentsWithExpiresAt is the count of segments that will expire automatically.
TotalSegmentsWithExpiresAt int64
}

// Reset resets the invidual metrics back to zero.
Expand All @@ -37,4 +40,5 @@ func (metrics *Metrics) Aggregate(partial Metrics) {
metrics.TotalRemoteBytes += partial.TotalRemoteBytes
metrics.TotalInlineSegments += partial.TotalInlineSegments
metrics.TotalRemoteSegments += partial.TotalRemoteSegments
metrics.TotalSegmentsWithExpiresAt += partial.TotalSegmentsWithExpiresAt
}
15 changes: 11 additions & 4 deletions satellite/metrics/observer.go
Expand Up @@ -71,6 +71,8 @@ func (obs *Observer) Finish(ctx context.Context) error {

mon.IntVal("total_inline_segments").Observe(obs.metrics.TotalInlineSegments) //mon:locked
mon.IntVal("total_remote_segments").Observe(obs.metrics.TotalRemoteSegments) //mon:locked

mon.IntVal("total_segments_with_expires_at").Observe(obs.metrics.TotalSegmentsWithExpiresAt) //mon:locked
return nil
}

Expand Down Expand Up @@ -102,6 +104,9 @@ func (fork *observerFork) Process(ctx context.Context, segments []rangedloop.Seg
fork.stream.remoteSegments++
fork.stream.remoteBytes += int64(segment.EncryptedSize)
}
if segment.ExpiresAt != nil {
fork.stream.segmentsWithExpiresAt++
}
}
return nil
}
Expand All @@ -113,6 +118,7 @@ func (fork *observerFork) Flush() {
fork.totals.TotalRemoteSegments += fork.stream.remoteSegments
fork.totals.TotalInlineBytes += fork.stream.inlineBytes
fork.totals.TotalRemoteBytes += fork.stream.remoteBytes
fork.totals.TotalSegmentsWithExpiresAt += fork.stream.segmentsWithExpiresAt
if fork.stream.remoteSegments > 0 {
// At least one remote segment was found for this stream so classify
// as a remote object.
Expand All @@ -127,8 +133,9 @@ func (fork *observerFork) Flush() {

// streamMetrics tracks the metrics for an individual stream.
type streamMetrics struct {
remoteSegments int64
remoteBytes int64
inlineSegments int64
inlineBytes int64
remoteSegments int64
remoteBytes int64
inlineSegments int64
inlineBytes int64
segmentsWithExpiresAt int64
}
28 changes: 15 additions & 13 deletions satellite/metrics/observer_test.go
Expand Up @@ -29,7 +29,7 @@ var (
{StreamID: uuid.UUID{3}, EncryptedSize: 16, Pieces: metabase.Pieces{{}}},
{StreamID: uuid.UUID{3}, EncryptedSize: 16, Pieces: metabase.Pieces{{}}},
{StreamID: uuid.UUID{3}, EncryptedSize: 16, Pieces: metabase.Pieces{{}}},
{StreamID: uuid.UUID{3}, EncryptedSize: 10},
{StreamID: uuid.UUID{3}, EncryptedSize: 10, ExpiresAt: &time.Time{}},
}
)

Expand All @@ -53,12 +53,13 @@ func TestObserver(t *testing.T) {
metrics := loop(t, obs, inline1, remote2, remote3)

require.Equal(t, Metrics{
InlineObjects: 1,
RemoteObjects: 2,
TotalInlineSegments: 3,
TotalRemoteSegments: 4,
TotalInlineBytes: 30,
TotalRemoteBytes: 64,
InlineObjects: 1,
RemoteObjects: 2,
TotalInlineSegments: 3,
TotalRemoteSegments: 4,
TotalInlineBytes: 30,
TotalRemoteBytes: 64,
TotalSegmentsWithExpiresAt: 1,
}, metrics)
})

Expand All @@ -71,12 +72,13 @@ func TestObserver(t *testing.T) {
metrics := loop(t, obs, remote3)

require.Equal(t, Metrics{
InlineObjects: 0,
RemoteObjects: 1,
TotalInlineSegments: 1,
TotalRemoteSegments: 3,
TotalInlineBytes: 10,
TotalRemoteBytes: 48,
InlineObjects: 0,
RemoteObjects: 1,
TotalInlineSegments: 1,
TotalRemoteSegments: 3,
TotalInlineBytes: 10,
TotalRemoteBytes: 48,
TotalSegmentsWithExpiresAt: 1,
}, metrics)
})

Expand Down

0 comments on commit c30b794

Please sign in to comment.