diff --git a/chainstore_test.go b/chainstore_test.go index a1c3434..199d351 100644 --- a/chainstore_test.go +++ b/chainstore_test.go @@ -15,7 +15,6 @@ import ( "github.com/pressly/chainstore/logmgr" "github.com/pressly/chainstore/lrumgr" "github.com/pressly/chainstore/memstore" - "github.com/pressly/chainstore/metricsmgr" "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -100,7 +99,7 @@ func TestAsyncChain(t *testing.T) { }, logmgr.New(logger, "async"), &testStore{}, - metricsmgr.New("chaintest", + chainstore.New( fs, lrumgr.New(100, bs), ), diff --git a/metricsmgr/metrics_manager.go b/metricsmgr/metrics_manager.go deleted file mode 100644 index 4cf13c1..0000000 --- a/metricsmgr/metrics_manager.go +++ /dev/null @@ -1,84 +0,0 @@ -package metricsmgr - -import ( - "context" - "fmt" - "time" - - "github.com/pressly/chainstore" - metrics "github.com/rcrowley/go-metrics" -) - -type metricsManager struct { - namespace string - chain chainstore.Store -} - -// New returns a metrics store. -func New(namespace string, stores ...chainstore.Store) chainstore.Store { - return &metricsManager{ - namespace: namespace, - chain: chainstore.New(stores...), - } -} - -func (m *metricsManager) Open() (err error) { - _, err = m.measure("Open", func() ([]byte, error) { - err := m.chain.Open() - return nil, err - }) - return -} - -func (m *metricsManager) Close() (err error) { - _, err = m.measure("Close", func() ([]byte, error) { - err := m.chain.Close() - return nil, err - }) - return -} - -func (m *metricsManager) Put(ctx context.Context, key string, val []byte) (err error) { - select { - case <-ctx.Done(): - return ctx.Err() - default: - _, err = m.measure("Put", func() ([]byte, error) { - err := m.chain.Put(ctx, key, val) - return nil, err - }) - return - } -} - -func (m *metricsManager) Get(ctx context.Context, key string) (val []byte, err error) { - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - val, err = m.measure("Get", func() ([]byte, error) { - val, err := m.chain.Get(ctx, key) - return val, err - }) - return - } -} - -func (m *metricsManager) Del(ctx context.Context, key string) (err error) { - select { - case <-ctx.Done(): - return ctx.Err() - default: - _, err = m.measure("Del", func() ([]byte, error) { - err := m.chain.Del(ctx, key) - return nil, err - }) - return - } -} - -func (m *metricsManager) measure(method string, fn func() ([]byte, error)) ([]byte, error) { - name := fmt.Sprintf("%s.%s", m.namespace, method) - defer metrics.MeasureSince([]string{name}, time.Now()) - return fn() -} diff --git a/metricsmgr/metrics_manager_test.go b/metricsmgr/metrics_manager_test.go deleted file mode 100644 index fe70ae3..0000000 --- a/metricsmgr/metrics_manager_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package metricsmgr - -import ( - "testing" - - "github.com/pressly/chainstore" - "github.com/stretchr/testify/assert" - "golang.org/x/net/context" -) - -func TestMetricsMgrStore(t *testing.T) { - var store chainstore.Store - var err error - - ctx := context.Background() - - assert := assert.New(t) - - store = chainstore.New(New("ns")) - err = store.Open() - assert.Nil(err) - defer store.Close() - - // Put a bunch of objects - e1 := store.Put(ctx, "hi", []byte{1, 2, 3}) - e2 := store.Put(ctx, "bye", []byte{4, 5, 6}) - assert.Nil(e1) - assert.Nil(e2) - - // Delete those objects - e1 = store.Del(ctx, "hi") - e2 = store.Del(ctx, "bye") - assert.Equal(e1, nil) - assert.Equal(e2, nil) -}