From 0a6c79c2017f2d67eea12c4746731f8127b1408d Mon Sep 17 00:00:00 2001 From: alanprot Date: Mon, 23 Dec 2024 11:53:33 -0800 Subject: [PATCH] Adding total on all metric Signed-off-by: alanprot --- pkg/ingester/ingester_test.go | 28 +++++++++---------- pkg/storage/tsdb/expanded_postings_cache.go | 10 +++---- .../tsdb/expanded_postings_cache_test.go | 26 ++++++++--------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index d4d05fef9a0..ad84c57be4c 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -5553,22 +5553,22 @@ func TestExpendedPostingsCache(t *testing.T) { if c.expectedHeadPostingCall > 0 || c.expectedBlockPostingCall > 0 { metric := ` - # HELP cortex_ingester_expanded_postings_cache_requests Total number of requests to the cache. - # TYPE cortex_ingester_expanded_postings_cache_requests counter + # HELP cortex_ingester_expanded_postings_cache_requests_total Total number of requests to the cache. + # TYPE cortex_ingester_expanded_postings_cache_requests_total counter ` if c.expectedBlockPostingCall > 0 { metric += ` - cortex_ingester_expanded_postings_cache_requests{cache="block"} 4 + cortex_ingester_expanded_postings_cache_requests_total{cache="block"} 4 ` } if c.expectedHeadPostingCall > 0 { metric += ` - cortex_ingester_expanded_postings_cache_requests{cache="head"} 4 + cortex_ingester_expanded_postings_cache_requests_total{cache="head"} 4 ` } - err = testutil.GatherAndCompare(r, bytes.NewBufferString(metric), "cortex_ingester_expanded_postings_cache_requests") + err = testutil.GatherAndCompare(r, bytes.NewBufferString(metric), "cortex_ingester_expanded_postings_cache_requests_total") require.NoError(t, err) } @@ -5583,22 +5583,22 @@ func TestExpendedPostingsCache(t *testing.T) { if c.expectedHeadPostingCall > 0 || c.expectedBlockPostingCall > 0 { metric := ` - # HELP cortex_ingester_expanded_postings_cache_hits Total number of hit requests to the cache. - # TYPE cortex_ingester_expanded_postings_cache_hits counter + # HELP cortex_ingester_expanded_postings_cache_hits_total Total number of hit requests to the cache. + # TYPE cortex_ingester_expanded_postings_cache_hits_total counter ` if c.expectedBlockPostingCall > 0 { metric += ` - cortex_ingester_expanded_postings_cache_hits{cache="block"} 4 + cortex_ingester_expanded_postings_cache_hits_total{cache="block"} 4 ` } if c.expectedHeadPostingCall > 0 { metric += ` - cortex_ingester_expanded_postings_cache_hits{cache="head"} 4 + cortex_ingester_expanded_postings_cache_hits_total{cache="head"} 4 ` } - err = testutil.GatherAndCompare(r, bytes.NewBufferString(metric), "cortex_ingester_expanded_postings_cache_hits") + err = testutil.GatherAndCompare(r, bytes.NewBufferString(metric), "cortex_ingester_expanded_postings_cache_hits_total") require.NoError(t, err) } @@ -5644,10 +5644,10 @@ func TestExpendedPostingsCache(t *testing.T) { require.Equal(t, postingsForMatchersCalls.Load(), int64(c.expectedBlockPostingCall)) if c.cacheConfig.Head.Enabled { err = testutil.GatherAndCompare(r, bytes.NewBufferString(` - # HELP cortex_ingester_expanded_postings_non_cacheable_queries Total number of non cacheable queries. - # TYPE cortex_ingester_expanded_postings_non_cacheable_queries counter - cortex_ingester_expanded_postings_non_cacheable_queries{cache="head"} 1 -`), "cortex_ingester_expanded_postings_non_cacheable_queries") + # HELP cortex_ingester_expanded_postings_non_cacheable_queries_total Total number of non cacheable queries. + # TYPE cortex_ingester_expanded_postings_non_cacheable_queries_total counter + cortex_ingester_expanded_postings_non_cacheable_queries_total{cache="head"} 1 +`), "cortex_ingester_expanded_postings_non_cacheable_queries_total") require.NoError(t, err) } diff --git a/pkg/storage/tsdb/expanded_postings_cache.go b/pkg/storage/tsdb/expanded_postings_cache.go index aeae9fb37ea..3ea8da709ec 100644 --- a/pkg/storage/tsdb/expanded_postings_cache.go +++ b/pkg/storage/tsdb/expanded_postings_cache.go @@ -47,23 +47,23 @@ type ExpandedPostingsCacheMetrics struct { func NewPostingCacheMetrics(r prometheus.Registerer) *ExpandedPostingsCacheMetrics { return &ExpandedPostingsCacheMetrics{ CacheRequests: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ - Name: "cortex_ingester_expanded_postings_cache_requests", + Name: "cortex_ingester_expanded_postings_cache_requests_total", Help: "Total number of requests to the cache.", }, []string{"cache"}), CacheHits: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ - Name: "cortex_ingester_expanded_postings_cache_hits", + Name: "cortex_ingester_expanded_postings_cache_hits_total", Help: "Total number of hit requests to the cache.", }, []string{"cache"}), CacheMiss: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ - Name: "cortex_ingester_expanded_postings_cache_miss", + Name: "cortex_ingester_expanded_postings_cache_miss_total", Help: "Total number of miss requests to the cache.", }, []string{"cache", "reason"}), CacheEvicts: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ - Name: "cortex_ingester_expanded_postings_cache_evicts", + Name: "cortex_ingester_expanded_postings_cache_evicts_total", Help: "Total number of evictions in the cache, excluding items that got evicted due to TTL.", }, []string{"cache", "reason"}), NonCacheableQueries: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ - Name: "cortex_ingester_expanded_postings_non_cacheable_queries", + Name: "cortex_ingester_expanded_postings_non_cacheable_queries_total", Help: "Total number of non cacheable queries.", }, []string{"cache"}), } diff --git a/pkg/storage/tsdb/expanded_postings_cache_test.go b/pkg/storage/tsdb/expanded_postings_cache_test.go index 7909ce0ff24..19272c00e72 100644 --- a/pkg/storage/tsdb/expanded_postings_cache_test.go +++ b/pkg/storage/tsdb/expanded_postings_cache_test.go @@ -154,10 +154,10 @@ func TestFifoCacheExpire(t *testing.T) { if c.expectedFinalItems != numberOfKeys { err := testutil.GatherAndCompare(r, bytes.NewBufferString(fmt.Sprintf(` - # HELP cortex_ingester_expanded_postings_cache_evicts Total number of evictions in the cache, excluding items that got evicted due to TTL. - # TYPE cortex_ingester_expanded_postings_cache_evicts counter - cortex_ingester_expanded_postings_cache_evicts{cache="test",reason="full"} %v -`, numberOfKeys-c.expectedFinalItems)), "cortex_ingester_expanded_postings_cache_evicts") + # HELP cortex_ingester_expanded_postings_cache_evicts_total Total number of evictions in the cache, excluding items that got evicted due to TTL. + # TYPE cortex_ingester_expanded_postings_cache_evicts_total counter + cortex_ingester_expanded_postings_cache_evicts_total{cache="test",reason="full"} %v +`, numberOfKeys-c.expectedFinalItems)), "cortex_ingester_expanded_postings_cache_evicts_total") require.NoError(t, err) } @@ -181,11 +181,11 @@ func TestFifoCacheExpire(t *testing.T) { } err := testutil.GatherAndCompare(r, bytes.NewBufferString(fmt.Sprintf(` - # HELP cortex_ingester_expanded_postings_cache_miss Total number of miss requests to the cache. - # TYPE cortex_ingester_expanded_postings_cache_miss counter - cortex_ingester_expanded_postings_cache_miss{cache="test",reason="expired"} %v - cortex_ingester_expanded_postings_cache_miss{cache="test",reason="miss"} %v -`, numberOfKeys, numberOfKeys)), "cortex_ingester_expanded_postings_cache_miss") + # HELP cortex_ingester_expanded_postings_cache_miss_total Total number of miss requests to the cache. + # TYPE cortex_ingester_expanded_postings_cache_miss_total counter + cortex_ingester_expanded_postings_cache_miss_total{cache="test",reason="expired"} %v + cortex_ingester_expanded_postings_cache_miss_total{cache="test",reason="miss"} %v +`, numberOfKeys, numberOfKeys)), "cortex_ingester_expanded_postings_cache_miss_total") require.NoError(t, err) cache.timeNow = func() time.Time { @@ -198,10 +198,10 @@ func TestFifoCacheExpire(t *testing.T) { // Should expire all keys expired keys err = testutil.GatherAndCompare(r, bytes.NewBufferString(fmt.Sprintf(` - # HELP cortex_ingester_expanded_postings_cache_evicts Total number of evictions in the cache, excluding items that got evicted due to TTL. - # TYPE cortex_ingester_expanded_postings_cache_evicts counter - cortex_ingester_expanded_postings_cache_evicts{cache="test",reason="expired"} %v -`, numberOfKeys)), "cortex_ingester_expanded_postings_cache_evicts") + # HELP cortex_ingester_expanded_postings_cache_evicts_total Total number of evictions in the cache, excluding items that got evicted due to TTL. + # TYPE cortex_ingester_expanded_postings_cache_evicts_total counter + cortex_ingester_expanded_postings_cache_evicts_total{cache="test",reason="expired"} %v +`, numberOfKeys)), "cortex_ingester_expanded_postings_cache_evicts_total") require.NoError(t, err) } })