[#373] blobstor: Add metrics

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-06 09:05:52 +03:00
parent 8318d90ad0
commit f54cc0b607
11 changed files with 134 additions and 19 deletions

View file

@ -3,6 +3,7 @@ package blobstor
import (
"context"
"encoding/hex"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
@ -17,6 +18,14 @@ import (
// Returns any error encountered that did not allow
// to completely check object existence.
func (b *BlobStor) Exists(ctx context.Context, prm common.ExistsPrm) (common.ExistsRes, error) {
var (
exists = false
startedAt = time.Now()
)
defer func() {
b.metrics.Exists(time.Since(startedAt), exists, prm.StorageID != nil)
}()
ctx, span := tracing.StartSpanFromContext(ctx, "BlobStor.Exists",
trace.WithAttributes(
attribute.String("address", prm.Address.EncodeToString()),
@ -29,9 +38,13 @@ func (b *BlobStor) Exists(ctx context.Context, prm common.ExistsPrm) (common.Exi
if prm.StorageID != nil {
if len(prm.StorageID) == 0 {
return b.storage[len(b.storage)-1].Storage.Exists(ctx, prm)
res, err := b.storage[len(b.storage)-1].Storage.Exists(ctx, prm)
exists = err == nil && res.Exists
return res, err
}
return b.storage[0].Storage.Exists(ctx, prm)
res, err := b.storage[0].Storage.Exists(ctx, prm)
exists = err == nil && res.Exists
return res, err
}
// If there was an error during existence check below,
@ -47,6 +60,7 @@ func (b *BlobStor) Exists(ctx context.Context, prm common.ExistsPrm) (common.Exi
for i := range b.storage {
res, err := b.storage[i].Storage.Exists(ctx, prm)
if err == nil && res.Exists {
exists = true
return res, nil
} else if err != nil {
errors = append(errors, err)