diff --git a/sql/querycache.go b/sql/querycache.go index d6a34cbaff..dbf5027ec9 100644 --- a/sql/querycache.go +++ b/sql/querycache.go @@ -222,6 +222,26 @@ func (c *queryCache) IsCached() bool { return c != nil } +func reportHit(key queryCacheKey) { + switch key.Kind { + case "atx-blob": + // don't use the key as it would create too many labels + queryCacheHits.WithLabelValues(string(key.Kind), "").Inc() + default: + queryCacheHits.WithLabelValues(string(key.Kind), key.Key).Inc() + } +} + +func reportMiss(key queryCacheKey) { + switch key.Kind { + case "atx-blob": + // don't use the key as it would create too many labels + queryCacheMisses.WithLabelValues(string(key.Kind), "").Inc() + default: + queryCacheMisses.WithLabelValues(string(key.Kind), key.Key).Inc() + } +} + func (c *queryCache) GetValue( ctx context.Context, key queryCacheKey, @@ -239,7 +259,7 @@ func (c *queryCache) GetValue( v, found := c.get(key, subKey) var err error if !found { - queryCacheMisses.WithLabelValues(string(key.Kind), key.Key).Inc() + reportMiss(key) // This may seem like a race, but at worst, retrieve() will be // called several times when populating this cached entry. // That's better than locking for the duration of retrieve(), @@ -249,7 +269,7 @@ func (c *queryCache) GetValue( c.set(key, subKey, v) } } else { - queryCacheHits.WithLabelValues(string(key.Kind), key.Key).Inc() + reportHit(key) } return v, err }