From d8ecc69d0091db029cb976456b8e923d332e1102 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 7 Jun 2023 14:39:03 +0300 Subject: [PATCH] [#373] local storage: Pass parent ID This is required to add shard ID as metric label. Signed-off-by: Dmitrii Stepanov --- .../blobstor/blobovniczatree/blobovnicza.go | 4 ++++ .../blobstor/blobovniczatree/metrics.go | 3 +++ pkg/local_object_storage/blobstor/blobstor.go | 7 +++++++ pkg/local_object_storage/blobstor/common/storage.go | 1 + pkg/local_object_storage/blobstor/fstree/fstree.go | 4 ++++ pkg/local_object_storage/blobstor/fstree/metrics.go | 3 +++ pkg/local_object_storage/blobstor/memstore/control.go | 1 + pkg/local_object_storage/blobstor/metrics.go | 2 ++ pkg/local_object_storage/blobstor/teststore/teststore.go | 2 ++ pkg/local_object_storage/metabase/db.go | 5 +++++ pkg/local_object_storage/metabase/metrics.go | 3 +++ pkg/local_object_storage/pilorama/boltdb.go | 4 ++++ pkg/local_object_storage/pilorama/forest.go | 1 + pkg/local_object_storage/pilorama/interface.go | 1 + pkg/local_object_storage/pilorama/metrics.go | 3 +++ pkg/local_object_storage/shard/id.go | 3 +++ 16 files changed, 47 insertions(+) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go index d99e9aa8..1b0af342 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/blobovnicza.go @@ -256,3 +256,7 @@ func (b *Blobovniczas) SetCompressor(cc *compression.Config) { func (b *Blobovniczas) SetReportErrorFunc(f func(string, error)) { b.reportError = f } + +func (b *Blobovniczas) SetParentID(parentID string) { + b.metrics.SetParentID(parentID) +} diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/metrics.go b/pkg/local_object_storage/blobstor/blobovniczatree/metrics.go index ffa3c8a8..39fe34e2 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/metrics.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/metrics.go @@ -9,6 +9,8 @@ import ( type Metrics interface { BlobovnicaMetrics(path string) blobovnicza.Metrics + SetParentID(parentID string) + SetMode(readOnly bool) Close() @@ -25,6 +27,7 @@ type noopMetrics struct{} func (m *noopMetrics) BlobovnicaMetrics(string) blobovnicza.Metrics { return &blobovnicza.NoopMetrics{} } +func (m *noopMetrics) SetParentID(string) {} func (m *noopMetrics) SetMode(bool) {} func (m *noopMetrics) Close() {} func (m *noopMetrics) Delete(time.Duration, bool, bool) {} diff --git a/pkg/local_object_storage/blobstor/blobstor.go b/pkg/local_object_storage/blobstor/blobstor.go index a422b2bc..6c6aed87 100644 --- a/pkg/local_object_storage/blobstor/blobstor.go +++ b/pkg/local_object_storage/blobstor/blobstor.go @@ -72,6 +72,13 @@ func (b *BlobStor) SetLogger(l *logger.Logger) { b.log = l } +func (b *BlobStor) SetParentID(parentID string) { + b.metrics.SetParentID(parentID) + for _, ss := range b.storage { + ss.Storage.SetParentID(parentID) + } +} + // WithStorages provides sub-blobstors. func WithStorages(st []SubStorage) Option { return func(c *cfg) { diff --git a/pkg/local_object_storage/blobstor/common/storage.go b/pkg/local_object_storage/blobstor/common/storage.go index c5d187f3..b808480e 100644 --- a/pkg/local_object_storage/blobstor/common/storage.go +++ b/pkg/local_object_storage/blobstor/common/storage.go @@ -19,6 +19,7 @@ type Storage interface { // SetReportErrorFunc allows to provide a function to be called on disk errors. // This function MUST be called before Open. SetReportErrorFunc(f func(string, error)) + SetParentID(parentID string) Get(context.Context, GetPrm) (GetRes, error) GetRange(context.Context, GetRangePrm) (GetRangeRes, error) diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index 645d4e5f..9ca5d4bd 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -554,3 +554,7 @@ func (t *FSTree) SetCompressor(cc *compression.Config) { func (t *FSTree) SetReportErrorFunc(_ func(string, error)) { // Do nothing, FSTree can encounter only one error which is returned. } + +func (t *FSTree) SetParentID(parentID string) { + t.metrics.SetParentID(parentID) +} diff --git a/pkg/local_object_storage/blobstor/fstree/metrics.go b/pkg/local_object_storage/blobstor/fstree/metrics.go index 04386d9b..ca6a5497 100644 --- a/pkg/local_object_storage/blobstor/fstree/metrics.go +++ b/pkg/local_object_storage/blobstor/fstree/metrics.go @@ -3,6 +3,8 @@ package fstree import "time" type Metrics interface { + SetParentID(parentID string) + SetMode(readOnly bool) Close() @@ -16,6 +18,7 @@ type Metrics interface { type noopMetrics struct{} +func (m *noopMetrics) SetParentID(string) {} func (m *noopMetrics) SetMode(bool) {} func (m *noopMetrics) Close() {} func (m *noopMetrics) Iterate(time.Duration, bool) {} diff --git a/pkg/local_object_storage/blobstor/memstore/control.go b/pkg/local_object_storage/blobstor/memstore/control.go index 4deb9f6e..e6943626 100644 --- a/pkg/local_object_storage/blobstor/memstore/control.go +++ b/pkg/local_object_storage/blobstor/memstore/control.go @@ -13,3 +13,4 @@ func (s *memstoreImpl) Type() string { return Type } func (s *memstoreImpl) Path() string { return s.rootPath } func (s *memstoreImpl) SetCompressor(cc *compression.Config) { s.compression = cc } func (s *memstoreImpl) SetReportErrorFunc(f func(string, error)) { s.reportError = f } +func (s *memstoreImpl) SetParentID(string) {} diff --git a/pkg/local_object_storage/blobstor/metrics.go b/pkg/local_object_storage/blobstor/metrics.go index 4fd6f3e5..4a7b4009 100644 --- a/pkg/local_object_storage/blobstor/metrics.go +++ b/pkg/local_object_storage/blobstor/metrics.go @@ -3,6 +3,7 @@ package blobstor import "time" type Metrics interface { + SetParentID(parentID string) SetMode(readOnly bool) Close() @@ -16,6 +17,7 @@ type Metrics interface { type noopMetrics struct{} +func (m *noopMetrics) SetParentID(string) {} func (m *noopMetrics) SetMode(bool) {} func (m *noopMetrics) Close() {} func (m *noopMetrics) Delete(time.Duration, bool, bool) {} diff --git a/pkg/local_object_storage/blobstor/teststore/teststore.go b/pkg/local_object_storage/blobstor/teststore/teststore.go index c7179eb4..2508d74f 100644 --- a/pkg/local_object_storage/blobstor/teststore/teststore.go +++ b/pkg/local_object_storage/blobstor/teststore/teststore.go @@ -214,3 +214,5 @@ func (s *TestStore) Iterate(ctx context.Context, req common.IteratePrm) (common. panic(fmt.Sprintf("unexpected storage call: Iterate(%+v)", req)) } } + +func (s *TestStore) SetParentID(string) {} diff --git a/pkg/local_object_storage/metabase/db.go b/pkg/local_object_storage/metabase/db.go index c54ed98d..33f27211 100644 --- a/pkg/local_object_storage/metabase/db.go +++ b/pkg/local_object_storage/metabase/db.go @@ -294,6 +294,11 @@ func (db *DB) SetLogger(l *logger.Logger) { db.log = l } +// SetParentID sets parent ID to nested components. It is used after the shard ID was generated to use it in logs. +func (db *DB) SetParentID(parentID string) { + db.metrics.SetParentID(parentID) +} + // WithLogger returns option to set logger of DB. func WithLogger(l *logger.Logger) Option { return func(c *cfg) { diff --git a/pkg/local_object_storage/metabase/metrics.go b/pkg/local_object_storage/metabase/metrics.go index 120579e4..fc971bd8 100644 --- a/pkg/local_object_storage/metabase/metrics.go +++ b/pkg/local_object_storage/metabase/metrics.go @@ -7,6 +7,8 @@ import ( ) type Metrics interface { + SetParentID(parentID string) + SetMode(m mode.Mode) Close() @@ -15,6 +17,7 @@ type Metrics interface { type noopMetrics struct{} +func (m *noopMetrics) SetParentID(string) {} func (m *noopMetrics) SetMode(mode.Mode) {} func (m *noopMetrics) Close() {} func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {} diff --git a/pkg/local_object_storage/pilorama/boltdb.go b/pkg/local_object_storage/pilorama/boltdb.go index 1b8ee7f1..a1956113 100644 --- a/pkg/local_object_storage/pilorama/boltdb.go +++ b/pkg/local_object_storage/pilorama/boltdb.go @@ -158,6 +158,10 @@ func (t *boltForest) Close() error { return err } +func (t *boltForest) SetParentID(id string) { + t.metrics.SetParentID(id) +} + // TreeMove implements the Forest interface. func (t *boltForest) TreeMove(ctx context.Context, d CIDDescriptor, treeID string, m *Move) (*Move, error) { _, span := tracing.StartSpanFromContext(ctx, "boltForest.TreeMove", diff --git a/pkg/local_object_storage/pilorama/forest.go b/pkg/local_object_storage/pilorama/forest.go index 7c5897ed..76220c1d 100644 --- a/pkg/local_object_storage/pilorama/forest.go +++ b/pkg/local_object_storage/pilorama/forest.go @@ -119,6 +119,7 @@ func (f *memoryForest) SetMode(mode.Mode) error { func (f *memoryForest) Close() error { return nil } +func (f *memoryForest) SetParentID(string) {} // TreeGetByPath implements the Forest interface. func (f *memoryForest) TreeGetByPath(_ context.Context, cid cid.ID, treeID string, attr string, path []string, latest bool) ([]Node, error) { diff --git a/pkg/local_object_storage/pilorama/interface.go b/pkg/local_object_storage/pilorama/interface.go index c8287c6d..89c75262 100644 --- a/pkg/local_object_storage/pilorama/interface.go +++ b/pkg/local_object_storage/pilorama/interface.go @@ -61,6 +61,7 @@ type ForestStorage interface { Open(bool) error Close() error SetMode(m mode.Mode) error + SetParentID(id string) Forest } diff --git a/pkg/local_object_storage/pilorama/metrics.go b/pkg/local_object_storage/pilorama/metrics.go index 8b113eaa..543ad3e3 100644 --- a/pkg/local_object_storage/pilorama/metrics.go +++ b/pkg/local_object_storage/pilorama/metrics.go @@ -7,6 +7,8 @@ import ( ) type Metrics interface { + SetParentID(id string) + SetMode(m mode.Mode) Close() @@ -15,6 +17,7 @@ type Metrics interface { type noopMetrics struct{} +func (m *noopMetrics) SetParentID(string) {} func (m *noopMetrics) SetMode(mode.Mode) {} func (m *noopMetrics) Close() {} func (m *noopMetrics) AddMethodDuration(string, time.Duration, bool) {} diff --git a/pkg/local_object_storage/shard/id.go b/pkg/local_object_storage/shard/id.go index 992a86c0..4f6fd065 100644 --- a/pkg/local_object_storage/shard/id.go +++ b/pkg/local_object_storage/shard/id.go @@ -55,6 +55,9 @@ func (s *Shard) UpdateID() (err error) { if s.hasWriteCache() { s.writeCache.SetLogger(s.log) } + s.metaBase.SetParentID(s.info.ID.String()) + s.blobStor.SetParentID(s.info.ID.String()) + s.pilorama.SetParentID(s.info.ID.String()) if len(id) != 0 { return nil