swarm: LocalStore metrics
* swarm/shed: remove metrics fields from DB struct * swarm/schunk: add String methods to modes * swarm/storage/localstore: add metrics and traces * swarm/chunk: unknown modes without spaces in String methods * swarm/storage/localstore: remove bin number from pull subscription metrics * swarm/storage/localstore: add resetting time metrics and code improvements
This commit is contained in:
committed by
Anton Evangelatov
parent
993b145f25
commit
c1213bd00c
@@ -18,10 +18,15 @@ package localstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/shed"
|
||||
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
||||
olog "github.com/opentracing/opentracing-go/log"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
)
|
||||
|
||||
@@ -30,7 +35,22 @@ import (
|
||||
// All required indexes will be updated required by the
|
||||
// Getter Mode. Get is required to implement chunk.Store
|
||||
// interface.
|
||||
func (db *DB) Get(_ context.Context, mode chunk.ModeGet, addr chunk.Address) (ch chunk.Chunk, err error) {
|
||||
func (db *DB) Get(ctx context.Context, mode chunk.ModeGet, addr chunk.Address) (ch chunk.Chunk, err error) {
|
||||
metricName := fmt.Sprintf("localstore.Get.%s", mode)
|
||||
|
||||
ctx, sp := spancontext.StartSpan(ctx, metricName)
|
||||
defer sp.Finish()
|
||||
sp.LogFields(olog.String("ref", addr.String()), olog.String("mode-get", mode.String()))
|
||||
|
||||
metrics.GetOrRegisterCounter(metricName, nil).Inc(1)
|
||||
defer totalTimeMetric(metricName, time.Now())
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
metrics.GetOrRegisterCounter(fmt.Sprintf(metricName+".error", mode), nil).Inc(1)
|
||||
}
|
||||
}()
|
||||
|
||||
out, err := db.get(mode, addr)
|
||||
if err != nil {
|
||||
if err == leveldb.ErrNotFound {
|
||||
@@ -66,8 +86,14 @@ func (db *DB) get(mode chunk.ModeGet, addr chunk.Address) (out shed.Item, err er
|
||||
// for a new goroutine
|
||||
defer func() { <-db.updateGCSem }()
|
||||
}
|
||||
|
||||
metricName := "localstore.updateGC"
|
||||
metrics.GetOrRegisterCounter(metricName, nil).Inc(1)
|
||||
defer totalTimeMetric(metricName, time.Now())
|
||||
|
||||
err := db.updateGC(out)
|
||||
if err != nil {
|
||||
metrics.GetOrRegisterCounter(metricName+".error", nil).Inc(1)
|
||||
log.Error("localstore update gc", "err", err)
|
||||
}
|
||||
// if gc update hook is defined, call it
|
||||
|
Reference in New Issue
Block a user