Skip to content

Commit 8587ea6

Browse files
authored
support snappy cache in query frontend (#3217)
* support snappy cache in query frontend Signed-off-by: Ben Ye <[email protected]> * add changelog Signed-off-by: Ben Ye <[email protected]> * add supported compression type check Signed-off-by: Ben Ye <[email protected]>
1 parent 22f2efd commit 8587ea6

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [CHANGE] Zone-awareness replication for time-series now should be explicitly enabled in the distributor via the `-distributor.zone-awareness-enabled` CLI flag (or its respective YAML config option). Before, zone-aware replication was implicitly enabled if a zone was set on ingesters. #3200
1111
* [CHANGE] Removed the deprecated CLI flag `-config-yaml`. You should use `-schema-config-file` instead. #3225
1212
* [FEATURE] Added support for shuffle-sharding queriers in the query-frontend. When configured (`-frontend.max-queriers-per-user` globally, or using per-user limit `max_queriers_per_user`), each user's requests will be handled by different set of queriers. #3113
13+
* [FEATURE] Query-frontend: added `compression` config to support results cache with compression. #3217
1314
* [ENHANCEMENT] Added `cortex_query_frontend_connected_clients` metric to show the number of workers currently connected to the frontend. #3207
1415
* [ENHANCEMENT] Shuffle sharding: improved shuffle sharding in the write path. Shuffle sharding now should be explicitly enabled via `-distributor.sharding-strategy` CLI flag (or its respective YAML config option) and guarantees stability, consistency, shuffling and balanced zone-awareness properties. #3090
1516
* [ENHANCEMENT] Ingester: added new metric `cortex_ingester_active_series` to track active series more accurately. Also added options to control whether active series tracking is enabled (`-ingester.active-series-enabled`, defaults to false), and how often this metric is updated (`-ingester.active-series-update-period`) and max idle time for series to be considered inactive (`-ingester.active-series-idle-timeout`). #3153

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ results_cache:
817817
# The CLI flags prefix for this block config is: frontend
818818
[fifocache: <fifo_cache_config>]
819819
820+
# Use compression in results cache. Supported values are: 'snappy' and ''
821+
# (disable compression).
822+
# CLI flag: -frontend.compression
823+
[compression: <string> | default = ""]
824+
820825
# Cache query results.
821826
# CLI flag: -querier.cache-results
822827
[cache_results: <boolean> | default = false]

pkg/querier/queryrange/results_cache.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/gogo/protobuf/types"
1515
"github.com/opentracing/opentracing-go"
1616
otlog "github.com/opentracing/opentracing-go/log"
17+
"github.com/pkg/errors"
1718
"github.com/prometheus/client_golang/prometheus"
1819
"github.com/prometheus/common/model"
1920
"github.com/uber/jaeger-client-go"
@@ -41,15 +42,28 @@ type CacheGenNumberLoader interface {
4142
// ResultsCacheConfig is the config for the results cache.
4243
type ResultsCacheConfig struct {
4344
CacheConfig cache.Config `yaml:"cache"`
45+
Compression string `yaml:"compression"`
4446
}
4547

4648
// RegisterFlags registers flags.
4749
func (cfg *ResultsCacheConfig) RegisterFlags(f *flag.FlagSet) {
4850
cfg.CacheConfig.RegisterFlagsWithPrefix("frontend.", "", f)
4951

52+
f.StringVar(&cfg.Compression, "frontend.compression", "", "Use compression in results cache. Supported values are: 'snappy' and '' (disable compression).")
5053
flagext.DeprecatedFlag(f, "frontend.cache-split-interval", "Deprecated: The maximum interval expected for each request, results will be cached per single interval. This behavior is now determined by querier.split-queries-by-interval.")
5154
}
5255

56+
func (cfg *ResultsCacheConfig) Validate() error {
57+
switch cfg.Compression {
58+
case "snappy", "":
59+
// valid
60+
default:
61+
return errors.Errorf("unsupported compression type: %s", cfg.Compression)
62+
}
63+
64+
return cfg.CacheConfig.Validate()
65+
}
66+
5367
// Extractor is used by the cache to extract a subset of a response from a cache entry.
5468
type Extractor interface {
5569
// Extract extracts a subset of a response from the `start` and `end` timestamps in milliseconds in the `from` response.
@@ -140,6 +154,9 @@ func NewResultsCacheMiddleware(
140154
if err != nil {
141155
return nil, nil, err
142156
}
157+
if cfg.Compression == "snappy" {
158+
c = cache.NewSnappy(c, logger)
159+
}
143160

144161
if cacheGenNumberLoader != nil {
145162
c = cache.NewCacheGenNumMiddleware(c)

pkg/querier/queryrange/results_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func TestShouldCache(t *testing.T) {
261261
}
262262
}
263263

264-
func TestPartiton(t *testing.T) {
264+
func TestPartition(t *testing.T) {
265265
for i, tc := range []struct {
266266
input Request
267267
prevCachedResponse []Extent

pkg/querier/queryrange/roundtrip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (cfg *Config) Validate(log log.Logger) error {
8282
if cfg.SplitQueriesByInterval <= 0 {
8383
return errors.New("querier.cache-results may only be enabled in conjunction with querier.split-queries-by-interval. Please set the latter")
8484
}
85-
if err := cfg.ResultsCacheConfig.CacheConfig.Validate(); err != nil {
85+
if err := cfg.ResultsCacheConfig.Validate(); err != nil {
8686
return errors.Wrap(err, "invalid ResultsCache config")
8787
}
8888
}

0 commit comments

Comments
 (0)