Skip to content

Commit

Permalink
Address PR feedback, and add more details to failing assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Nov 16, 2023
1 parent 333ae6e commit 23602e3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions integration/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,17 @@ func TestQuerierWithBlocksStorageRunningInSingleBinaryMode(t *testing.T) {
require.NoError(t, err)
require.Equal(t, model.ValVector, result.Type())
assert.Equal(t, expectedVector1, result.(model.Vector))
expectedCacheRequests += seriesReplicationFactor * 4 // expanded postings, postings, series (retrieving labels and then while streaming chunks)
expectedCacheHits += seriesReplicationFactor // one for each series (for chunks)
expectedMemcachedOps += seriesReplicationFactor * (3*2 + 1) // Same reasoning as for expectedCacheRequests, but this also includes a set for each get that is not a hit
expectedCacheRequests += seriesReplicationFactor * 4 // expanded postings, postings, series (retrieving labels and then while streaming chunks)
expectedCacheHits += seriesReplicationFactor // one for each series (while streaming chunks)
expectedMemcachedOps += (seriesReplicationFactor * 4) + (seriesReplicationFactor * 3) // Same reasoning as for expectedCacheRequests, but this also includes a set for each get that is not a hit

result, err = c.Query(series2Name, series2Timestamp)
require.NoError(t, err)
require.Equal(t, model.ValVector, result.Type())
assert.Equal(t, expectedVector2, result.(model.Vector))
expectedCacheRequests += seriesReplicationFactor*4 + seriesReplicationFactor // expanded postings, postings, series for 1 time range; only expanded postings for another
expectedCacheHits += seriesReplicationFactor // one for each series
expectedMemcachedOps += seriesReplicationFactor * (4 + 3 + 1) // Same reasoning as for expectedCacheRequests, but this also includes a set for each get that is not a hit
expectedCacheRequests += seriesReplicationFactor*4 + seriesReplicationFactor // expanded postings, postings, series for 1 time range; only expanded postings for another
expectedCacheHits += seriesReplicationFactor // one for each series (while streaming chunks)
expectedMemcachedOps += (seriesReplicationFactor * 4) + (seriesReplicationFactor * 3) // Same reasoning as for expectedCacheRequests, but this also includes a set for each get that is not a hit

result, err = c.Query(series3Name, series3Timestamp)
require.NoError(t, err)
Expand All @@ -505,18 +505,18 @@ func TestQuerierWithBlocksStorageRunningInSingleBinaryMode(t *testing.T) {
expectedMemcachedOps += seriesReplicationFactor * 2

// Check the in-memory index cache metrics (in the store-gateway).
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheRequests)), "thanos_store_index_cache_requests_total"))
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheHits)), "thanos_store_index_cache_hits_total")) // no cache hit cause the cache was empty
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheRequests)), "thanos_store_index_cache_requests_total"), "expected %v requests", expectedCacheRequests)
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheHits)), "thanos_store_index_cache_hits_total"), "expected %v hits", expectedCacheHits)
if testCfg.indexCacheBackend == tsdb.IndexCacheBackendInMemory {
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64((2*2+2+3)*seriesReplicationFactor)), "thanos_store_index_cache_items")) // 2 series both for postings and series cache, 2 expanded postings on one block, 3 on another one
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64((2*2+2+3)*seriesReplicationFactor)), "thanos_store_index_cache_items_added_total")) // 2 series both for postings and series cache, 2 expanded postings on one block, 3 on another one
} else if testCfg.indexCacheBackend == tsdb.IndexCacheBackendMemcached {
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedMemcachedOps)), "thanos_memcached_operations_total"))
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedMemcachedOps)), "thanos_memcached_operations_total"), "expected %v operations", expectedMemcachedOps)
}

// Query back again the 1st series from storage. This time it should use the index cache.
// It should get a hit on expanded postings; this means that it will not request individual postings for matchers.
// It should get two hits on series (once for the labels, and again for the chunks).
// It should get two hits on series (once for the labels, and again for the labels when streaming chunks).
// We expect 3 cache requests and 3 cache hits.
result, err = c.Query(series1Name, series1Timestamp)
require.NoError(t, err)
Expand All @@ -526,14 +526,14 @@ func TestQuerierWithBlocksStorageRunningInSingleBinaryMode(t *testing.T) {
expectedCacheHits += seriesReplicationFactor * 3
expectedMemcachedOps += seriesReplicationFactor * 2 // there is no set after the gets this time

require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheRequests)), "thanos_store_index_cache_requests_total"))
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheHits)), "thanos_store_index_cache_hits_total")) // this time has used the index cache
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheRequests)), "thanos_store_index_cache_requests_total"), "expected %v requests", expectedCacheRequests)
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedCacheHits)), "thanos_store_index_cache_hits_total"), "expected %v hits", expectedCacheHits) // this time has used the index cache

if testCfg.indexCacheBackend == tsdb.IndexCacheBackendInMemory {
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64((2*2+2+3)*seriesReplicationFactor)), "thanos_store_index_cache_items")) // as before
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64((2*2+2+3)*seriesReplicationFactor)), "thanos_store_index_cache_items_added_total")) // as before
} else if testCfg.indexCacheBackend == tsdb.IndexCacheBackendMemcached {
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedMemcachedOps)), "thanos_memcached_operations_total"))
require.NoError(t, cluster.WaitSumMetrics(e2e.Equals(float64(expectedMemcachedOps)), "thanos_memcached_operations_total"), "expected %v operations", expectedMemcachedOps)
}

// Query metadata.
Expand Down

0 comments on commit 23602e3

Please sign in to comment.