Skip to content

Commit

Permalink
Add prometheus summary for entries' size
Browse files Browse the repository at this point in the history
Entries could be rather different in size between projects.
This is why it's a summary instead of a histogram.
  • Loading branch information
reimai authored and mostynb committed Oct 2, 2024
1 parent 76a3093 commit 5eb6c8f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cache/disk/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type SizedLRU struct {
gaugeCacheLogicalBytes prometheus.Gauge
counterEvictedBytes prometheus.Counter
counterOverwrittenBytes prometheus.Counter
summaryCacheItemBytes prometheus.Summary
}

type entry struct {
Expand Down Expand Up @@ -83,6 +84,16 @@ func NewSizedLRU(maxSize int64, onEvict EvictCallback, initialCapacity int) Size
Name: "bazel_remote_disk_cache_overwritten_bytes_total",
Help: "The total number of bytes removed from disk backend, due to put of already existing key",
}),
summaryCacheItemBytes: prometheus.NewSummary(prometheus.SummaryOpts{
Name: "bazel_remote_disk_cache_entry_bytes",
Help: "Size of cache entries",
Objectives: map[float64]float64{
0.5: 0.05,
0.9: 0.01,
0.99: 0.001,
1: 0,
},
}),
}
}

Expand All @@ -91,6 +102,7 @@ func (c *SizedLRU) RegisterMetrics() {
prometheus.MustRegister(c.gaugeCacheLogicalBytes)
prometheus.MustRegister(c.counterEvictedBytes)
prometheus.MustRegister(c.counterOverwrittenBytes)
prometheus.MustRegister(c.summaryCacheItemBytes)
}

// Add adds a (key, value) to the cache, evicting items as necessary.
Expand Down Expand Up @@ -149,6 +161,7 @@ func (c *SizedLRU) Add(key Key, value lruItem) (ok bool) {

c.gaugeCacheSizeBytes.Set(float64(c.currentSize))
c.gaugeCacheLogicalBytes.Set(float64(c.uncompressedSize))
c.summaryCacheItemBytes.Observe(float64(sizeDelta))

return true
}
Expand Down

0 comments on commit 5eb6c8f

Please sign in to comment.