Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Emit size gauge metric for autorefresh cache #48

Merged
merged 1 commit into from
Oct 23, 2019
Merged
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
4 changes: 4 additions & 0 deletions cache/auto_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type metrics struct {
SyncLatency promutils.StopWatch
CacheHit prometheus.Counter
CacheMiss prometheus.Counter
Size prometheus.Gauge
scope promutils.Scope
}

Expand Down Expand Up @@ -139,6 +140,7 @@ func newMetrics(scope promutils.Scope) metrics {
SyncLatency: scope.MustNewStopWatch("latency", "Latency for sync operations.", time.Millisecond),
CacheHit: scope.MustNewCounter("cache_hit", "Counter for cache hits."),
CacheMiss: scope.MustNewCounter("cache_miss", "Counter for cache misses."),
Size: scope.MustNewGauge("size", "Current size of the cache"),
scope: scope,
}
}
Expand Down Expand Up @@ -194,6 +196,8 @@ func (w *autoRefresh) GetOrCreate(id ItemID, item Item) (Item, error) {
// - Enqueue all the batches into the workqueue
func (w *autoRefresh) enqueueBatches(ctx context.Context) error {
keys := w.lruMap.Keys()
w.metrics.Size.Set(float64(len(keys)))

snapshot := make([]ItemWrapper, 0, len(keys))
for _, k := range keys {
// If not ok, it means evicted between the item was evicted between getting the keys and this update loop
Expand Down