metrics: Set actual value for shard_id after node restart #978

Merged
dstepanov-yadro merged 2 commits from acid-ant/frostfs-node:bugfix/948-wrong-shard into master 2024-09-04 19:51:06 +00:00
9 changed files with 28 additions and 2 deletions

View file

@ -41,7 +41,7 @@ func newGenericWriteData(c FileCounter, perm fs.FileMode, noSync bool) writer {
fileGuard = utilSync.NewKeyLocker[string]() fileGuard = utilSync.NewKeyLocker[string]()
} }
var w = &genericWriter{ w := &genericWriter{
perm: perm, perm: perm,
flags: flags, flags: flags,

View file

@ -44,6 +44,10 @@ type gcMetrics struct {
shardID string shardID string
} }
func (m *gcMetrics) SetShardID(id string) {
m.shardID = id
}
func (m *gcMetrics) AddRunDuration(d time.Duration, success bool) { func (m *gcMetrics) AddRunDuration(d time.Duration, success bool) {
m.storage.AddRunDuration(m.shardID, d, success) m.storage.AddRunDuration(m.shardID, d, success)
} }

View file

@ -145,6 +145,10 @@ type writeCacheMetrics struct {
metrics metrics.WriteCacheMetrics metrics metrics.WriteCacheMetrics
} }
func (m *writeCacheMetrics) SetShardID(id string) {
m.shardID = id
}
func (m *writeCacheMetrics) Get(d time.Duration, success bool, st writecache.StorageType) { func (m *writeCacheMetrics) Get(d time.Duration, success bool, st writecache.StorageType) {
m.metrics.AddMethodDuration(m.shardID, "Get", success, d, st.String()) 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) s.gc.init(ctx)

View file

@ -81,6 +81,7 @@ const (
) )
type GCMectrics interface { type GCMectrics interface {
SetShardID(string)
AddRunDuration(d time.Duration, success bool) AddRunDuration(d time.Duration, success bool)
AddDeletedCount(deleted, failed uint64) AddDeletedCount(deleted, failed uint64)
AddExpiredObjectCollectionDuration(d time.Duration, success bool, objectType string) AddExpiredObjectCollectionDuration(d time.Duration, success bool, objectType string)
@ -89,6 +90,7 @@ type GCMectrics interface {
type noopGCMetrics struct{} type noopGCMetrics struct{}
func (m *noopGCMetrics) SetShardID(string) {}
func (m *noopGCMetrics) AddRunDuration(time.Duration, bool) {} func (m *noopGCMetrics) AddRunDuration(time.Duration, bool) {}
func (m *noopGCMetrics) AddDeletedCount(uint64, uint64) {} func (m *noopGCMetrics) AddDeletedCount(uint64, uint64) {}
func (m *noopGCMetrics) AddExpiredObjectCollectionDuration(time.Duration, bool, string) {} 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) s.info.ID = NewIDFromBytes(idFromMetabase)
} }
shardID := s.info.ID.String()
if s.cfg.metricsWriter != nil { 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.log = &logger.Logger{Logger: s.log.With(zap.Stringer("shard_id", s.info.ID))}
s.metaBase.SetLogger(s.log) s.metaBase.SetLogger(s.log)
s.blobStor.SetLogger(s.log) s.blobStor.SetLogger(s.log)

View file

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

View file

@ -19,6 +19,7 @@ const (
) )
type Metrics interface { type Metrics interface {
SetShardID(string)
Get(d time.Duration, success bool, st StorageType) Get(d time.Duration, success bool, st StorageType)
Delete(d time.Duration, success bool, st StorageType) Delete(d time.Duration, success bool, st StorageType)
Put(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{} type metricsStub struct{}
func (metricsStub) SetShardID(string) {}
func (metricsStub) Get(time.Duration, bool, StorageType) {} func (metricsStub) Get(time.Duration, bool, StorageType) {}
func (metricsStub) Delete(time.Duration, bool, StorageType) {} func (metricsStub) Delete(time.Duration, bool, StorageType) {}

View file

@ -41,6 +41,7 @@ type Cache interface {
Init() error Init() error
Open(ctx context.Context, mode mode.Mode) error Open(ctx context.Context, mode mode.Mode) error
Close() error Close() error
GetMetrics() Metrics
} }
// MainStorage is the interface of the underlying storage of Cache implementations. // MainStorage is the interface of the underlying storage of Cache implementations.