From 3ffebd942f1507ee9f1330bc5ef59ee0cf6eeb12 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Wed, 20 May 2015 15:02:35 -0700 Subject: [PATCH] Record datastore metrics for non-default datastores License: MIT Signed-off-by: Tommi Virtanen --- repo/fsrepo/fsrepo.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 04c624142..87546bd74 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -11,6 +11,7 @@ import ( "strings" "sync" + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/measure" repo "github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo/common" config "github.com/ipfs/go-ipfs/repo/config" @@ -348,6 +349,20 @@ func (r *FSRepo) openDatastore() error { return fmt.Errorf("unknown datastore type: %s", r.config.Datastore.Type) } + // Wrap it with metrics gathering + // + // Add our PeerID to metrics paths to keep them unique + // + // As some tests just pass a zero-value Config to fsrepo.Init, + // cope with missing PeerID. + id := r.config.Identity.PeerID + if id == "" { + // the tests pass in a zero Config; cope with it + id = fmt.Sprintf("uninitialized_%p", r) + } + prefix := "fsrepo." + id + ".datastore" + r.ds = measure.New(prefix, r.ds) + return nil }