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

Commit

Permalink
Emit size gauge metric for autorefresh cache (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
EngHabu authored Oct 23, 2019
1 parent 62c2309 commit 66e0317
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flytestdlib/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

0 comments on commit 66e0317

Please sign in to comment.