From 37d3e495941b1606d279818a44eec590170bc58e Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Fri, 26 Apr 2024 19:11:42 +0300 Subject: [PATCH 1/3] [#1107] node: Fix gofumpt issues Signed-off-by: Alexander Chuprov --- pkg/services/tree/ape.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/services/tree/ape.go b/pkg/services/tree/ape.go index f58721509..76ec254f0 100644 --- a/pkg/services/tree/ape.go +++ b/pkg/services/tree/ape.go @@ -19,9 +19,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" ) -var ( - subjectNotFoundErrorMessage = "subject not found" -) +var subjectNotFoundErrorMessage = "subject not found" func (s *Service) checkAPE(container *core.Container, cid cid.ID, operation acl.Op, role acl.Role, publicKey *keys.PublicKey) error { namespace := "" -- 2.45.2 From 01baf41f9b5136aa59c44f8f344fd3013efda8b2 Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Sat, 27 Apr 2024 15:34:29 +0300 Subject: [PATCH 2/3] [#966] node: Refactor WriteCacheMetrics interface Grouping common fields of methods will enhance the readability of the interface. Signed-off-by: Alexander Chuprov --- pkg/local_object_storage/engine/writecache.go | 18 +++++++++--------- pkg/metrics/mode.go | 4 ++-- pkg/metrics/writecache.go | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/local_object_storage/engine/writecache.go b/pkg/local_object_storage/engine/writecache.go index f30bce00d..850e10d17 100644 --- a/pkg/local_object_storage/engine/writecache.go +++ b/pkg/local_object_storage/engine/writecache.go @@ -150,20 +150,20 @@ func (m *writeCacheMetrics) SetShardID(id string) { } 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, st.String(), "Get", success, d) } func (m *writeCacheMetrics) Delete(d time.Duration, success bool, st writecache.StorageType) { - m.metrics.AddMethodDuration(m.shardID, "Delete", success, d, st.String()) + m.metrics.AddMethodDuration(m.shardID, st.String(), "Delete", success, d) } func (m *writeCacheMetrics) Put(d time.Duration, success bool, st writecache.StorageType) { - m.metrics.AddMethodDuration(m.shardID, "Put", success, d, st.String()) + m.metrics.AddMethodDuration(m.shardID, st.String(), "Put", success, d) } func (m *writeCacheMetrics) SetEstimateSize(db, fstree uint64) { - m.metrics.SetEstimateSize(m.shardID, db, writecache.StorageTypeDB.String()) - m.metrics.SetEstimateSize(m.shardID, fstree, writecache.StorageTypeFSTree.String()) + m.metrics.SetEstimateSize(m.shardID, writecache.StorageTypeDB.String(), db) + m.metrics.SetEstimateSize(m.shardID, writecache.StorageTypeFSTree.String(), fstree) } func (m *writeCacheMetrics) SetMode(mode mode.Mode) { @@ -171,16 +171,16 @@ func (m *writeCacheMetrics) SetMode(mode mode.Mode) { } func (m *writeCacheMetrics) SetActualCounters(db, fstree uint64) { - m.metrics.SetActualCount(m.shardID, db, writecache.StorageTypeDB.String()) - m.metrics.SetActualCount(m.shardID, fstree, writecache.StorageTypeFSTree.String()) + m.metrics.SetActualCount(m.shardID, writecache.StorageTypeDB.String(), db) + m.metrics.SetActualCount(m.shardID, writecache.StorageTypeFSTree.String(), fstree) } func (m *writeCacheMetrics) Flush(success bool, st writecache.StorageType) { - m.metrics.IncOperationCounter(m.shardID, "Flush", metrics.NullBool{Bool: success, Valid: true}, st.String()) + m.metrics.IncOperationCounter(m.shardID, st.String(), "Flush", metrics.NullBool{Bool: success, Valid: true}) } func (m *writeCacheMetrics) Evict(st writecache.StorageType) { - m.metrics.IncOperationCounter(m.shardID, "Evict", metrics.NullBool{}, st.String()) + m.metrics.IncOperationCounter(m.shardID, st.String(), "Evict", metrics.NullBool{}) } func (m *writeCacheMetrics) Close() { diff --git a/pkg/metrics/mode.go b/pkg/metrics/mode.go index cf6bdac48..a9ac47acd 100644 --- a/pkg/metrics/mode.go +++ b/pkg/metrics/mode.go @@ -21,7 +21,7 @@ func newShardIDMode(subsystem, name, help string) *shardIDModeValue { } } -func (m *shardIDModeValue) SetMode(shardID string, mode string) { +func (m *shardIDModeValue) SetMode(shardID, mode string) { m.modeValue.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, }) @@ -54,7 +54,7 @@ func newShardIDPathMode(subsystem, name, help string) *shardIDPathModeValue { } } -func (m *shardIDPathModeValue) SetMode(shardID, path string, mode string) { +func (m *shardIDPathModeValue) SetMode(shardID, path, mode string) { m.modeValue.DeletePartialMatch(prometheus.Labels{ shardIDLabel: shardID, pathLabel: path, diff --git a/pkg/metrics/writecache.go b/pkg/metrics/writecache.go index ea3d8742a..70181ee2b 100644 --- a/pkg/metrics/writecache.go +++ b/pkg/metrics/writecache.go @@ -9,11 +9,11 @@ import ( ) type WriteCacheMetrics interface { - AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) - SetActualCount(shardID string, count uint64, storageType string) - SetEstimateSize(shardID string, size uint64, storageType string) - SetMode(shardID string, mode string) - IncOperationCounter(shardID string, operation string, success NullBool, storageType string) + AddMethodDuration(shardID, storageType, method string, success bool, d time.Duration) + SetActualCount(shardID, storageType string, count uint64) + SetEstimateSize(shardID, storageType string, size uint64) + SetMode(shardID, mode string) + IncOperationCounter(shardID, storageType, operation string, success NullBool) Close(shardID string) } @@ -48,7 +48,7 @@ func newWriteCacheMetrics() *writeCacheMetrics { } } -func (m *writeCacheMetrics) AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) { +func (m *writeCacheMetrics) AddMethodDuration(shardID, storageType, method string, success bool, d time.Duration) { m.methodDuration.With( prometheus.Labels{ shardIDLabel: shardID, @@ -59,14 +59,14 @@ func (m *writeCacheMetrics) AddMethodDuration(shardID string, method string, suc ).Observe(d.Seconds()) } -func (m *writeCacheMetrics) SetActualCount(shardID string, count uint64, storageType string) { +func (m *writeCacheMetrics) SetActualCount(shardID, storageType string, count uint64) { m.actualCount.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, }).Set(float64(count)) } -func (m *writeCacheMetrics) SetEstimateSize(shardID string, size uint64, storageType string) { +func (m *writeCacheMetrics) SetEstimateSize(shardID, storageType string, size uint64) { m.estimatedSize.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, @@ -77,7 +77,7 @@ func (m *writeCacheMetrics) SetMode(shardID string, mode string) { m.mode.SetMode(shardID, mode) } -func (m *writeCacheMetrics) IncOperationCounter(shardID string, operation string, success NullBool, storageType string) { +func (m *writeCacheMetrics) IncOperationCounter(shardID, storageType, operation string, success NullBool) { m.operationCounter.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, -- 2.45.2 From fa0bc8e1df41c93abf6ee385976eda16b93df10d Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Sat, 27 Apr 2024 15:49:07 +0300 Subject: [PATCH 3/3] [#966] node: Add path of the write_cache to metric labels Signed-off-by: Alexander Chuprov --- pkg/local_object_storage/engine/writecache.go | 25 +++++++----- pkg/local_object_storage/shard/shard.go | 1 + .../writecache/metrics.go | 3 ++ pkg/metrics/writecache.go | 38 ++++++++++--------- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/pkg/local_object_storage/engine/writecache.go b/pkg/local_object_storage/engine/writecache.go index 850e10d17..670cfcbf5 100644 --- a/pkg/local_object_storage/engine/writecache.go +++ b/pkg/local_object_storage/engine/writecache.go @@ -143,6 +143,11 @@ func (e *StorageEngine) SealWriteCache(ctx context.Context, prm SealWriteCachePr type writeCacheMetrics struct { shardID string metrics metrics.WriteCacheMetrics + path string +} + +func (m *writeCacheMetrics) SetPath(path string) { + m.path = path } func (m *writeCacheMetrics) SetShardID(id string) { @@ -150,20 +155,20 @@ func (m *writeCacheMetrics) SetShardID(id string) { } func (m *writeCacheMetrics) Get(d time.Duration, success bool, st writecache.StorageType) { - m.metrics.AddMethodDuration(m.shardID, st.String(), "Get", success, d) + m.metrics.AddMethodDuration(m.shardID, m.path, st.String(), "Get", success, d) } func (m *writeCacheMetrics) Delete(d time.Duration, success bool, st writecache.StorageType) { - m.metrics.AddMethodDuration(m.shardID, st.String(), "Delete", success, d) + m.metrics.AddMethodDuration(m.shardID, m.path, st.String(), "Delete", success, d) } func (m *writeCacheMetrics) Put(d time.Duration, success bool, st writecache.StorageType) { - m.metrics.AddMethodDuration(m.shardID, st.String(), "Put", success, d) + m.metrics.AddMethodDuration(m.shardID, m.path, st.String(), "Put", success, d) } func (m *writeCacheMetrics) SetEstimateSize(db, fstree uint64) { - m.metrics.SetEstimateSize(m.shardID, writecache.StorageTypeDB.String(), db) - m.metrics.SetEstimateSize(m.shardID, writecache.StorageTypeFSTree.String(), fstree) + m.metrics.SetEstimateSize(m.shardID, m.path, writecache.StorageTypeDB.String(), db) + m.metrics.SetEstimateSize(m.shardID, m.path, writecache.StorageTypeFSTree.String(), fstree) } func (m *writeCacheMetrics) SetMode(mode mode.Mode) { @@ -171,18 +176,18 @@ func (m *writeCacheMetrics) SetMode(mode mode.Mode) { } func (m *writeCacheMetrics) SetActualCounters(db, fstree uint64) { - m.metrics.SetActualCount(m.shardID, writecache.StorageTypeDB.String(), db) - m.metrics.SetActualCount(m.shardID, writecache.StorageTypeFSTree.String(), fstree) + m.metrics.SetActualCount(m.shardID, m.path, writecache.StorageTypeDB.String(), db) + m.metrics.SetActualCount(m.shardID, m.path, writecache.StorageTypeFSTree.String(), fstree) } func (m *writeCacheMetrics) Flush(success bool, st writecache.StorageType) { - m.metrics.IncOperationCounter(m.shardID, st.String(), "Flush", metrics.NullBool{Bool: success, Valid: true}) + m.metrics.IncOperationCounter(m.shardID, m.path, st.String(), "Flush", metrics.NullBool{Bool: success, Valid: true}) } func (m *writeCacheMetrics) Evict(st writecache.StorageType) { - m.metrics.IncOperationCounter(m.shardID, st.String(), "Evict", metrics.NullBool{}) + m.metrics.IncOperationCounter(m.shardID, m.path, st.String(), "Evict", metrics.NullBool{}) } func (m *writeCacheMetrics) Close() { - m.metrics.Close(m.shardID) + m.metrics.Close(m.shardID, m.path) } diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index d9cd2b2f4..cf59c0bfc 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -182,6 +182,7 @@ func New(opts ...Option) *Shard { writecache.WithReportErrorFunc(reportFunc), writecache.WithBlobstor(bs), writecache.WithMetabase(mb))...) + s.writeCache.GetMetrics().SetPath(s.writeCache.DumpInfo().Path) } if s.piloramaOpts != nil { diff --git a/pkg/local_object_storage/writecache/metrics.go b/pkg/local_object_storage/writecache/metrics.go index 492e0973a..962e22eea 100644 --- a/pkg/local_object_storage/writecache/metrics.go +++ b/pkg/local_object_storage/writecache/metrics.go @@ -29,6 +29,7 @@ type Metrics interface { SetEstimateSize(db, fstree uint64) SetMode(m mode.Mode) SetActualCounters(db, fstree uint64) + SetPath(path string) Close() } @@ -38,6 +39,8 @@ type metricsStub struct{} func (metricsStub) SetShardID(string) {} +func (metricsStub) SetPath(string) {} + func (metricsStub) Get(time.Duration, bool, StorageType) {} func (metricsStub) Delete(time.Duration, bool, StorageType) {} diff --git a/pkg/metrics/writecache.go b/pkg/metrics/writecache.go index 70181ee2b..2fe01526e 100644 --- a/pkg/metrics/writecache.go +++ b/pkg/metrics/writecache.go @@ -9,12 +9,12 @@ import ( ) type WriteCacheMetrics interface { - AddMethodDuration(shardID, storageType, method string, success bool, d time.Duration) - SetActualCount(shardID, storageType string, count uint64) - SetEstimateSize(shardID, storageType string, size uint64) + AddMethodDuration(shardID, path, storageType, method string, success bool, d time.Duration) + SetActualCount(shardID, path, storageType string, count uint64) + SetEstimateSize(shardID, path, storageType string, size uint64) SetMode(shardID, mode string) - IncOperationCounter(shardID, storageType, operation string, success NullBool) - Close(shardID string) + IncOperationCounter(shardID, path, storageType, operation string, success NullBool) + Close(shardID, path string) } type writeCacheMetrics struct { @@ -41,35 +41,38 @@ func newWriteCacheMetrics() *writeCacheMetrics { Subsystem: writeCacheSubsystem, Name: "operations_total", Help: "The number of writecache operations processed", - }, []string{shardIDLabel, storageLabel, successLabel, operationLabel}), - actualCount: newWCGaugeVec("actual_objects_total", "Actual objects count in writecache", []string{shardIDLabel, storageLabel}), - estimatedSize: newWCGaugeVec("estimated_size_bytes", "Estimated writecache size", []string{shardIDLabel, storageLabel}), + }, []string{shardIDLabel, storageLabel, successLabel, operationLabel, pathLabel}), + actualCount: newWCGaugeVec("actual_objects_total", "Actual objects count in writecache", []string{shardIDLabel, storageLabel, pathLabel}), + estimatedSize: newWCGaugeVec("estimated_size_bytes", "Estimated writecache size", []string{shardIDLabel, storageLabel, pathLabel}), mode: newShardIDMode(writeCacheSubsystem, "mode_info", "Writecache mode value"), } } -func (m *writeCacheMetrics) AddMethodDuration(shardID, storageType, method string, success bool, d time.Duration) { +func (m *writeCacheMetrics) AddMethodDuration(shardID, path, storageType, method string, success bool, d time.Duration) { m.methodDuration.With( prometheus.Labels{ shardIDLabel: shardID, successLabel: strconv.FormatBool(success), storageLabel: storageType, methodLabel: method, + pathLabel: path, }, ).Observe(d.Seconds()) } -func (m *writeCacheMetrics) SetActualCount(shardID, storageType string, count uint64) { +func (m *writeCacheMetrics) SetActualCount(shardID, path, storageType string, count uint64) { m.actualCount.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, + pathLabel: path, }).Set(float64(count)) } -func (m *writeCacheMetrics) SetEstimateSize(shardID, storageType string, size uint64) { +func (m *writeCacheMetrics) SetEstimateSize(shardID, path, storageType string, size uint64) { m.estimatedSize.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, + pathLabel: path, }).Set(float64(size)) } @@ -77,21 +80,22 @@ func (m *writeCacheMetrics) SetMode(shardID string, mode string) { m.mode.SetMode(shardID, mode) } -func (m *writeCacheMetrics) IncOperationCounter(shardID, storageType, operation string, success NullBool) { +func (m *writeCacheMetrics) IncOperationCounter(shardID, path, storageType, operation string, success NullBool) { m.operationCounter.With(prometheus.Labels{ shardIDLabel: shardID, storageLabel: storageType, operationLabel: operation, successLabel: success.String(), + pathLabel: path, }).Inc() } -func (m *writeCacheMetrics) Close(shardID string) { +func (m *writeCacheMetrics) Close(shardID, path string) { m.mode.Delete(shardID) - m.methodDuration.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID}) - m.operationCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID}) - m.actualCount.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID}) - m.estimatedSize.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID}) + m.methodDuration.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path}) + m.operationCounter.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path}) + m.actualCount.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path}) + m.estimatedSize.DeletePartialMatch(prometheus.Labels{shardIDLabel: shardID, pathLabel: path}) } func newWCGaugeVec(name, help string, labels []string) *prometheus.GaugeVec { -- 2.45.2