From f34234ae7914dc60dce5b426d480906ea017d945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Thu, 13 Jun 2024 17:11:50 +0200 Subject: [PATCH] Dont use 'key' label for atx-blobs Kind --- sql/querycache.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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 }