From 371c5e80aa14d1dbedb72736b1964c408845bf0e Mon Sep 17 00:00:00 2001 From: Ed Welch Date: Thu, 4 Apr 2024 15:55:20 -0400 Subject: [PATCH] feat: enable caching of index stats results, volume results, series results and label results by default (#12452) Signed-off-by: Edward Welch --- docs/sources/configure/_index.md | 8 ++++---- docs/sources/setup/upgrade/_index.md | 8 ++++++++ pkg/loki/config_test.go | 5 +++++ pkg/loki/modules_test.go | 6 ++++++ pkg/querier/queryrange/roundtrip.go | 8 ++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/sources/configure/_index.md b/docs/sources/configure/_index.md index e0425597ec9bf..ea0ce206fd720 100644 --- a/docs/sources/configure/_index.md +++ b/docs/sources/configure/_index.md @@ -866,7 +866,7 @@ results_cache: # Cache index stats query results. # CLI flag: -querier.cache-index-stats-results -[cache_index_stats_results: | default = false] +[cache_index_stats_results: | default = true] # If a cache config is not specified and cache_index_stats_results is true, the # config for the results cache is used. @@ -883,7 +883,7 @@ index_stats_results_cache: # Cache volume query results. # CLI flag: -querier.cache-volume-results -[cache_volume_results: | default = false] +[cache_volume_results: | default = true] # If a cache config is not specified and cache_volume_results is true, the # config for the results cache is used. @@ -922,7 +922,7 @@ instant_metric_results_cache: # Cache series query results. # CLI flag: -querier.cache-series-results -[cache_series_results: | default = false] +[cache_series_results: | default = true] # If series_results_cache is not configured and cache_series_results is true, # the config for the results cache is used. @@ -939,7 +939,7 @@ series_results_cache: # Cache label query results. # CLI flag: -querier.cache-label-results -[cache_label_results: | default = false] +[cache_label_results: | default = true] # If label_results_cache is not configured and cache_label_results is true, the # config for the results cache is used. diff --git a/docs/sources/setup/upgrade/_index.md b/docs/sources/setup/upgrade/_index.md index 133d9493fc53c..2cec750395521 100644 --- a/docs/sources/setup/upgrade/_index.md +++ b/docs/sources/setup/upgrade/_index.md @@ -186,6 +186,14 @@ Structured Metadata is enabled by default in Loki 3.0, however, it requires your Automatic stream sharding helps keep the write load of high volume streams balanced across ingesters and helps to avoid hot-spotting. Check out the [operations page](https://grafana.com/docs/loki/latest/operations/automatic-stream-sharding/) for more information +#### More results caching is enabled by default + +The TSDB index type has support for caching results for 'stats' and 'volume' queries which are now enabled by default. + +'label' and 'series' requests can be cached now too and this is enabled by default. + +All of these are cached to the `results_cache` which is configured in the `query_range` config section. By default, an in memory cache is used. + #### Write dedupe cache is deprecated Write dedupe cache is deprecated because it not required by the newer single store indexes ([TSDB]({{< relref "../../operations/storage/tsdb" >}}) and [boltdb-shipper]({{< relref "../../operations/storage/boltdb-shipper" >}})). If you using a [legacy index type]({{< relref "../../storage#index-storage" >}}), consider migrating to TSDB (recommended). diff --git a/pkg/loki/config_test.go b/pkg/loki/config_test.go index 0fa36ea2ba9d4..1642213f6739f 100644 --- a/pkg/loki/config_test.go +++ b/pkg/loki/config_test.go @@ -69,6 +69,11 @@ func TestCrossComponentValidation(t *testing.T) { tc.base.RegisterFlags(flag.NewFlagSet(tc.desc, 0)) // This test predates the newer schema required for structured metadata tc.base.LimitsConfig.AllowStructuredMetadata = false + // Several caches will error if not configured, disabled them for this test + tc.base.QueryRange.CacheIndexStatsResults = false + tc.base.QueryRange.CacheSeriesResults = false + tc.base.QueryRange.CacheLabelResults = false + tc.base.QueryRange.CacheVolumeResults = false err := tc.base.Validate() if tc.err { require.NotNil(t, err) diff --git a/pkg/loki/modules_test.go b/pkg/loki/modules_test.go index 989d8e588c0de..90c0b887dd02e 100644 --- a/pkg/loki/modules_test.go +++ b/pkg/loki/modules_test.go @@ -380,6 +380,12 @@ func minimalWorkingConfig(t *testing.T, dir, target string, cfgTransformers ...f }, } + // Disable some caches otherwise we'll get errors if we don't configure them + cfg.QueryRange.CacheLabelResults = false + cfg.QueryRange.CacheSeriesResults = false + cfg.QueryRange.CacheIndexStatsResults = false + cfg.QueryRange.CacheVolumeResults = false + cfg.SchemaConfig = config.SchemaConfig{ Configs: []config.PeriodConfig{ { diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index 3d64c50231d02..3118ceb13136a 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -62,16 +62,16 @@ type Config struct { // RegisterFlags adds the flags required to configure this flag set. func (cfg *Config) RegisterFlags(f *flag.FlagSet) { cfg.Config.RegisterFlags(f) - f.BoolVar(&cfg.CacheIndexStatsResults, "querier.cache-index-stats-results", false, "Cache index stats query results.") + f.BoolVar(&cfg.CacheIndexStatsResults, "querier.cache-index-stats-results", true, "Cache index stats query results.") cfg.StatsCacheConfig.RegisterFlags(f) - f.BoolVar(&cfg.CacheVolumeResults, "querier.cache-volume-results", false, "Cache volume query results.") + f.BoolVar(&cfg.CacheVolumeResults, "querier.cache-volume-results", true, "Cache volume query results.") cfg.VolumeCacheConfig.RegisterFlags(f) f.BoolVar(&cfg.CacheInstantMetricResults, "querier.cache-instant-metric-results", false, "Cache instant metric query results.") cfg.InstantMetricCacheConfig.RegisterFlags(f) f.BoolVar(&cfg.InstantMetricQuerySplitAlign, "querier.instant-metric-query-split-align", false, "Align the instant metric splits with splityByInterval and query's exec time.") - f.BoolVar(&cfg.CacheSeriesResults, "querier.cache-series-results", false, "Cache series query results.") + f.BoolVar(&cfg.CacheSeriesResults, "querier.cache-series-results", true, "Cache series query results.") cfg.SeriesCacheConfig.RegisterFlags(f) - f.BoolVar(&cfg.CacheLabelResults, "querier.cache-label-results", false, "Cache label query results.") + f.BoolVar(&cfg.CacheLabelResults, "querier.cache-label-results", true, "Cache label query results.") cfg.LabelsCacheConfig.RegisterFlags(f) }