Skip to content

Commit 634df35

Browse files
authored
Fix flaky on thanos_memcached_operations_total metrics (#5482)
* fix flaky on thanos_memcached_operations_total metrics Signed-off-by: Ben Ye <benye@amazon.com> * update comment Signed-off-by: Ben Ye <benye@amazon.com> --------- Signed-off-by: Ben Ye <benye@amazon.com>
1 parent e0bcca5 commit 634df35

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

integration/e2e/metrics.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ func LessOrEqual(value float64) func(sums ...float64) bool {
137137
}
138138
}
139139

140+
// EqualsAmong is an isExpected function for WaitSumMetrics that returns true if the first sum is equal to any value provided.
141+
func EqualsAmong(values ...float64) func(sums ...float64) bool {
142+
return func(sums ...float64) bool {
143+
if len(sums) != 1 {
144+
panic("equals among: expected one value")
145+
}
146+
for _, value := range values {
147+
if sums[0] == value {
148+
return true
149+
}
150+
}
151+
return false
152+
}
153+
}
154+
140155
// EqualsAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is equal to the second.
141156
// NOTE: Be careful on scrapes in between of process that changes two metrics. Those are
142157
// usually not atomic.

integration/querier_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,27 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
270270
require.Equal(t, model.ValVector, result.Type())
271271
assert.Equal(t, expectedVector1, result.(model.Vector))
272272

273+
var l0CacheHits float64
273274
if numberOfCacheBackends > 1 {
274275
// 6 requests for Expanded Postings, 5 for Postings and 3 for Series.
275276
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.Equals(float64(6+5+3)), []string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
276277
labels.MustNewMatcher(labels.MatchEqual, "level", "L0"),
277278
)))
278279
// In case of L0 cache hits, store gateway might send fewer requests. Should be within range 12 ~ 14.
279-
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.GreaterOrEqual(float64(12)), []string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
280+
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.EqualsAmong(float64(12), float64(14)), []string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
280281
labels.MustNewMatcher(labels.MatchEqual, "level", "L1"),
281282
)))
282-
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.LessOrEqual(float64(14)), []string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
283+
l1IndexCacheRequests, err := storeGateways.SumMetrics([]string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
283284
labels.MustNewMatcher(labels.MatchEqual, "level", "L1"),
284-
)))
285+
))
286+
require.NoError(t, err)
287+
l0IndexCacheHits, err := storeGateways.SumMetrics([]string{"thanos_store_index_cache_hits_total"}, e2e.WithLabelMatchers(
288+
labels.MustNewMatcher(labels.MatchEqual, "level", "L0"),
289+
))
290+
require.NoError(t, err)
291+
// Make sure l1 cache requests + l0 cache hits is 14.
292+
require.Equal(t, float64(14), l1IndexCacheRequests[0]+l0IndexCacheHits[0])
293+
l0CacheHits = l0IndexCacheHits[0]
285294
} else {
286295
// 6 requests for Expanded Postings, 5 for Postings and 3 for Series.
287296
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(float64(6+5+3)), "thanos_store_index_cache_requests_total"))
@@ -293,7 +302,7 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
293302
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(9), "thanos_store_index_cache_items_added_total")) // as before
294303
}
295304
if strings.Contains(testCfg.indexCacheBackend, tsdb.IndexCacheBackendMemcached) {
296-
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(23), "thanos_memcached_operations_total")) // as before + 2 gets
305+
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(23-l0CacheHits), "thanos_memcached_operations_total")) // as before + 2 gets - cache hits
297306
}
298307

299308
// Query metadata.

0 commit comments

Comments
 (0)