From c30b7941758715f44f8edddd9155a70caca04a72 Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Wed, 3 Jan 2024 14:22:30 +0100 Subject: [PATCH] satellite/metrics: add metric of total segments with expiration set Change-Id: I87c2c9ca0aff94492bab69489bdf4ea2f82de019 --- monkit.lock | 1 + satellite/metrics/metrics.go | 4 ++++ satellite/metrics/observer.go | 15 +++++++++++---- satellite/metrics/observer_test.go | 28 +++++++++++++++------------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/monkit.lock b/monkit.lock index d794ff0e0db1..1c8425f5c99f 100644 --- a/monkit.lock +++ b/monkit.lock @@ -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 diff --git a/satellite/metrics/metrics.go b/satellite/metrics/metrics.go index b5c985d53afb..5a270339602d 100644 --- a/satellite/metrics/metrics.go +++ b/satellite/metrics/metrics.go @@ -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. @@ -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 } diff --git a/satellite/metrics/observer.go b/satellite/metrics/observer.go index 1b8da1e97770..3a0a2df97437 100644 --- a/satellite/metrics/observer.go +++ b/satellite/metrics/observer.go @@ -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 } @@ -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 } @@ -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. @@ -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 } diff --git a/satellite/metrics/observer_test.go b/satellite/metrics/observer_test.go index f0c8a7d417a7..4de758309c88 100644 --- a/satellite/metrics/observer_test.go +++ b/satellite/metrics/observer_test.go @@ -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{}}, } ) @@ -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) }) @@ -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) })