[#1410] engine: Provide the default implementation to MetricsRegister
All checks were successful
DCO action / DCO (pull_request) Successful in 1m6s
Tests and linters / Run gofumpt (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m9s
Vulncheck / Vulncheck (pull_request) Successful in 2m16s
Build / Build Components (pull_request) Successful in 2m40s
Tests and linters / gopls check (pull_request) Successful in 2m53s
Tests and linters / Staticcheck (pull_request) Successful in 3m11s
Tests and linters / Lint (pull_request) Successful in 3m42s
Tests and linters / Tests (pull_request) Successful in 4m29s
Tests and linters / Tests with -race (pull_request) Successful in 6m13s

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-10-03 10:40:56 +03:00
parent 82674c0439
commit 906f3edfaa
11 changed files with 77 additions and 55 deletions

View file

@ -68,9 +68,7 @@ func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) {
} }
func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) { func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRes, err error) {
if e.metrics != nil { defer elapsed("EstimateContainerSize", e.metrics.AddMethodDuration)()
defer elapsed("EstimateContainerSize", e.metrics.AddMethodDuration)()
}
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
var csPrm shard.ContainerSizePrm var csPrm shard.ContainerSizePrm
@ -116,9 +114,7 @@ func ListContainers(ctx context.Context, e *StorageEngine) ([]cid.ID, error) {
} }
func (e *StorageEngine) listContainers(ctx context.Context) (ListContainersRes, error) { func (e *StorageEngine) listContainers(ctx context.Context) (ListContainersRes, error) {
if e.metrics != nil { defer elapsed("ListContainers", e.metrics.AddMethodDuration)()
defer elapsed("ListContainers", e.metrics.AddMethodDuration)()
}
uniqueIDs := make(map[string]cid.ID) uniqueIDs := make(map[string]cid.ID)

View file

@ -68,9 +68,7 @@ func (e *StorageEngine) Delete(ctx context.Context, prm DeletePrm) (res DeleteRe
} }
func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) { func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, error) {
if e.metrics != nil { defer elapsed("Delete", e.metrics.AddMethodDuration)()
defer elapsed("Delete", e.metrics.AddMethodDuration)()
}
var locked struct { var locked struct {
is bool is bool

View file

@ -219,6 +219,7 @@ func defaultCfg() *cfg {
res := &cfg{ res := &cfg{
log: &logger.Logger{Logger: zap.L()}, log: &logger.Logger{Logger: zap.L()},
shardPoolSize: 20, shardPoolSize: 20,
metrics: noopMetrics{},
} }
res.containerSource.Store(&containerSource{}) res.containerSource.Store(&containerSource{})
return res return res

View file

@ -66,9 +66,7 @@ func (e *StorageEngine) Get(ctx context.Context, prm GetPrm) (res GetRes, err er
} }
func (e *StorageEngine) get(ctx context.Context, prm GetPrm) (GetRes, error) { func (e *StorageEngine) get(ctx context.Context, prm GetPrm) (GetRes, error) {
if e.metrics != nil { defer elapsed("Get", e.metrics.AddMethodDuration)()
defer elapsed("Get", e.metrics.AddMethodDuration)()
}
errNotFound := new(apistatus.ObjectNotFound) errNotFound := new(apistatus.ObjectNotFound)

View file

@ -68,9 +68,7 @@ func (e *StorageEngine) Head(ctx context.Context, prm HeadPrm) (res HeadRes, err
func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) { func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) {
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head") ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head")
defer span.End() defer span.End()
if e.metrics != nil { defer elapsed("Head", e.metrics.AddMethodDuration)()
defer elapsed("Head", e.metrics.AddMethodDuration)()
}
var ( var (
head *objectSDK.Object head *objectSDK.Object

View file

@ -80,9 +80,7 @@ func (e *StorageEngine) Inhume(ctx context.Context, prm InhumePrm) (res InhumeRe
} }
func (e *StorageEngine) inhume(ctx context.Context, prm InhumePrm) (InhumeRes, error) { func (e *StorageEngine) inhume(ctx context.Context, prm InhumePrm) (InhumeRes, error) {
if e.metrics != nil { defer elapsed("Inhume", e.metrics.AddMethodDuration)()
defer elapsed("Inhume", e.metrics.AddMethodDuration)()
}
var shPrm shard.InhumePrm var shPrm shard.InhumePrm
if prm.forceRemoval { if prm.forceRemoval {

View file

@ -68,3 +68,48 @@ func (m *gcMetrics) AddExpiredObjectCollectionDuration(d time.Duration, success
func (m *gcMetrics) AddInhumedObjectCount(count uint64, objectType string) { func (m *gcMetrics) AddInhumedObjectCount(count uint64, objectType string) {
m.storage.AddInhumedObjectCount(m.shardID, count, objectType) m.storage.AddInhumedObjectCount(m.shardID, count, objectType)
} }
type (
noopMetrics struct{}
noopWriteCacheMetrics struct{}
noopGCMetrics struct{}
)
var (
_ MetricRegister = noopMetrics{}
_ metrics.WriteCacheMetrics = noopWriteCacheMetrics{}
_ metrics.GCMetrics = noopGCMetrics{}
)
func (noopMetrics) AddMethodDuration(string, time.Duration) {}
func (noopMetrics) SetObjectCounter(string, string, uint64) {}
func (noopMetrics) AddToObjectCounter(string, string, int) {}
func (noopMetrics) SetMode(string, mode.Mode) {}
func (noopMetrics) AddToContainerSize(string, int64) {}
func (noopMetrics) DeleteContainerSize(string) {}
func (noopMetrics) DeleteContainerCount(string) {}
func (noopMetrics) AddToPayloadCounter(string, int64) {}
func (noopMetrics) IncErrorCounter(string) {}
func (noopMetrics) ClearErrorCounter(string) {}
func (noopMetrics) DeleteShardMetrics(string) {}
func (noopMetrics) SetContainerObjectCounter(string, string, string, uint64) {}
func (noopMetrics) IncContainerObjectCounter(string, string, string) {}
func (noopMetrics) SubContainerObjectCounter(string, string, string, uint64) {}
func (noopMetrics) IncRefillObjectsCount(string, string, int, bool) {}
func (noopMetrics) SetRefillPercent(string, string, uint32) {}
func (noopMetrics) SetRefillStatus(string, string, string) {}
func (noopMetrics) SetEvacuationInProgress(string, bool) {}
func (noopMetrics) WriteCache() metrics.WriteCacheMetrics { return noopWriteCacheMetrics{} }
func (noopMetrics) GC() metrics.GCMetrics { return noopGCMetrics{} }
func (noopWriteCacheMetrics) AddMethodDuration(string, string, string, string, bool, time.Duration) {}
func (noopWriteCacheMetrics) SetActualCount(string, string, string, uint64) {}
func (noopWriteCacheMetrics) SetEstimateSize(string, string, string, uint64) {}
func (noopWriteCacheMetrics) SetMode(string, string) {}
func (noopWriteCacheMetrics) IncOperationCounter(string, string, string, string, metrics.NullBool) {}
func (noopWriteCacheMetrics) Close(string, string) {}
func (noopGCMetrics) AddRunDuration(string, time.Duration, bool) {}
func (noopGCMetrics) AddDeletedCount(string, uint64, uint64) {}
func (noopGCMetrics) AddExpiredObjectCollectionDuration(string, time.Duration, bool, string) {}
func (noopGCMetrics) AddInhumedObjectCount(string, uint64, string) {}

View file

@ -72,9 +72,7 @@ func (e *StorageEngine) Put(ctx context.Context, prm PutPrm) (err error) {
} }
func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error { func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
if e.metrics != nil { defer elapsed("Put", e.metrics.AddMethodDuration)()
defer elapsed("Put", e.metrics.AddMethodDuration)()
}
addr := object.AddressOf(prm.obj) addr := object.AddressOf(prm.obj)

View file

@ -82,9 +82,7 @@ func (e *StorageEngine) getRange(ctx context.Context, prm RngPrm) (RngRes, error
)) ))
defer span.End() defer span.End()
if e.metrics != nil { defer elapsed("GetRange", e.metrics.AddMethodDuration)()
defer elapsed("GetRange", e.metrics.AddMethodDuration)()
}
var shPrm shard.RngPrm var shPrm shard.RngPrm
shPrm.SetAddress(prm.addr) shPrm.SetAddress(prm.addr)

View file

@ -59,9 +59,7 @@ func (e *StorageEngine) Select(ctx context.Context, prm SelectPrm) (res SelectRe
} }
func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) (SelectRes, error) { func (e *StorageEngine) _select(ctx context.Context, prm SelectPrm) (SelectRes, error) {
if e.metrics != nil { defer elapsed("Search", e.metrics.AddMethodDuration)()
defer elapsed("Search", e.metrics.AddMethodDuration)()
}
addrList := make([]oid.Address, 0) addrList := make([]oid.Address, 0)
uniqueMap := make(map[string]struct{}) uniqueMap := make(map[string]struct{})
@ -108,9 +106,7 @@ func (e *StorageEngine) List(ctx context.Context, limit uint64) (res SelectRes,
} }
func (e *StorageEngine) list(ctx context.Context, limit uint64) (SelectRes, error) { func (e *StorageEngine) list(ctx context.Context, limit uint64) (SelectRes, error) {
if e.metrics != nil { defer elapsed("ListObjects", e.metrics.AddMethodDuration)()
defer elapsed("ListObjects", e.metrics.AddMethodDuration)()
}
addrList := make([]oid.Address, 0, limit) addrList := make([]oid.Address, 0, limit)
uniqueMap := make(map[string]struct{}) uniqueMap := make(map[string]struct{})

View file

@ -116,9 +116,7 @@ func (e *StorageEngine) AddShard(ctx context.Context, opts ...shard.Option) (*sh
return nil, fmt.Errorf("could not add %s shard: %w", sh.ID().String(), err) return nil, fmt.Errorf("could not add %s shard: %w", sh.ID().String(), err)
} }
if e.cfg.metrics != nil { e.cfg.metrics.SetMode(sh.ID().String(), sh.GetMode())
e.cfg.metrics.SetMode(sh.ID().String(), sh.GetMode())
}
return sh.ID(), nil return sh.ID(), nil
} }
@ -152,28 +150,26 @@ func (e *StorageEngine) appendMetrics(id *shard.ID, opts []shard.Option) []shard
e.mtx.RLock() e.mtx.RLock()
defer e.mtx.RUnlock() defer e.mtx.RUnlock()
if e.metrics != nil { opts = append(opts,
opts = append(opts, shard.WithMetricsWriter(
shard.WithMetricsWriter( &metricsWithID{
&metricsWithID{ id: id.String(),
id: id.String(), mw: e.metrics,
mw: e.metrics, },
}, ),
), shard.WithWriteCacheMetrics(
shard.WithWriteCacheMetrics( &writeCacheMetrics{
&writeCacheMetrics{ shardID: id.String(),
shardID: id.String(), metrics: e.metrics.WriteCache(),
metrics: e.metrics.WriteCache(), },
}, ),
), shard.WithGCMetrics(
shard.WithGCMetrics( &gcMetrics{
&gcMetrics{ storage: e.metrics.GC(),
storage: e.metrics.GC(), shardID: id.String(),
shardID: id.String(), },
}, ),
), )
)
}
return opts return opts
} }