diff --git a/pkg/local_object_storage/engine/metrics.go b/pkg/local_object_storage/engine/metrics.go index e4117bb1..91dfa876 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 0eca018f..f30bce00 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 8d1007ff..408354b5 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 24c3a337..83be3259 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 b67fd59c..be474e0f 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 2ae62c46..fdba8d40 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 5eac0669..492e0973 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 69dfee95..112594ec 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.