[#1410] engine: Provide the default implementation to MetricsRegister

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-10-03 10:40:56 +03:00 committed by Dmitrii Stepanov
parent 9206ce5cd2
commit 9a87acb87a
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) {
if e.metrics != nil {
defer elapsed("EstimateContainerSize", e.metrics.AddMethodDuration)()
}
defer elapsed("EstimateContainerSize", e.metrics.AddMethodDuration)()
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
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) {
if e.metrics != nil {
defer elapsed("ListContainers", e.metrics.AddMethodDuration)()
}
defer elapsed("ListContainers", e.metrics.AddMethodDuration)()
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) {
if e.metrics != nil {
defer elapsed("Delete", e.metrics.AddMethodDuration)()
}
defer elapsed("Delete", e.metrics.AddMethodDuration)()
var locked struct {
is bool

View file

@ -219,6 +219,7 @@ func defaultCfg() *cfg {
res := &cfg{
log: &logger.Logger{Logger: zap.L()},
shardPoolSize: 20,
metrics: noopMetrics{},
}
res.containerSource.Store(&containerSource{})
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) {
if e.metrics != nil {
defer elapsed("Get", e.metrics.AddMethodDuration)()
}
defer elapsed("Get", e.metrics.AddMethodDuration)()
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) {
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head")
defer span.End()
if e.metrics != nil {
defer elapsed("Head", e.metrics.AddMethodDuration)()
}
defer elapsed("Head", e.metrics.AddMethodDuration)()
var (
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) {
if e.metrics != nil {
defer elapsed("Inhume", e.metrics.AddMethodDuration)()
}
defer elapsed("Inhume", e.metrics.AddMethodDuration)()
var shPrm shard.InhumePrm
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) {
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 {
if e.metrics != nil {
defer elapsed("Put", e.metrics.AddMethodDuration)()
}
defer elapsed("Put", e.metrics.AddMethodDuration)()
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()
if e.metrics != nil {
defer elapsed("GetRange", e.metrics.AddMethodDuration)()
}
defer elapsed("GetRange", e.metrics.AddMethodDuration)()
var shPrm shard.RngPrm
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) {
if e.metrics != nil {
defer elapsed("Search", e.metrics.AddMethodDuration)()
}
defer elapsed("Search", e.metrics.AddMethodDuration)()
addrList := make([]oid.Address, 0)
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) {
if e.metrics != nil {
defer elapsed("ListObjects", e.metrics.AddMethodDuration)()
}
defer elapsed("ListObjects", e.metrics.AddMethodDuration)()
addrList := make([]oid.Address, 0, limit)
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)
}
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
}
@ -152,28 +150,26 @@ func (e *StorageEngine) appendMetrics(id *shard.ID, opts []shard.Option) []shard
e.mtx.RLock()
defer e.mtx.RUnlock()
if e.metrics != nil {
opts = append(opts,
shard.WithMetricsWriter(
&metricsWithID{
id: id.String(),
mw: e.metrics,
},
),
shard.WithWriteCacheMetrics(
&writeCacheMetrics{
shardID: id.String(),
metrics: e.metrics.WriteCache(),
},
),
shard.WithGCMetrics(
&gcMetrics{
storage: e.metrics.GC(),
shardID: id.String(),
},
),
)
}
opts = append(opts,
shard.WithMetricsWriter(
&metricsWithID{
id: id.String(),
mw: e.metrics,
},
),
shard.WithWriteCacheMetrics(
&writeCacheMetrics{
shardID: id.String(),
metrics: e.metrics.WriteCache(),
},
),
shard.WithGCMetrics(
&gcMetrics{
storage: e.metrics.GC(),
shardID: id.String(),
},
),
)
return opts
}