From 0bd030507ef7f0d6a47a8f310d3de03804a8d416 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 13 Feb 2024 09:09:47 +0300 Subject: [PATCH] [#948] metrics: Set actual value for `shard_id` after restart Signed-off-by: Anton Nikiforov --- pkg/local_object_storage/engine/metrics.go | 4 ++++ pkg/local_object_storage/engine/writecache.go | 4 ++++ pkg/local_object_storage/shard/control.go | 3 +++ pkg/local_object_storage/shard/gc.go | 2 ++ pkg/local_object_storage/shard/id.go | 7 ++++++- pkg/local_object_storage/writecache/cachebbolt.go | 4 ++++ pkg/local_object_storage/writecache/metrics.go | 3 +++ pkg/local_object_storage/writecache/writecache.go | 1 + 8 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/engine/metrics.go b/pkg/local_object_storage/engine/metrics.go index e4117bb1a..91dfa8762 100644 --- a/pkg/local_object_storage/engine/metrics.go +++ b/pkg/local_object_storage/engine/metrics.go @@ -44,6 +44,10 @@ type gcMetrics struct { shardID string } +func (m *gcMetrics) SetShardID(id string) { + m.shardID = id +} + func (m *gcMetrics) AddRunDuration(d time.Duration, success bool) { m.storage.AddRunDuration(m.shardID, d, success) } diff --git a/pkg/local_object_storage/engine/writecache.go b/pkg/local_object_storage/engine/writecache.go index 0eca018f8..f30bce00d 100644 --- a/pkg/local_object_storage/engine/writecache.go +++ b/pkg/local_object_storage/engine/writecache.go @@ -145,6 +145,10 @@ type writeCacheMetrics struct { metrics metrics.WriteCacheMetrics } +func (m *writeCacheMetrics) SetShardID(id string) { + m.shardID = id +} + func (m *writeCacheMetrics) Get(d time.Duration, success bool, st writecache.StorageType) { m.metrics.AddMethodDuration(m.shardID, "Get", success, d, st.String()) } diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 8d1007ffd..408354b55 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -166,6 +166,9 @@ func (s *Shard) Init(ctx context.Context) error { }, }, } + if s.gc.metrics != nil { + s.gc.metrics.SetShardID(s.info.ID.String()) + } s.gc.init(ctx) diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index 24c3a337a..83be3259a 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -81,6 +81,7 @@ const ( ) type GCMectrics interface { + SetShardID(string) AddRunDuration(d time.Duration, success bool) AddDeletedCount(deleted, failed uint64) AddExpiredObjectCollectionDuration(d time.Duration, success bool, objectType string) @@ -89,6 +90,7 @@ type GCMectrics interface { type noopGCMetrics struct{} +func (m *noopGCMetrics) SetShardID(string) {} func (m *noopGCMetrics) AddRunDuration(time.Duration, bool) {} func (m *noopGCMetrics) AddDeletedCount(uint64, uint64) {} func (m *noopGCMetrics) AddExpiredObjectCollectionDuration(time.Duration, bool, string) {} diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go index b67fd59cd..be474e0fa 100644 --- a/pkg/local_object_storage/shard/id.go +++ b/pkg/local_object_storage/shard/id.go @@ -53,9 +53,14 @@ func (s *Shard) UpdateID(ctx context.Context) (err error) { s.info.ID = NewIDFromBytes(idFromMetabase) } + shardID := s.info.ID.String() if s.cfg.metricsWriter != nil { - s.cfg.metricsWriter.SetShardID(s.info.ID.String()) + s.cfg.metricsWriter.SetShardID(shardID) } + if s.writeCache != nil && s.writeCache.GetMetrics() != nil { + s.writeCache.GetMetrics().SetShardID(shardID) + } + s.log = &logger.Logger{Logger: s.log.With(zap.Stringer("shard_id", s.info.ID))} s.metaBase.SetLogger(s.log) s.blobStor.SetLogger(s.log) diff --git a/pkg/local_object_storage/writecache/cachebbolt.go b/pkg/local_object_storage/writecache/cachebbolt.go index 2ae62c461..fdba8d409 100644 --- a/pkg/local_object_storage/writecache/cachebbolt.go +++ b/pkg/local_object_storage/writecache/cachebbolt.go @@ -146,3 +146,7 @@ func (c *cache) Close() error { c.metrics.Close() return nil } + +func (c *cache) GetMetrics() Metrics { + return c.metrics +} diff --git a/pkg/local_object_storage/writecache/metrics.go b/pkg/local_object_storage/writecache/metrics.go index 5eac06698..492e0973a 100644 --- a/pkg/local_object_storage/writecache/metrics.go +++ b/pkg/local_object_storage/writecache/metrics.go @@ -19,6 +19,7 @@ const ( ) type Metrics interface { + SetShardID(string) Get(d time.Duration, success bool, st StorageType) Delete(d time.Duration, success bool, st StorageType) Put(d time.Duration, success bool, st StorageType) @@ -35,6 +36,8 @@ func DefaultMetrics() Metrics { return metricsStub{} } type metricsStub struct{} +func (metricsStub) SetShardID(string) {} + func (metricsStub) Get(time.Duration, bool, StorageType) {} func (metricsStub) Delete(time.Duration, bool, StorageType) {} diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 69dfee953..112594ec0 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -41,6 +41,7 @@ type Cache interface { Init() error Open(ctx context.Context, mode mode.Mode) error Close() error + GetMetrics() Metrics } // MainStorage is the interface of the underlying storage of Cache implementations.