Skip to content

Commit

Permalink
Merge pull request #23 from ipfs/feat/ds-update
Browse files Browse the repository at this point in the history
update datastore Interface
  • Loading branch information
aschmahmann authored Dec 3, 2019
2 parents 0ebe79f + 4bdddbf commit 70c8911
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/ipfs/go-ds-measure

require (
github.com/ipfs/go-datastore v0.1.1
github.com/ipfs/go-datastore v0.3.0
github.com/ipfs/go-metrics-interface v0.0.1
)

Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJY
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/ipfs/go-datastore v0.0.1 h1:AW/KZCScnBWlSb5JbnEnLKFWXL224LBEh/9KXXOrUms=
github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore v0.1.0 h1:TOxI04l8CmO4zGtesENhzm4PwkFwJXY3rKiYaaMf9fI=
github.com/ipfs/go-datastore v0.1.0/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE=
github.com/ipfs/go-datastore v0.1.1 h1:F4k0TkTAZGLFzBOrVKDAvch6JZtuN4NHkfdcEZL50aI=
github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw=
github.com/ipfs/go-datastore v0.3.0 h1:9au0tYi/+n7xeUnGHG6davnS8x9hWbOzP/388Vx3CMs=
github.com/ipfs/go-datastore v0.3.0/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRVNdgPHtbHw=
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg=
github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY=
Expand Down
19 changes: 19 additions & 0 deletions measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func New(prefix string, ds datastore.Datastore) *measure {
putSize: metrics.New(prefix+".put.size_bytes",
"Size distribution of stored byte slices").Histogram(datastoreSizeBuckets),

syncNum: metrics.New(prefix+".sync_total", "Total number of Datastore.Sync calls").Counter(),
syncErr: metrics.New(prefix+".sync.errors_total", "Number of errored Datastore.Sync calls").Counter(),
syncLatency: metrics.New(prefix+".sync.latency_seconds",
"Latency distribution of Datastore.Sync calls").Histogram(datastoreLatencyBuckets),

getNum: metrics.New(prefix+".get_total", "Total number of Datastore.Get calls").Counter(),
getErr: metrics.New(prefix+".get.errors_total", "Number of errored Datastore.Get calls").Counter(),
getLatency: metrics.New(prefix+".get.latency_seconds",
Expand Down Expand Up @@ -106,6 +111,10 @@ type measure struct {
putLatency metrics.Histogram
putSize metrics.Histogram

syncNum metrics.Counter
syncErr metrics.Counter
syncLatency metrics.Histogram

getNum metrics.Counter
getErr metrics.Counter
getLatency metrics.Histogram
Expand Down Expand Up @@ -173,6 +182,16 @@ func (m *measure) Put(key datastore.Key, value []byte) error {
return err
}

func (m *measure) Sync(prefix datastore.Key) error {
defer recordLatency(m.syncLatency, time.Now())
m.syncNum.Inc()
err := m.backend.Sync(prefix)
if err != nil {
m.syncErr.Inc()
}
return err
}

func (m *measure) Get(key datastore.Key) (value []byte, err error) {
defer recordLatency(m.getLatency, time.Now())
m.getNum.Inc()
Expand Down

0 comments on commit 70c8911

Please sign in to comment.