-
Notifications
You must be signed in to change notification settings - Fork 544
/
Copy pathconfig.go
182 lines (153 loc) · 6.18 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package tempodb
import (
"errors"
"flag"
"fmt"
"time"
"github.com/grafana/tempo/modules/cache/memcached"
"github.com/grafana/tempo/modules/cache/redis"
"github.com/grafana/tempo/pkg/cache"
"github.com/grafana/tempo/tempodb/backend/azure"
backend_cache "github.com/grafana/tempo/tempodb/backend/cache"
"github.com/grafana/tempo/tempodb/backend/gcs"
"github.com/grafana/tempo/tempodb/backend/local"
"github.com/grafana/tempo/tempodb/backend/s3"
"github.com/grafana/tempo/tempodb/encoding"
"github.com/grafana/tempo/tempodb/encoding/common"
"github.com/grafana/tempo/tempodb/pool"
"github.com/grafana/tempo/tempodb/wal"
)
const (
DefaultBlocklistPoll = 5 * time.Minute
DefaultMaxTimePerTenant = 5 * time.Minute
DefaultBlocklistPollConcurrency = uint(50)
DefaultBlocklistPollTenantConcurrency = uint(1)
DefaultRetentionConcurrency = uint(10)
DefaultTenantIndexBuilders = 2
DefaultTolerateConsecutiveErrors = 1
DefaultTolerateTenantFailures = 1
DefaultEmptyTenantDeletionAge = 12 * time.Hour
DefaultPrefetchTraceCount = 1000
DefaultSearchChunkSizeBytes = 1_000_000
DefaultReadBufferCount = 32
DefaultReadBufferSize = 1 * 1024 * 1024
)
// Config holds the entirety of tempodb configuration
// Defaults are in modules/storage/config.go
type Config struct {
Pool *pool.Config `yaml:"pool,omitempty"`
WAL *wal.Config `yaml:"wal"`
Block *common.BlockConfig `yaml:"block"`
Search *SearchConfig `yaml:"search"`
BlocklistPoll time.Duration `yaml:"blocklist_poll"`
BlocklistPollConcurrency uint `yaml:"blocklist_poll_concurrency"`
BlocklistPollTenantConcurrency uint `yaml:"blocklist_poll_tenant_concurrency"`
BlocklistPollFallback bool `yaml:"blocklist_poll_fallback"`
BlocklistPollTenantIndexBuilders int `yaml:"blocklist_poll_tenant_index_builders"`
BlocklistPollStaleTenantIndex time.Duration `yaml:"blocklist_poll_stale_tenant_index"`
BlocklistPollJitterMs int `yaml:"blocklist_poll_jitter_ms"`
BlocklistPollTolerateConsecutiveErrors int `yaml:"blocklist_poll_tolerate_consecutive_errors"`
BlocklistPollTolerateTenantFailures int `yaml:"blocklist_poll_tolerate_tenant_failures"`
EmptyTenantDeletionEnabled bool `yaml:"empty_tenant_deletion_enabled"`
EmptyTenantDeletionAge time.Duration `yaml:"empty_tenant_deletion_age"`
// backends
Backend string `yaml:"backend"`
Local *local.Config `yaml:"local"`
GCS *gcs.Config `yaml:"gcs"`
S3 *s3.Config `yaml:"s3"`
Azure *azure.Config `yaml:"azure"`
// legacy cache config. this is loaded by tempodb and added to the cache
// provider on construction
Cache string `yaml:"cache"`
BackgroundCache *cache.BackgroundConfig `yaml:"background_cache"`
Memcached *memcached.Config `yaml:"memcached"`
Redis *redis.Config `yaml:"redis"`
BloomCacheCfg backend_cache.BloomConfig `yaml:",inline"`
}
type CacheControlConfig struct {
Footer bool `yaml:"footer"`
ColumnIndex bool `yaml:"column_index"`
OffsetIndex bool `yaml:"offset_index"`
}
type SearchConfig struct {
// v2 blocks
ChunkSizeBytes uint32 `yaml:"chunk_size_bytes"`
PrefetchTraceCount int `yaml:"prefetch_trace_count"`
// vParquet blocks
ReadBufferCount int `yaml:"read_buffer_count"`
ReadBufferSizeBytes int `yaml:"read_buffer_size_bytes"`
// todo: consolidate caching config in one spot
CacheControl CacheControlConfig `yaml:"cache_control"`
}
func (c *SearchConfig) RegisterFlagsAndApplyDefaults(string, *flag.FlagSet) {
c.ChunkSizeBytes = DefaultSearchChunkSizeBytes
c.PrefetchTraceCount = DefaultPrefetchTraceCount
c.ReadBufferCount = DefaultReadBufferCount
c.ReadBufferSizeBytes = DefaultReadBufferSize
}
func (c SearchConfig) ApplyToOptions(o *common.SearchOptions) {
o.ChunkSizeBytes = c.ChunkSizeBytes
o.PrefetchTraceCount = c.PrefetchTraceCount
o.ReadBufferCount = c.ReadBufferCount
o.ReadBufferSize = c.ReadBufferSizeBytes
if o.ChunkSizeBytes == 0 {
o.ChunkSizeBytes = DefaultSearchChunkSizeBytes
}
if o.PrefetchTraceCount <= 0 {
o.PrefetchTraceCount = DefaultPrefetchTraceCount
}
if o.ReadBufferSize <= 0 {
o.ReadBufferSize = DefaultReadBufferSize
}
if o.ReadBufferCount <= 0 {
o.ReadBufferCount = DefaultReadBufferCount
}
}
// CompactorConfig contains compaction configuration options
type CompactorConfig struct {
ChunkSizeBytes uint32 `yaml:"v2_in_buffer_bytes"`
FlushSizeBytes uint32 `yaml:"v2_out_buffer_bytes"`
IteratorBufferSize int `yaml:"v2_prefetch_traces_count"`
MaxCompactionRange time.Duration `yaml:"compaction_window"`
MaxCompactionObjects int `yaml:"max_compaction_objects"`
MaxBlockBytes uint64 `yaml:"max_block_bytes"`
BlockRetention time.Duration `yaml:"block_retention"`
CompactedBlockRetention time.Duration `yaml:"compacted_block_retention"`
RetentionConcurrency uint `yaml:"retention_concurrency"`
MaxTimePerTenant time.Duration `yaml:"max_time_per_tenant"`
CompactionCycle time.Duration `yaml:"compaction_cycle"`
}
func (compactorConfig CompactorConfig) validate() error {
if compactorConfig.MaxCompactionRange == 0 {
return errors.New("Compaction window can't be 0")
}
return nil
}
func validateConfig(cfg *Config) error {
if cfg == nil {
return errors.New("config should be non-nil")
}
if cfg.WAL == nil {
return errors.New("wal config should be non-nil")
}
if cfg.Block == nil {
return errors.New("block config should be non-nil")
}
// if the wal version is unspecified default to the block version
if cfg.WAL.Version == "" {
cfg.WAL.Version = cfg.Block.Version
}
err := cfg.WAL.Validate()
if err != nil {
return fmt.Errorf("wal config validation failed: %w", err)
}
err = common.ValidateConfig(cfg.Block)
if err != nil {
return fmt.Errorf("block config validation failed: %w", err)
}
_, err = encoding.FromVersion(cfg.Block.Version)
if err != nil {
return fmt.Errorf("block version validation failed: %w", err)
}
return nil
}