From 4ae37f70eaed6d90488a16365c5a320ccca78caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Wed, 11 May 2022 20:25:04 +0300 Subject: [PATCH] groupcache: fix handling of slashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use https://github.com/julienschmidt/httprouter#catch-all-parameters for the groupcache route otherwise slashes in the cache's key gets interpreted by the router and thus groupcache's function never gets invoked, and all clients get 404. Remove test regarding cache hit because now Thanos Store during test constantly generates cache hits due to 1s delay between block information refreshes. Signed-off-by: Giedrius Statkevičius --- CHANGELOG.md | 1 + pkg/cache/groupcache.go | 2 +- test/e2e/store_gateway_test.go | 25 +++---------------------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19d100c06f..0a66874971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Fixed - [#5339](https://github.com/thanos-io/thanos/pull/5339) Receive: Fix deadlock on interrupt in routerOnly mode +- [#5357](https://github.com/thanos-io/thanos/pull/5357) Store: fix groupcache handling of slashes ### Added diff --git a/pkg/cache/groupcache.go b/pkg/cache/groupcache.go index 6e62112fba..ae46513852 100644 --- a/pkg/cache/groupcache.go +++ b/pkg/cache/groupcache.go @@ -150,7 +150,7 @@ func NewGroupcacheWithConfig(logger log.Logger, reg prometheus.Registerer, conf galaxyhttp.RegisterHTTPHandler(universe, &galaxyhttp.HTTPOptions{ BasePath: basepath, }, mux) - r.Get(filepath.Join(basepath, conf.GroupcacheGroup, ":key"), mux.ServeHTTP) + r.Get(filepath.Join(basepath, conf.GroupcacheGroup, "*key"), mux.ServeHTTP) galaxy := universe.NewGalaxy(conf.GroupcacheGroup, int64(conf.MaxSize), galaxycache.GetterFunc( func(ctx context.Context, id string, dest galaxycache.Codec) error { diff --git a/test/e2e/store_gateway_test.go b/test/e2e/store_gateway_test.go index 84599a1ee0..5fe6958141 100644 --- a/test/e2e/store_gateway_test.go +++ b/test/e2e/store_gateway_test.go @@ -493,28 +493,9 @@ metafile_content_ttl: 0s` } }) - t.Run("query with cache hit", func(t *testing.T) { - retrievedMetrics, err := store1.SumMetrics([]string{`thanos_cache_groupcache_hits_total`, `thanos_cache_groupcache_loads_total`, `thanos_cache_groupcache_get_requests_total`}) + t.Run("try to load file with slashes", func(t *testing.T) { + resp, err := http.Get(fmt.Sprintf("http://%s/_galaxycache/groupcache_test_group/content:%s/meta.json", store1.Endpoint("http"), id.String())) testutil.Ok(t, err) - testutil.Assert(t, len(retrievedMetrics) == 3) - - queryAndAssertSeries(t, ctx, q.Endpoint("http"), func() string { return testQuery }, - time.Now, promclient.QueryOptions{ - Deduplicate: false, - }, - []model.Metric{ - { - "a": "1", - "b": "2", - "ext1": "value1", - "replica": "1", - }, - }, - ) - - testutil.Ok(t, store1.WaitSumMetricsWithOptions(e2e.Greater(retrievedMetrics[0]), []string{`thanos_cache_groupcache_hits_total`})) - testutil.Ok(t, store1.WaitSumMetricsWithOptions(e2e.Equals(retrievedMetrics[1]), []string{`thanos_cache_groupcache_loads_total`})) - testutil.Ok(t, store1.WaitSumMetricsWithOptions(e2e.Greater(retrievedMetrics[2]), []string{`thanos_cache_groupcache_get_requests_total`})) - testutil.Ok(t, store2.WaitSumMetricsWithOptions(e2e.Greater(0), []string{`thanos_cache_groupcache_peer_loads_total`})) + testutil.Equals(t, 200, resp.StatusCode) }) }