Skip to content

Commit

Permalink
Dont use 'key' label for atx-blobs Kind
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Jun 13, 2024
1 parent a1d9482 commit f34234a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sql/querycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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
}
Expand Down

0 comments on commit f34234a

Please sign in to comment.