diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-23 16:34:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-06 13:39:32 +0300 |
commit | 00d3b1c8f91d21e2dd8792bf5fb66e6a7d20762c (patch) | |
tree | 9a4e467f5839cb138e19326e03e5ee6be2758912 | |
parent | 594e139de19c27d458625f0b80db42f2ca774421 (diff) |
catfile: Convert reporting of cache members to use a gauge vector
We will split up the cache into two caches, one for object readers and
one for object info readers. As a result, the current gauge we use for
tracking the number of cached batch processes will not be as informative
anymore given that it can only report the total count of processes, but
cannot distinguish the types.
Convert the gauge to a vector with a "type" label such that we can
distinguish cached processes. While at it, this also pulls out handling
of the metric from generic parts which manage the stack of cached
processe and instead moves it into a separate function. This has the
benefit that we can easily split out the generic logic for the second
cache, and it removes handling of metrics from the critical section.
-rw-r--r-- | internal/git/catfile/cache.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/internal/git/catfile/cache.go b/internal/git/catfile/cache.go index 056da582f..877cedd47 100644 --- a/internal/git/catfile/cache.go +++ b/internal/git/catfile/cache.go @@ -80,7 +80,7 @@ type ProcessCache struct { currentCatfileProcesses prometheus.Gauge totalCatfileProcesses prometheus.Counter catfileLookupCounter *prometheus.CounterVec - catfileCacheMembers prometheus.Gauge + catfileCacheMembers *prometheus.GaugeVec entriesMutex sync.Mutex entries []*entry @@ -130,11 +130,12 @@ func newCache(ttl time.Duration, maxLen int, refreshInterval time.Duration) *Pro }, []string{"type"}, ), - catfileCacheMembers: prometheus.NewGauge( + catfileCacheMembers: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "gitaly_catfile_cache_members", - Help: "Gauge of catfile cache members", + Help: "Gauge of catfile cache members by process type", }, + []string{"type"}, ), monitorTicker: time.NewTicker(refreshInterval), monitorDone: make(chan interface{}), @@ -167,6 +168,8 @@ func (c *ProcessCache) monitor() { close(c.monitorDone) return } + + c.reportCacheMembers() } } @@ -186,6 +189,8 @@ func (c *ProcessCache) BatchProcess(ctx context.Context, repo git.RepositoryExec panic("empty ctx.Done() in catfile.Batch.New()") } + defer c.reportCacheMembers() + var cancel func() cacheKey, isCacheable := newCacheKey(metadata.GetValue(ctx, SessionIDField), repo) if isCacheable { @@ -249,9 +254,15 @@ func (c *ProcessCache) BatchProcess(ctx context.Context, repo git.RepositoryExec return batch, nil } +func (c *ProcessCache) reportCacheMembers() { + c.catfileCacheMembers.WithLabelValues("batch").Set(float64(c.entryCount())) +} + func (c *ProcessCache) returnWhenDone(done <-chan struct{}, cacheKey key, batch *batch, cancel func()) { <-done + defer c.reportCacheMembers() + if c.cachedProcessDone != nil { defer func() { c.cachedProcessDone.Broadcast() @@ -299,8 +310,6 @@ func (c *ProcessCache) add(k key, b *batch, cancel func()) bool { c.evictHead() } - c.catfileCacheMembers.Set(float64(len(c.entries))) - return replacedExisting } @@ -370,5 +379,4 @@ func (c *ProcessCache) delete(i int, wantClose bool) { } c.entries = append(c.entries[:i], c.entries[i+1:]...) - c.catfileCacheMembers.Set(float64(len(c.entries))) } |