Skip to content

Commit 39761ee

Browse files
authored
Replace EnableNativeHistograms from TSDB config with PerTenant Limit (#6718)
* Removing EnableNativeHistograms from TSDB config and replacing with EnableNativeHistogramPerUser limit Signed-off-by: Paurush Garg <[email protected]> * Adding experimental flag Signed-off-by: Paurush Garg <[email protected]> * Adding changelog entry and make doc Signed-off-by: Paurush Garg <[email protected]> * Updating to keep the EnableNativeHistograms limit name same as existing config name Signed-off-by: Paurush Garg <[email protected]> --------- Signed-off-by: Paurush Garg <[email protected]>
1 parent 59e7d6c commit 39761ee

File tree

8 files changed

+44
-37
lines changed

8 files changed

+44
-37
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## master / unreleased
4+
* [CHANGE] Ingester: Remove EnableNativeHistograms config flag and instead gate keep through new per-tenant limit at ingestion. #6718
45
* [CHANGE] StoreGateway/Alertmanager: Add default 5s connection timeout on client. #6603
56
* [FEATURE] Query Frontend: Add dynamic interval size for query splitting. This is enabled by configuring experimental flags `querier.max-shards-per-query` and/or `querier.max-fetched-data-duration-per-query`. The split interval size is dynamically increased to maintain a number of shards and total duration fetched below the configured values. #6458
67
* [FEATURE] Querier/Ruler: Add `query_partial_data` and `rules_partial_data` limits to allow queries/rules to be evaluated with data from a single zone, if other zones are not available. #6526

docs/blocks-storage/querier.md

-4
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,6 @@ blocks_storage:
15611561
# CLI flag: -blocks-storage.tsdb.out-of-order-cap-max
15621562
[out_of_order_cap_max: <int> | default = 32]
15631563

1564-
# [EXPERIMENTAL] True to enable native histogram.
1565-
# CLI flag: -blocks-storage.tsdb.enable-native-histograms
1566-
[enable_native_histograms: <boolean> | default = false]
1567-
15681564
# [EXPERIMENTAL] If enabled, ingesters will cache expanded postings when
15691565
# querying blocks. Caching can be configured separately for the head and
15701566
# compacted blocks.

docs/blocks-storage/store-gateway.md

-4
Original file line numberDiff line numberDiff line change
@@ -1679,10 +1679,6 @@ blocks_storage:
16791679
# CLI flag: -blocks-storage.tsdb.out-of-order-cap-max
16801680
[out_of_order_cap_max: <int> | default = 32]
16811681

1682-
# [EXPERIMENTAL] True to enable native histogram.
1683-
# CLI flag: -blocks-storage.tsdb.enable-native-histograms
1684-
[enable_native_histograms: <boolean> | default = false]
1685-
16861682
# [EXPERIMENTAL] If enabled, ingesters will cache expanded postings when
16871683
# querying blocks. Caching can be configured separately for the head and
16881684
# compacted blocks.

docs/configuration/config-file-reference.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2130,10 +2130,6 @@ tsdb:
21302130
# CLI flag: -blocks-storage.tsdb.out-of-order-cap-max
21312131
[out_of_order_cap_max: <int> | default = 32]
21322132

2133-
# [EXPERIMENTAL] True to enable native histogram.
2134-
# CLI flag: -blocks-storage.tsdb.enable-native-histograms
2135-
[enable_native_histograms: <boolean> | default = false]
2136-
21372133
# [EXPERIMENTAL] If enabled, ingesters will cache expanded postings when
21382134
# querying blocks. Caching can be configured separately for the head and
21392135
# compacted blocks.
@@ -3516,6 +3512,10 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s
35163512
# [max_series]
35173513
[limits_per_label_set: <list of LimitsPerLabelSet> | default = []]
35183514
3515+
# [EXPERIMENTAL] True to enable native histogram.
3516+
# CLI flag: -blocks-storage.tsdb.enable-native-histograms
3517+
[enable_native_histograms: <boolean> | default = false]
3518+
35193519
# The maximum number of active metrics with metadata per user, per ingester. 0
35203520
# to disable.
35213521
# CLI flag: -ingester.max-metadata-per-user

pkg/ingester/ingester.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13471347
return nil, wrapWithUser(err, userID)
13481348
}
13491349

