Skip to content

Commit

Permalink
Adding total on all metric
Browse files Browse the repository at this point in the history
Signed-off-by: alanprot <alanprot@gmail.com>
  • Loading branch information
alanprot committed Dec 23, 2024
1 parent 960f7b6 commit 0a6c79c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
28 changes: 14 additions & 14 deletions pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/tsdb/expanded_postings_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/storage/tsdb/expanded_postings_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
Expand All @@ -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 {
Expand All @@ -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)
}
})
Expand Down

0 comments on commit 0a6c79c

Please sign in to comment.