Skip to content

Commit

Permalink
fix: metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Feb 5, 2024
1 parent 2a00c0b commit 64d8ea6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/storer/internal/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func NewStorage(sharky *sharky.Store, bstore storage.BatchStore) Storage {
}

type transaction struct {
start time.Time
batch storage.Batch
indexstore storage.IndexStore
chunkStore *chunkStoreTrx
Expand All @@ -81,10 +82,11 @@ type transaction struct {
func (s *store) NewTransaction(ctx context.Context) (Transaction, func()) {

b := s.bstore.Batch(ctx)
indexTrx := &indexTrx{s.bstore, b}
indexTrx := &indexTrx{s.bstore, b, s.metrics}
sharyTrx := &sharkyTrx{s.sharky, s.metrics, nil, nil}

t := &transaction{
start: time.Now(),
batch: b,
indexstore: indexTrx,
chunkStore: &chunkStoreTrx{indexTrx, sharyTrx, s.chunkLocker, make(map[string]struct{}), s.metrics, false},
Expand All @@ -108,7 +110,7 @@ func (s *store) NewTransaction(ctx context.Context) (Transaction, func()) {
}

func (s *store) ReadOnly() ReadOnlyStore {
indexStore := &indexTrx{s.bstore, nil}
indexStore := &indexTrx{s.bstore, nil, s.metrics}
sharyTrx := &sharkyTrx{s.sharky, s.metrics, nil, nil}

return &readOnly{indexStore, &chunkStoreTrx{indexStore, sharyTrx, s.chunkLocker, nil, s.metrics, true}}
Expand Down Expand Up @@ -149,6 +151,10 @@ func (t *readOnly) ChunkStore() storage.ReadOnlyChunkStore {

func (t *transaction) Commit() (err error) {

defer func() {
t.metrics.MethodDuration.WithLabelValues("transaction", "success").Observe(float64(time.Since(t.start).Seconds()))

Check failure on line 155 in pkg/storer/internal/transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)
}()

defer handleMetric("commit", t.metrics)(err)
defer func() {
for addr := range t.chunkStore.lockedAddrs {
Expand Down Expand Up @@ -250,14 +256,16 @@ func (c *chunkStoreTrx) lock(addr swarm.Address) func() {
}

type indexTrx struct {
store storage.Reader
batch storage.Batch
store storage.Reader
batch storage.Batch
metrics metrics
}

func (s *indexTrx) Get(i storage.Item) error { return s.store.Get(i) }
func (s *indexTrx) Has(k storage.Key) (bool, error) { return s.store.Has(k) }
func (s *indexTrx) GetSize(k storage.Key) (int, error) { return s.store.GetSize(k) }
func (s *indexTrx) Iterate(q storage.Query, f storage.IterateFn) error {
func (s *indexTrx) Iterate(q storage.Query, f storage.IterateFn) (err error) {
defer handleMetric("index_iterate", s.metrics)(err)
return s.store.Iterate(q, f)
}
func (s *indexTrx) Count(k storage.Key) (int, error) { return s.store.Count(k) }
Expand Down Expand Up @@ -297,10 +305,10 @@ func handleMetric(key string, m metrics) func(err error) {
return func(err error) {
if err != nil {
m.MethodCalls.WithLabelValues(key, "failure").Inc()
m.MethodDuration.WithLabelValues(key, "failure").Observe(float64(time.Since(t)))
m.MethodDuration.WithLabelValues(key, "failure").Observe(float64(time.Since(t).Seconds()))

Check failure on line 308 in pkg/storer/internal/transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)
} else {
m.MethodCalls.WithLabelValues(key, "success").Inc()
m.MethodDuration.WithLabelValues(key, "success").Observe(float64(time.Since(t)))
m.MethodDuration.WithLabelValues(key, "success").Observe(float64(time.Since(t).Seconds()))

Check failure on line 311 in pkg/storer/internal/transaction/transaction.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)
}
}
}
1 change: 1 addition & 0 deletions pkg/storer/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (db *DB) unreserve(ctx context.Context) (err error) {
radius++
db.logger.Info("reserve radius increase", "radius", radius)
_ = db.reserve.SetRadius(radius)
db.metrics.StorageRadius.Set(float64(radius))
}

return errMaxRadius
Expand Down

0 comments on commit 64d8ea6

Please sign in to comment.