1350-
if i.cfg.BlocksStorageConfig.TSDB.EnableNativeHistograms {
1350+
if i.limits.EnableNativeHistograms(userID) {
13511351
for _, hp := range ts.Histograms {
13521352
var (
13531353
err error
@@ -1494,7 +1494,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
14941494
i.validateMetrics.DiscardedSamples.WithLabelValues(perLabelsetSeriesLimit, userID).Add(float64(perLabelSetSeriesLimitCount))
14951495
}
14961496

1497-
if !i.cfg.BlocksStorageConfig.TSDB.EnableNativeHistograms && discardedNativeHistogramCount > 0 {
1497+
if !i.limits.EnableNativeHistograms(userID) && discardedNativeHistogramCount > 0 {
14981498
i.validateMetrics.DiscardedSamples.WithLabelValues(nativeHistogramSample, userID).Add(float64(discardedNativeHistogramCount))
14991499
}
15001500

@@ -2449,9 +2449,9 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
24492449
EnableMemorySnapshotOnShutdown: i.cfg.BlocksStorageConfig.TSDB.MemorySnapshotOnShutdown,
24502450
OutOfOrderTimeWindow: time.Duration(oooTimeWindow).Milliseconds(),
24512451
OutOfOrderCapMax: i.cfg.BlocksStorageConfig.TSDB.OutOfOrderCapMax,
2452-
EnableOOONativeHistograms: i.cfg.BlocksStorageConfig.TSDB.EnableNativeHistograms, // Automatically enabled when EnableNativeHistograms is true.
2453-
EnableOverlappingCompaction: false, // Always let compactors handle overlapped blocks, e.g. OOO blocks.
2454-
EnableNativeHistograms: i.cfg.BlocksStorageConfig.TSDB.EnableNativeHistograms,
2452+
EnableOOONativeHistograms: true,
2453+
EnableOverlappingCompaction: false, // Always let compactors handle overlapped blocks, e.g. OOO blocks.
2454+
EnableNativeHistograms: true, // Always enable Native Histograms. Gate keeping is done though a per-tenant limit at ingestion.
24552455
BlockChunkQuerierFunc: i.blockChunkQuerierFunc(userID),
24562456
}, nil)
24572457
if err != nil {

pkg/ingester/ingester_test.go

+27-16
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func seriesSetFromResponseStream(s *mockQueryStreamServer) (storage.SeriesSet, e
124124

125125
func TestMatcherCache(t *testing.T) {
126126
limits := defaultLimitsTestConfig()
127+
limits.EnableNativeHistograms = true
127128
userID := "1"
128129
tenantLimits := newMockTenantLimits(map[string]*validation.Limits{userID: &limits})
129130
registry := prometheus.NewRegistry()
@@ -135,7 +136,7 @@ func TestMatcherCache(t *testing.T) {
135136
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
136137
cfg := defaultIngesterTestConfig(t)
137138
cfg.MatchersCacheMaxItems = 50
138-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, registry, true)
139+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, registry)
139140
require.NoError(t, err)
140141
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
141142

@@ -204,7 +205,7 @@ func TestIngesterDeletionRace(t *testing.T) {
204205
require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
205206
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
206207

207-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, registry, false)
208+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, registry)
208209
require.NoError(t, err)
209210
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
210211
defer services.StopAndAwaitTerminated(context.Background(), ing) //nolint:errcheck
@@ -254,6 +255,7 @@ func TestIngesterDeletionRace(t *testing.T) {
254255

255256
func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
256257
limits := defaultLimitsTestConfig()
258+
limits.EnableNativeHistograms = true
257259
userID := "1"
258260
registry := prometheus.NewRegistry()
259261

@@ -287,7 +289,7 @@ func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
287289
require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
288290
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
289291

290-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry, true)
292+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry)
291293
require.NoError(t, err)
292294
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
293295
// Wait until it's ACTIVE
@@ -630,7 +632,7 @@ func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
630632
// Should persist between restarts
631633
services.StopAndAwaitTerminated(context.Background(), ing) //nolint:errcheck
632634
registry = prometheus.NewRegistry()
633-
ing, err = prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry, true)
635+
ing, err = prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, tenantLimits, blocksDir, registry)
634636
require.NoError(t, err)
635637
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
636638
ing.updateActiveSeries(ctx)
@@ -661,6 +663,7 @@ func TestIngesterPerLabelsetLimitExceeded(t *testing.T) {
661663
func TestPushRace(t *testing.T) {
662664
cfg := defaultIngesterTestConfig(t)
663665
l := defaultLimitsTestConfig()
666+
l.EnableNativeHistograms = true
664667
cfg.LabelsStringInterningEnabled = true
665668
cfg.LifecyclerConfig.JoinAfter = 0
666669

@@ -686,7 +689,7 @@ func TestPushRace(t *testing.T) {
686689
blocksDir := filepath.Join(dir, "blocks")
687690
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
688691

689-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, l, nil, blocksDir, prometheus.NewRegistry(), true)
692+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, l, nil, blocksDir, prometheus.NewRegistry())
690693
require.NoError(t, err)
691694
defer services.StopAndAwaitTerminated(context.Background(), ing) //nolint:errcheck
692695
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
@@ -747,6 +750,7 @@ func TestPushRace(t *testing.T) {
747750

748751
func TestIngesterUserLimitExceeded(t *testing.T) {
749752
limits := defaultLimitsTestConfig()
753+
limits.EnableNativeHistograms = true
750754
limits.MaxLocalSeriesPerUser = 1
751755
limits.MaxLocalMetricsWithMetadataPerUser = 1
752756

@@ -778,7 +782,7 @@ func TestIngesterUserLimitExceeded(t *testing.T) {
778782
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
779783

780784
blocksIngesterGenerator := func(reg prometheus.Registerer) *Ingester {
781-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, nil, blocksDir, reg, true)
785+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, nil, blocksDir, reg)
782786
require.NoError(t, err)
783787
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
784788
// Wait until it's ACTIVE
@@ -878,6 +882,7 @@ func benchmarkData(nSeries int) (allLabels []labels.Labels, allSamples []cortexp
878882

879883
func TestIngesterMetricLimitExceeded(t *testing.T) {
880884
limits := defaultLimitsTestConfig()
885+
limits.EnableNativeHistograms = true
881886
limits.MaxLocalSeriesPerMetric = 1
882887
limits.MaxLocalMetadataPerMetric = 1
883888

@@ -909,7 +914,7 @@ func TestIngesterMetricLimitExceeded(t *testing.T) {
909914
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
910915

911916
blocksIngesterGenerator := func(reg prometheus.Registerer) *Ingester {
912-
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, nil, blocksDir, reg, true)
917+
ing, err := prepareIngesterWithBlocksStorageAndLimits(t, defaultIngesterTestConfig(t), limits, nil, blocksDir, reg)
913918
require.NoError(t, err)
914919
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ing))
915920
// Wait until it's ACTIVE
@@ -1933,6 +1938,7 @@ func TestIngester_Push(t *testing.T) {
19331938
cfg.ActiveSeriesMetricsEnabled = !testData.disableActiveSeries
19341939

19351940
limits := defaultLimitsTestConfig()
1941+
limits.EnableNativeHistograms = !testData.disableNativeHistogram
19361942
limits.MaxExemplars = testData.maxExemplars
19371943
limits.OutOfOrderTimeWindow = model.Duration(testData.oooTimeWindow)
19381944
limits.LimitsPerLabelSet = []validation.LimitsPerLabelSet{
@@ -1945,7 +1951,7 @@ func TestIngester_Push(t *testing.T) {
19451951
Hash: 1,
19461952
},
19471953
}
1948-
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, "", registry, !testData.disableNativeHistogram)
1954+
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, "", registry)
19491955
require.NoError(t, err)
19501956
require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
19511957
defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
@@ -2174,7 +2180,8 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) {
21742180
cfg.LifecyclerConfig.JoinAfter = 0
21752181

21762182
limits := defaultLimitsTestConfig()
2177-
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, "", registry, true)
2183+
limits.EnableNativeHistograms = true
2184+
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, "", registry)
21782185
require.NoError(t, err)
21792186
require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
21802187
defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
@@ -2662,6 +2669,7 @@ func Benchmark_Ingester_PushOnError(b *testing.B) {
26622669
cfg.LifecyclerConfig.JoinAfter = 0
26632670

26642671
limits := defaultLimitsTestConfig()
2672+
limits.EnableNativeHistograms = true
26652673
if !testData.prepareConfig(&limits, instanceLimits) {
26662674
b.SkipNow()
26672675
}
@@ -2670,7 +2678,7 @@ func Benchmark_Ingester_PushOnError(b *testing.B) {
26702678
return instanceLimits
26712679
}
26722680

2673-
ingester, err := prepareIngesterWithBlocksStorageAndLimits(b, cfg, limits, nil, "", registry, true)
2681+
ingester, err := prepareIngesterWithBlocksStorageAndLimits(b, cfg, limits, nil, "", registry)
26742682
require.NoError(b, err)
26752683
require.NoError(b, services.StartAndAwaitRunning(context.Background(), ingester))
26762684
defer services.StopAndAwaitTerminated(context.Background(), ingester) //nolint:errcheck
@@ -3947,10 +3955,12 @@ func mockHistogramWriteRequest(t *testing.T, lbls labels.Labels, value int64, ti
39473955
}
39483956

39493957
func prepareIngesterWithBlocksStorage(t testing.TB, ingesterCfg Config, registerer prometheus.Registerer) (*Ingester, error) {
3950-
return prepareIngesterWithBlocksStorageAndLimits(t, ingesterCfg, defaultLimitsTestConfig(), nil, "", registerer, true)
3958+
limits := defaultLimitsTestConfig()
3959+
limits.EnableNativeHistograms = true
3960+
return prepareIngesterWithBlocksStorageAndLimits(t, ingesterCfg, limits, nil, "", registerer)
39513961
}
39523962

3953-
func prepareIngesterWithBlocksStorageAndLimits(t testing.TB, ingesterCfg Config, limits validation.Limits, tenantLimits validation.TenantLimits, dataDir string, registerer prometheus.Registerer, nativeHistograms bool) (*Ingester, error) {
3963+
func prepareIngesterWithBlocksStorageAndLimits(t testing.TB, ingesterCfg Config, limits validation.Limits, tenantLimits validation.TenantLimits, dataDir string, registerer prometheus.Registerer) (*Ingester, error) {
39543964
// Create a data dir if none has been provided.
39553965
if dataDir == "" {
39563966
dataDir = t.TempDir()
@@ -3966,7 +3976,6 @@ func prepareIngesterWithBlocksStorageAndLimits(t testing.TB, ingesterCfg Config,
39663976
ingesterCfg.BlocksStorageConfig.TSDB.Dir = dataDir
39673977
ingesterCfg.BlocksStorageConfig.Bucket.Backend = "filesystem"
39683978
ingesterCfg.BlocksStorageConfig.Bucket.Filesystem.Directory = bucketDir
3969-
ingesterCfg.BlocksStorageConfig.TSDB.EnableNativeHistograms = nativeHistograms
39703979

39713980
ingester, err := New(ingesterCfg, overrides, registerer, log.NewNopLogger(), nil)
39723981
if err != nil {
@@ -6432,15 +6441,16 @@ func TestIngester_MaxExemplarsFallBack(t *testing.T) {
64326441
dir := t.TempDir()
64336442
blocksDir := filepath.Join(dir, "blocks")
64346443
limits := defaultLimitsTestConfig()
6435-
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, blocksDir, prometheus.NewRegistry(), true)
6444+
limits.EnableNativeHistograms = true
6445+
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, blocksDir, prometheus.NewRegistry())
64366446
require.NoError(t, err)
64376447

64386448
maxExemplars := i.getMaxExemplars("someTenant")
64396449
require.Equal(t, maxExemplars, int64(2))
64406450

64416451
// set max exemplars value in limits, and re-initialize the ingester
64426452
limits.MaxExemplars = 5
6443-
i, err = prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, blocksDir, prometheus.NewRegistry(), true)
6453+
i, err = prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, nil, blocksDir, prometheus.NewRegistry())
64446454
require.NoError(t, err)
64456455

64466456
// validate this value is picked up now
@@ -6815,6 +6825,7 @@ func TestIngester_UpdateLabelSetMetrics(t *testing.T) {
68156825
cfg.BlocksStorageConfig.TSDB.BlockRanges = []time.Duration{2 * time.Hour}
68166826
reg := prometheus.NewRegistry()
68176827
limits := defaultLimitsTestConfig()
6828+
limits.EnableNativeHistograms = true
68186829
userID := "1"
68196830
ctx := user.InjectOrgID(context.Background(), userID)
68206831

@@ -6839,7 +6850,7 @@ func TestIngester_UpdateLabelSetMetrics(t *testing.T) {
68396850
require.NoError(t, os.Mkdir(chunksDir, os.ModePerm))
68406851
require.NoError(t, os.Mkdir(blocksDir, os.ModePerm))
68416852

6842-
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, reg, false)
6853+
i, err := prepareIngesterWithBlocksStorageAndLimits(t, cfg, limits, tenantLimits, blocksDir, reg)
68436854
require.NoError(t, err)
68446855
require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
68456856
defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck

pkg/storage/tsdb/config.go

-4
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ type TSDBConfig struct {
172172
// OutOfOrderCapMax is maximum capacity for OOO chunks (in samples).
173173
OutOfOrderCapMax int64 `yaml:"out_of_order_cap_max"`
174174

175-
// Enable native histogram ingestion.
176-
EnableNativeHistograms bool `yaml:"enable_native_histograms"`
177-
178175
// Posting Cache Configuration for TSDB
179176
PostingsCache TSDBPostingsCacheConfig `yaml:"expanded_postings_cache" doc:"description=[EXPERIMENTAL] If enabled, ingesters will cache expanded postings when querying blocks. Caching can be configured separately for the head and compacted blocks."`
180177
}
@@ -204,7 +201,6 @@ func (cfg *TSDBConfig) RegisterFlags(f *flag.FlagSet) {
204201
f.IntVar(&cfg.MaxExemplars, "blocks-storage.tsdb.max-exemplars", 0, "Deprecated, use maxExemplars in limits instead. If the MaxExemplars value in limits is set to zero, cortex will fallback on this value. This setting enables support for exemplars in TSDB and sets the maximum number that will be stored. 0 or less means disabled.")
205202
f.BoolVar(&cfg.MemorySnapshotOnShutdown, "blocks-storage.tsdb.memory-snapshot-on-shutdown", false, "True to enable snapshotting of in-memory TSDB data on disk when shutting down.")
206203
f.Int64Var(&cfg.OutOfOrderCapMax, "blocks-storage.tsdb.out-of-order-cap-max", tsdb.DefaultOutOfOrderCapMax, "[EXPERIMENTAL] Configures the maximum number of samples per chunk that can be out-of-order.")
207-
f.BoolVar(&cfg.EnableNativeHistograms, "blocks-storage.tsdb.enable-native-histograms", false, "[EXPERIMENTAL] True to enable native histogram.")
208204

209205
flagext.DeprecatedFlag(f, "blocks-storage.tsdb.wal-compression-enabled", "Deprecated (use blocks-storage.tsdb.wal-compression-type instead): True to enable TSDB WAL compression.", util_log.Logger)
210206

0 commit comments

Comments
 (0)