Skip to content

Commit

Permalink
Simplify in-memory cache metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jml committed Jun 20, 2016
1 parent e1db8ee commit f524a82
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions app/multitenant/dynamo_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
memcacheExpiration = 15 // seconds
memcacheUpdateInterval = 1 * time.Minute
natsTimeout = 10 * time.Second
hitLabel = "hit"
missLabel = "miss"
)

var (
Expand All @@ -43,16 +45,11 @@ var (
Name: "dynamo_request_duration_nanoseconds",
Help: "Time spent doing DynamoDB requests.",
}, []string{"method", "status_code"})
dynamoCacheHits = prometheus.NewCounter(prometheus.CounterOpts{
dynamoCacheCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "scope",
Name: "dynamo_cache_hits",
Help: "Reports fetches that hit local cache.",
})
dynamoCacheMiss = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "scope",
Name: "dynamo_cache_miss",
Help: "Reports fetches that miss local cache.",
})
Name: "dynamo_cache",
Help: "Reports fetches that hit in-memory cache.",
}, []string{"result"})
dynamoConsumedCapacity = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "scope",
Name: "dynamo_consumed_capacity",
Expand Down Expand Up @@ -97,8 +94,7 @@ var (

func init() {
prometheus.MustRegister(dynamoRequestDuration)
prometheus.MustRegister(dynamoCacheHits)
prometheus.MustRegister(dynamoCacheMiss)
prometheus.MustRegister(dynamoCacheCounter)
prometheus.MustRegister(dynamoConsumedCapacity)
prometheus.MustRegister(dynamoValueSize)
prometheus.MustRegister(reportSize)
Expand Down Expand Up @@ -384,17 +380,17 @@ func (c *dynamoDBCollector) getReports(userid string, row int64, start, end time
// and a list of providers: in-memory cache, memcache, dynamo. Possibly
// also an "always everything missing" implementation to simplify logic.
cachedReports, missing := c.getCached(reportKeys)
dynamoCacheHits.Add(float64(len(cachedReports)))
dynamoCacheMiss.Add(float64(len(missing)))
dynamoCacheCounter.WithLabelValues(hitLabel).Add(float64(len(cachedReports)))
dynamoCacheCounter.WithLabelValues(missLabel).Add(float64(len(missing)))
if len(missing) == 0 {
return cachedReports, nil
}

if c.memcache != nil {
var memcachedReports []report.Report
memcachedReports, newMissing, err := c.fetchFromMemcache(missing)
memcacheCounter.WithLabelValues("hit").Add(float64(len(memcachedReports)))
memcacheCounter.WithLabelValues("miss").Add(float64(len(newMissing)))
memcacheCounter.WithLabelValues(hitLabel).Add(float64(len(memcachedReports)))
memcacheCounter.WithLabelValues(missLabel).Add(float64(len(newMissing)))
if err == nil {
cachedReports = append(cachedReports, memcachedReports...)
missing = newMissing
Expand Down

0 comments on commit f524a82

Please sign in to comment.