**What this PR does / why we need it**:
Before this PR, the index stats cache would use the same config as the
query results cache. This was a limitation since:
1. We would not be able to point to a different cache for storing the
index stats if needed.
2. We would not be able to add specific settings for this cache, without
adding it to the results cache.
In this PR, we refactor the index stats cache config to be independently
configurable. Note that if it's not configured, it will try to use the
results cache settings.
**Which issue(s) this PR fixes**:
This is needed for:
- https://github.com/grafana/loki/pull/9537
- https://github.com/grafana/loki/pull/9536
**Special notes for your reviewer**:
- This PR also refactors all the tripperwares in rountrip.go to reuse
the same stats tripperware instead of each one creating their own.
- Configuring a new cache in rountrip.go is a requirement for
https://github.com/grafana/loki/pull/9536 so the stats summary can
distinguish before the stats cache and the results cache.
**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [x] Documentation added
- [x] Tests updated
- [x] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](d10549e3ec)
* [9357](https://github.com/grafana/loki/pull/9357) **Indransh**: Add HTTP API to change the log level at runtime
* [9431](https://github.com/grafana/loki/pull/9431) **dannykopping**: Add more buckets to `loki_memcache_request_duration_seconds` metric; latencies can increase if using memcached with NVMe
* [8684](https://github.com/grafana/loki/pull/8684) **oleksii-boiko-ua**: Helm: Add hpa templates for read, write and backend components.
* [9535](https://github.com/grafana/loki/pull/9535) **salvacorts** Index stats cache can be configured independently of the results cache. If it's not configured, but it's enabled, it will use the results cache configuration.
f.StringVar(&cfg.Compression,"frontend.compression","","Use compression in results cache. Supported values are: 'snappy' and '' (disable compression).")
f.StringVar(&cfg.Compression,prefix+"compression","","Use compression in results cache. Supported values are: 'snappy' and '' (disable compression).")
//lint:ignore faillint Need to pass the global logger like this for warning on deprecated methods
flagext.DeprecatedFlag(f,"frontend.cache-split-interval","Deprecated: The maximum interval expected for each request, results will be cached per single interval. This behavior is now determined by querier.split-queries-by-interval.",util_log.Logger)
flagext.DeprecatedFlag(f,prefix+"cache-split-interval","Deprecated: The maximum interval expected for each request, results will be cached per single interval. This behavior is now determined by querier.split-queries-by-interval.",util_log.Logger)
// Deprecated: SplitQueriesByInterval will be removed in the next major release
SplitQueriesByIntervaltime.Duration`yaml:"split_queries_by_interval" doc:"deprecated|description=Use -querier.split-queries-by-interval instead. CLI flag: -querier.split-queries-by-day. Split queries by day and execute in parallel."`
f.IntVar(&cfg.MaxRetries,"querier.max-retries-per-request",5,"Maximum number of retries for a single request; beyond this, the downstream error is returned.")
f.BoolVar(&cfg.AlignQueriesWithStep,"querier.align-querier-with-step",false,"Mutate incoming queries to align their start and end with their step.")
f.BoolVar(&cfg.CacheIndexStatsResults,"querier.cache-index-stats-results",false,"Cache index stats query results.")
f.BoolVar(&cfg.ShardedQueries,"querier.parallelise-shardable-queries",true,"Perform query parallelisations based on storage sharding configuration and query ASTs. This feature is supported only by the chunks storage engine.")
f.Var(&cfg.ForwardHeaders,"frontend.forward-headers-list","List of headers forwarded by the query Frontend to downstream querier.")
StatsCacheConfigIndexStatsCacheConfig`yaml:"index_stats_results_cache" doc:"description=If a cache config is not specified and cache_index_stats_results is true, the config for the results cache is used."`
}
// 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.")
// NOTE: When we would start caching response from non-metric queries we would have to consider cache gen headers as well in
// MergeResponse implementation for Loki codecs same as it is done in Cortex at https://github.com/cortexproject/cortex/blob/21bad57b346c730d684d6d0205efef133422ab28/pkg/querier/queryrange/query_range.go#L170
// NOTE: When we would start caching response from non-metric queries we would have to consider cache gen headers as well in
// MergeResponse implementation for Loki codecs same as it is done in Cortex at https://github.com/cortexproject/cortex/blob/21bad57b346c730d684d6d0205efef133422ab28/pkg/querier/queryrange/query_range.go#L170