[#948] metrics: Set actual value for shard_id after restart
All checks were successful
DCO action / DCO (pull_request) Successful in 2m26s
Vulncheck / Vulncheck (pull_request) Successful in 3m56s
Tests and linters / Staticcheck (pull_request) Successful in 4m18s
Build / Build Components (1.21) (pull_request) Successful in 4m11s
Build / Build Components (1.20) (pull_request) Successful in 4m19s
Tests and linters / Lint (pull_request) Successful in 6m3s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m7s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m26s
Tests and linters / Tests with -race (pull_request) Successful in 9m20s

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