diff --git a/app/multitenant/dynamo_collector.go b/app/multitenant/dynamo_collector.go index 5f5301059..c639be062 100644 --- a/app/multitenant/dynamo_collector.go +++ b/app/multitenant/dynamo_collector.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/s3" "github.com/bluele/gcache" - "github.com/bradfitz/gomemcache/memcache" "github.com/nats-io/nats" "github.com/prometheus/client_golang/prometheus" "golang.org/x/net/context" @@ -362,20 +361,6 @@ func (c *dynamoDBCollector) getReports(userid string, row int64, start, end time return append(reports, fetchedReports...), nil } -func memcacheStatusCode(err error) string { - // See https://godoc.org/github.com/bradfitz/gomemcache/memcache#pkg-variables - switch err { - case nil: - return "200" - case memcache.ErrCacheMiss: - return "404" - case memcache.ErrMalformedKey: - return "400" - default: - return "500" - } -} - func (c *dynamoDBCollector) Report(ctx context.Context) (report.Report, error) { var ( now = time.Now() @@ -445,9 +430,7 @@ func (c *dynamoDBCollector) Add(ctx context.Context, rep report.Report) error { // third, put it in memcache if c.memcache != nil { - err = timeRequestStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error { - return c.memcache.StoreBytes(s3Key, buf.Bytes()) - }) + err = c.memcache.StoreBytes(s3Key, buf.Bytes()) if err != nil { // NOTE: We don't abort here because failing to store in memcache // doesn't actually break anything else -- it's just an diff --git a/app/multitenant/memcache_client.go b/app/multitenant/memcache_client.go index 2dcd4b14c..6aed287eb 100644 --- a/app/multitenant/memcache_client.go +++ b/app/multitenant/memcache_client.go @@ -119,6 +119,20 @@ func (c *MemcacheClient) updateMemcacheServers() error { return c.serverList.SetServers(servers...) } +func memcacheStatusCode(err error) string { + // See https://godoc.org/github.com/bradfitz/gomemcache/memcache#pkg-variables + switch err { + case nil: + return "200" + case memcache.ErrCacheMiss: + return "404" + case memcache.ErrMalformedKey: + return "400" + default: + return "500" + } +} + // FetchReports gets reports from memcache. func (c *MemcacheClient) FetchReports(keys []string) ([]report.Report, []string, error) { var found map[string]*memcache.Item @@ -172,6 +186,8 @@ func (c *MemcacheClient) FetchReports(keys []string) ([]report.Report, []string, // StoreBytes stores a report, expecting the report to be serialized already. func (c *MemcacheClient) StoreBytes(key string, content []byte) error { - item := memcache.Item{Key: key, Value: content, Expiration: c.expiration} - return c.client.Set(&item) + return timeRequestStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error { + item := memcache.Item{Key: key, Value: content, Expiration: c.expiration} + return c.client.Set(&item) + }) }