Skip to content

Commit 66da475

Browse files
committed
Enable setting default chunk encoding by config file (#2077)
Signed-off-by: ChinYing-Li <[email protected]>
1 parent 8851245 commit 66da475

File tree

9 files changed

+45
-11
lines changed

9 files changed

+45
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* [ENHANCEMENT] Block Storage Ingester: `/flush` now accepts two new parameters: `tenant` to specify tenant to flush and `wait=true` to make call synchronous. Multiple tenants can be specified by repeating `tenant` parameter. If no `tenant` is specified, all tenants are flushed, as before. #4073
4444
* [ENHANCEMENT] Alertmanager: validate configured `-alertmanager.web.external-url` and fail if ends with `/`. #4081
4545
* [ENHANCEMENT] Allow configuration of Cassandra's host selection policy. #4069
46+
* [ENHANCEMENT] Ingester: enable setting default chunk encoding by config file. #4086
4647
* [BUGFIX] Ruler-API: fix bug where `/api/v1/rules/<namespace>/<group_name>` endpoint return `400` instead of `404`. #4013
4748
* [BUGFIX] Distributor: reverted changes done to rate limiting in #3825. #3948
4849
* [BUGFIX] Ingester: Fix race condition when opening and closing tsdb concurrently. #3959

development/tsdb-blocks-storage-s3-gossip/config/cortex.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ alertmanager_storage:
116116
storage:
117117
engine: blocks
118118

119+
encoding:
120+
chunk_encoding: big-chunk
121+
119122
compactor:
120123
compaction_interval: 30s
121124
data_dir: /tmp/cortex-compactor

development/tsdb-blocks-storage-s3-single-binary/config/cortex.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ blocks_storage:
6060
storage:
6161
engine: blocks
6262

63+
encoding:
64+
chunk_encoding: big-chunk
65+
6366
ruler:
6467
enable_api: true
6568
enable_sharding: true

development/tsdb-blocks-storage-s3/config/cortex.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ alertmanager_storage:
114114
storage:
115115
engine: blocks
116116

117+
encoding:
118+
chunk_encoding: big-chunk
119+
117120
compactor:
118121
compaction_interval: 30s
119122
data_dir: /tmp/cortex-compactor

development/tsdb-blocks-storage-swift-single-binary/config/cortex.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ blocks_storage:
6161
storage:
6262
engine: blocks
6363

64+
encoding:
65+
chunk_encoding: big-chunk
66+
6467
ruler:
6568
enable_api: true
6669
enable_sharding: true

docs/configuration/config-file-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ api:
130130
# The table_manager_config configures the Cortex table-manager.
131131
[table_manager: <table_manager_config>]
132132

133+
encoding:
134+
# Encoding version to use for chunks.
135+
# CLI flag: -encoding.chunk-encoding
136+
[chunk_encoding: <string> | default = "big-chunk"]
137+
133138
# The blocks_storage_config configures the blocks storage.
134139
[blocks_storage: <blocks_storage_config>]
135140

docs/guides/capacity-planning.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ Now, some rules of thumb:
5151
2. Each million series (including churn) consumes 15GB of chunk
5252
storage and 4GB of index, per day (so multiply by the retention
5353
period).
54-
3. Each 100,000 samples/sec arriving takes 1 CPU in distributors.
55-
Distributors don't need much RAM.
54+
3. The distributors CPU utilization depends on the specific Cortex cluster
55+
setup, while they don't need much RAM. Typically, distributors are capable
56+
to process between 20,000 and 100,000 samples/sec with 1 CPU core. It's also
57+
highly recommended to configure Prometheus `max_samples_per_send` to 1,000
58+
samples, in order to reduce the distributors CPU utilization given the same
59+
total samples/sec throughput.
5660

5761
If you turn on compression between distributors and ingesters (for
5862
example to save on inter-zone bandwidth charges at AWS/GCP) they will use

pkg/chunk/encoding/factory.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
type Encoding byte
1212

1313
// Config configures the behaviour of chunk encoding
14-
type Config struct{}
14+
type Config struct {
15+
EncodingName string `yaml:"chunk_encoding"`
16+
}
1517

1618
var (
1719
// DefaultEncoding exported for use in unit tests elsewhere
@@ -20,8 +22,8 @@ var (
2022
)
2123

2224
// RegisterFlags registers configuration settings.
23-
func (Config) RegisterFlags(f *flag.FlagSet) {
24-
f.Var(&DefaultEncoding, "ingester.chunk-encoding", "Encoding version to use for chunks.")
25+
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
26+
f.StringVar(&cfg.EncodingName, "encoding.chunk-encoding", "big-chunk", "Encoding version to use for chunks.")
2527
f.IntVar(&bigchunkSizeCapBytes, "store.bigchunk-size-cap-bytes", bigchunkSizeCapBytes, "When using bigchunk encoding, start a new bigchunk if over this size (0 = unlimited)")
2628
}
2729

@@ -63,25 +65,25 @@ type encoding struct {
6365

6466
var encodings = map[Encoding]encoding{
6567
DoubleDelta: {
66-
Name: "DoubleDelta",
68+
Name: "double-delta",
6769
New: func() Chunk {
6870
return newDoubleDeltaEncodedChunk(d1, d0, true, ChunkLen)
6971
},
7072
},
7173
Varbit: {
72-
Name: "Varbit",
74+
Name: "varbit",
7375
New: func() Chunk {
7476
return newVarbitChunk(varbitZeroEncoding)
7577
},
7678
},
7779
Bigchunk: {
78-
Name: "Bigchunk",
80+
Name: "big-chunk",
7981
New: func() Chunk {
8082
return newBigchunk()
8183
},
8284
},
8385
PrometheusXorChunk: {
84-
Name: "PrometheusXorChunk",
86+
Name: "prometheus-xor-chunk",
8587
New: func() Chunk {
8688
return newPrometheusXorChunk()
8789
},
@@ -90,7 +92,12 @@ var encodings = map[Encoding]encoding{
9092

9193
// Set implements flag.Value.
9294
func (e *Encoding) Set(s string) error {
93-
// First see if the name was given
95+
// If nothing is provided, keep the original value
96+
if s == "" {
97+
return nil
98+
}
99+
100+
// Then see if the name was given
94101
for k, v := range encodings {
95102
if s == v.Name {
96103
*e = k

pkg/cortex/cortex.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type Config struct {
108108
Frontend frontend.CombinedFrontendConfig `yaml:"frontend"`
109109
QueryRange queryrange.Config `yaml:"query_range"`
110110
TableManager chunk.TableManagerConfig `yaml:"table_manager"`
111-
Encoding encoding.Config `yaml:"-"` // No yaml for this, it only works with flags.
111+
Encoding encoding.Config `yaml:"encoding"`
112112
BlocksStorage tsdb.BlocksStorageConfig `yaml:"blocks_storage"`
113113
Compactor compactor.Config `yaml:"compactor"`
114114
StoreGateway storegateway.Config `yaml:"store_gateway"`
@@ -355,6 +355,11 @@ func New(cfg Config) (*Cortex, error) {
355355
Cfg: cfg,
356356
}
357357

358+
// Set default chunk encoding
359+
if err := encoding.DefaultEncoding.Set(cfg.Encoding.EncodingName); err != nil {
360+
return nil, err
361+
}
362+
358363
cortex.setupThanosTracing()
359364

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

0 commit comments

Comments
 (0)