Skip to content

Commit

Permalink
fix evict metric
Browse files Browse the repository at this point in the history
Signed-off-by: alanprot <[email protected]>
  • Loading branch information
alanprot committed Jan 6, 2025
1 parent 8b57e7b commit 0f0de00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func TestMatcherCache(t *testing.T) {
blocksDir := filepath.Join(dir, "blocks")
require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))

ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry, true)
cfg := defaultIngesterTestConfig(t)
cfg.MatchersCacheMaxItems = 50
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, registry, true)
require.NoError(t, err)
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))

Expand All @@ -142,7 +143,8 @@ func TestMatcherCache(t *testing.T) {
return ing.lifecycler.GetState()
})
ctx := user.InjectOrgID(context.Background(), userID)
numberOfDifferentMatchers := 50
// Lets have 1 key evicted
numberOfDifferentMatchers := cfg.MatchersCacheMaxItems + 1
callPerMatcher := 10
for j := 0; j < numberOfDifferentMatchers; j++ {
for i := 0; i < callPerMatcher; i++ {
Expand All @@ -159,7 +161,7 @@ func TestMatcherCache(t *testing.T) {
require.NoError(t, testutil.GatherAndCompare(registry, bytes.NewBufferString(fmt.Sprintf(`
# HELP ingester_matchers_cache_evicted_total Total number of items evicted from the cache
# TYPE ingester_matchers_cache_evicted_total counter
ingester_matchers_cache_evicted_total 0
ingester_matchers_cache_evicted_total 1
# HELP ingester_matchers_cache_hits_total Total number of cache hits for series matchers
# TYPE ingester_matchers_cache_hits_total counter
ingester_matchers_cache_hits_total %v
Expand All @@ -172,7 +174,7 @@ func TestMatcherCache(t *testing.T) {
# HELP ingester_matchers_cache_requests_total Total number of cache requests for series matchers
# TYPE ingester_matchers_cache_requests_total counter
ingester_matchers_cache_requests_total %v
`, callPerMatcher*numberOfDifferentMatchers-numberOfDifferentMatchers, numberOfDifferentMatchers, callPerMatcher*numberOfDifferentMatchers)), "ingester_matchers_cache_requests_total", "ingester_matchers_cache_hits_total", "ingester_matchers_cache_items", "ingester_matchers_cache_max_items", "ingester_matchers_cache_evicted_total"))
`, callPerMatcher*numberOfDifferentMatchers-numberOfDifferentMatchers, cfg.MatchersCacheMaxItems, callPerMatcher*numberOfDifferentMatchers)), "ingester_matchers_cache_requests_total", "ingester_matchers_cache_hits_total", "ingester_matchers_cache_items", "ingester_matchers_cache_max_items", "ingester_matchers_cache_evicted_total"))
}

func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,5 +742,5 @@ func (m *matcherCacheMetrics) Collect(out chan<- prometheus.Metric) {
out <- prometheus.MustNewConstMetric(m.hitsTotal, prometheus.CounterValue, mfm.SumCounters("thanos_matchers_cache_hits_total"))
out <- prometheus.MustNewConstMetric(m.numItems, prometheus.GaugeValue, mfm.SumGauges("thanos_matchers_cache_items"))
out <- prometheus.MustNewConstMetric(m.maxItems, prometheus.GaugeValue, mfm.SumGauges("thanos_matchers_cache_max_items"))
out <- prometheus.MustNewConstMetric(m.evicted, prometheus.CounterValue, mfm.SumCounters("thanos_matchers_cache_max_items"))
out <- prometheus.MustNewConstMetric(m.evicted, prometheus.CounterValue, mfm.SumCounters("thanos_matchers_cache_evicted_total"))
}

0 comments on commit 0f0de00

Please sign in to comment.