Skip to content

Enable setting default chunk encoding by config file (#2077) #4086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master / unreleased

* [CHANGE] Querier / ruler: deprecated `-store.query-chunk-limit` CLI flag (and its respective YAML config option `max_chunks_per_query`) in favour of `-querier.max-fetched-chunks-per-query` (and its respective YAML config option `max_fetched_chunks_per_query`). The new limit specifies the maximum number of chunks that can be fetched in a single query from ingesters and long-term storage: the total number of actual fetched chunks could be 2x the limit, being independently applied when querying ingesters and long-term storage. #4125
* [ENHANCEMENT] Ingester: enable setting default chunk encoding by config file. #4086

## 1.9.0 in progress

Expand Down
3 changes: 3 additions & 0 deletions development/tsdb-blocks-storage-s3-gossip/config/cortex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ alertmanager_storage:
storage:
engine: blocks

encoding:
chunk_encoding: BigChunk

compactor:
compaction_interval: 30s
data_dir: /tmp/cortex-compactor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ blocks_storage:
storage:
engine: blocks

encoding:
chunk_encoding: BigChunk

ruler:
enable_api: true
enable_sharding: true
Expand Down
3 changes: 3 additions & 0 deletions development/tsdb-blocks-storage-s3/config/cortex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ alertmanager_storage:
storage:
engine: blocks

encoding:
chunk_encoding: BigChunk

compactor:
compaction_interval: 30s
data_dir: /tmp/cortex-compactor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ blocks_storage:
storage:
engine: blocks

encoding:
chunk_encoding: BigChunk

ruler:
enable_api: true
enable_sharding: true
Expand Down
5 changes: 5 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ api:
# The table_manager_config configures the Cortex table-manager.
[table_manager: <table_manager_config>]

encoding:
# Encoding version to use for chunks.
# CLI flag: -encoding.chunk-encoding
[chunk_encoding: <string> | default = "BigChunk"]

# The blocks_storage_config configures the blocks storage.
[blocks_storage: <blocks_storage_config>]

Expand Down
17 changes: 12 additions & 5 deletions pkg/chunk/encoding/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
type Encoding byte

// Config configures the behaviour of chunk encoding
type Config struct{}
type Config struct {
EncodingName string `yaml:"chunk_encoding"`
}

var (
// DefaultEncoding exported for use in unit tests elsewhere
Expand All @@ -20,8 +22,8 @@ var (
)

// RegisterFlags registers configuration settings.
func (Config) RegisterFlags(f *flag.FlagSet) {
f.Var(&DefaultEncoding, "ingester.chunk-encoding", "Encoding version to use for chunks.")
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cfg.EncodingName, "encoding.chunk-encoding", "BigChunk", "Encoding version to use for chunks.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't change CLI flag names or default values, otherwise we break our backward compatibility guarantee (see https://cortexmetrics.io/docs/configuration/v1guarantees/).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reminding!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pracucci Is it allowed to set a value using different names in CLI and json?
E.g. set DefaultEnconding using the CLI flag ingester.chunk-encoding, but set it as

encoding:  
  chunk_encoding: BigChunk 

in yaml config files?

f.IntVar(&bigchunkSizeCapBytes, "store.bigchunk-size-cap-bytes", bigchunkSizeCapBytes, "When using bigchunk encoding, start a new bigchunk if over this size (0 = unlimited)")
}

Expand Down Expand Up @@ -75,7 +77,7 @@ var encodings = map[Encoding]encoding{
},
},
Bigchunk: {
Name: "Bigchunk",
Name: "BigChunk",
New: func() Chunk {
return newBigchunk()
},
Expand All @@ -90,7 +92,12 @@ var encodings = map[Encoding]encoding{

// Set implements flag.Value.
func (e *Encoding) Set(s string) error {
// First see if the name was given
// If nothing is provided, keep the original value
if s == "" {
return nil
}

// Then see if the name was given
for k, v := range encodings {
if s == v.Name {
*e = k
Expand Down
7 changes: 6 additions & 1 deletion pkg/cortex/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type Config struct {
Frontend frontend.CombinedFrontendConfig `yaml:"frontend"`
QueryRange queryrange.Config `yaml:"query_range"`
TableManager chunk.TableManagerConfig `yaml:"table_manager"`
Encoding encoding.Config `yaml:"-"` // No yaml for this, it only works with flags.
Encoding encoding.Config `yaml:"encoding"`
BlocksStorage tsdb.BlocksStorageConfig `yaml:"blocks_storage"`
Compactor compactor.Config `yaml:"compactor"`
StoreGateway storegateway.Config `yaml:"store_gateway"`
Expand Down Expand Up @@ -355,6 +355,11 @@ func New(cfg Config) (*Cortex, error) {
Cfg: cfg,
}

// Set default chunk encoding
if err := encoding.DefaultEncoding.Set(cfg.Encoding.EncodingName); err != nil {
return nil, err
}

cortex.setupThanosTracing()

if err := cortex.setupModuleManager(); err != nil {
Expand Down