[#948] metrics: Set actual value for shard_id after restart

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2024-02-13 09:09:47 +03:00
parent 6a5769d1da
commit 0bd030507e
8 changed files with 27 additions and 1 deletions

View file

@ -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)
}

View file

@ -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())
}

View file

@ -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)

View file

@ -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) {}

View file

@ -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)

View file

@ -146,3 +146,7 @@ func (c *cache) Close() error {
c.metrics.Close()
return nil
}
func (c *cache) GetMetrics() Metrics {
return c.metrics
}

View file

@ -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) {}

View file

@ -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.