Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion relay/cache/cache_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ func (c *cacheAccessor[K, V]) Get(ctx context.Context, key K) (V, error) {
c.cacheLock.Unlock()

if c.metrics != nil {
c.metrics.ReportCacheMiss()
if alreadyLoading {
// A lookup is currently in progress. Not a cache hit, but this call won't duplicate the work.
c.metrics.ReportCacheNearMiss()
} else {
// The data is not in the cache and no lookup is in progress. We must fetch the data from the source.
c.metrics.ReportCacheMiss()
}
}

if alreadyLoading {
Expand Down
15 changes: 15 additions & 0 deletions relay/cache/cache_accessor_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const namespace = "eigenda_relay"
// CacheAccessorMetrics provides metrics for a CacheAccessor.
type CacheAccessorMetrics struct {
cacheHits *prometheus.CounterVec
cacheNearMisses *prometheus.CounterVec
cacheMisses *prometheus.CounterVec
size *prometheus.GaugeVec
weight *prometheus.GaugeVec
Expand All @@ -34,6 +35,15 @@ func NewCacheAccessorMetrics(
[]string{},
)

cacheNearMisses := promauto.With(registry).NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: fmt.Sprintf("%s_cache_near_miss_count", cacheName),
Help: "Number of near cache misses (i.e. a lookup is already in progress)",
},
[]string{},
)

cacheMisses := promauto.With(registry).NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Expand Down Expand Up @@ -82,6 +92,7 @@ func NewCacheAccessorMetrics(

return &CacheAccessorMetrics{
cacheHits: cacheHits,
cacheNearMisses: cacheNearMisses,
cacheMisses: cacheMisses,
size: size,
weight: weight,
Expand All @@ -94,6 +105,10 @@ func (m *CacheAccessorMetrics) ReportCacheHit() {
m.cacheHits.WithLabelValues().Inc()
}

func (m *CacheAccessorMetrics) ReportCacheNearMiss() {
m.cacheNearMisses.WithLabelValues().Inc()
}

func (m *CacheAccessorMetrics) ReportCacheMiss() {
m.cacheMisses.WithLabelValues().Inc()
}
Expand Down
Loading