Record Datastore metrics for flatfs and leveldb
Tommi Virtanen committed
Apr 28, 2015 at 18:31 UTC
96a86cac9814aa0000d5150b7757caf0db545c13
1 file changed
+30
-3
repo/fsrepo/fsrepo.go
+30
-3
@@ -13,6 +13,7 @@ import (
13
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
14
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/flatfs"
15
levelds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/leveldb"
16
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/measure"
17
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/mount"
18
ldbopts "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
19
repo "github.com/ipfs/go-ipfs/repo"
@@ -93,7 +94,9 @@ type FSRepo struct {
94
config *config.Config
95
ds ds.ThreadSafeDatastore
96
// tracked separately for use in Close; do not use directly.
96
- leveldbDS levelds.Datastore
97
+ leveldbDS levelds.Datastore
98
+ metricsBlocks measure.DatastoreCloser
99
+ metricsLevelDB measure.DatastoreCloser
100
}
101
102
var _ repo.Repo = (*FSRepo)(nil)
@@ -329,9 +332,27 @@ func (r *FSRepo) openDatastore() error {
332
return errors.New("unable to open flatfs datastore")
333
}
334
335
+ // Add our PeerID to metrics paths to keep them unique
336
+ //
337
+ // As some tests just pass a zero-value Config to fsrepo.Init,
338
+ // cope with missing PeerID.
339
+ id := r.config.Identity.PeerID
340
+ if id == "" {
341
+ // the tests pass in a zero Config; cope with it
342
+ id = fmt.Sprintf("uninitialized_%p", r)
343
+ }
344
+ prefix := "fsrepo." + id + ".datastore."
345
+ r.metricsBlocks = measure.New(prefix+"blocks", blocksDS)
346
+ r.metricsLevelDB = measure.New(prefix+"leveldb", r.leveldbDS)
347
mountDS := mount.New([]mount.Mount{
333
- {Prefix: ds.NewKey("/blocks"), Datastore: blocksDS},
334
- {Prefix: ds.NewKey("/"), Datastore: r.leveldbDS},
348
+ {
349
+ Prefix: ds.NewKey("/blocks"),
350
+ Datastore: r.metricsBlocks,
351
+ },
352
+ {
353
+ Prefix: ds.NewKey("/"),
354
+ Datastore: r.metricsLevelDB,
355
+ },
356
})
357
// Make sure it's ok to claim the virtual datastore from mount as
358
// threadsafe. There's no clean way to make mount itself provide
@@ -365,6 +386,12 @@ func (r *FSRepo) Close() error {
386
return errors.New("repo is closed")
387
}
388
389
+ if err := r.metricsBlocks.Close(); err != nil {
390
+ return err
391
+ }
392
+ if err := r.metricsLevelDB.Close(); err != nil {
393
+ return err
394
+ }
395
if err := r.leveldbDS.Close(); err != nil {
396
return err
397
}