Skip to content

Commit 72cd7eb

Browse files
authored
querymiddleware: cache instant query errors (#11120)
* querymiddleware: cache instant query errors Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> * update CHANGELOG Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> * simplify isCacheable Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> * expand tests with instant query requests Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> * handle subsequent errors in instant queries * address review comments Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> * improve tests Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com> --------- Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
1 parent 7f4d541 commit 72cd7eb

File tree

5 files changed

+288
-193
lines changed

5 files changed

+288
-193
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [CHANGE] Overrides-exporter: Don't export per-tenant overrides that are set to their default values. #11173
1313
* [CHANGE] gRPC/HTTP clients: Rename metric `cortex_client_request_invalid_cluster_validation_labels_total` to `cortex_client_invalid_cluster_validation_label_requests_total`. #11237
1414
* [FEATURE] Distributor: Experimental support for Prometheus Remote-Write 2.0 protocol. Limitations: Created timestamp is ignored, per series metadata is merged on metric family level automatically, ingestion might fail if client sends ProtoBuf fields out of order. The label `version` is added to the metric `cortex_distributor_requests_in_total` with a value of either `1.0` or `2.0` depending on the detected Remote-Write protocol. #11100 #11101 #11192 #11143
15+
* [FEATURE] Query-frontend: expand `query-frontend.cache-errors` and `query-frontend.results-cache-ttl-for-errors` configuration options to cache non-transient response failures for instant queries. #11120
1516
* [ENHANCEMENT] Ingester: Add support for exporting native histogram cost attribution metrics (`cortex_ingester_attributed_active_native_histogram_series` and `cortex_ingester_attributed_active_native_histogram_buckets`) with labels specified by customers to a custom Prometheus registry. #10892
1617
* [ENHANCEMENT] Store-gateway: Download sparse headers uploaded by compactors. Compactors have to be configured with `-compactor.upload-sparse-index-headers=true` option. #10879 #11072.
1718
* [ENHANCEMENT] Compactor: Upload block index file and multiple segment files concurrently. Concurrency scales linearly with block size up to `-compactor.max-per-block-upload-concurrency`. #10947

pkg/frontend/querymiddleware/error_caching.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func (e *errorCachingHandler) loadErrorFromCache(ctx context.Context, key, hashe
161161
}
162162

163163
return apierror.New(apierror.Type(cachedError.ErrorType), cachedError.ErrorMessage)
164-
165164
}
166165

167166
func (e *errorCachingHandler) storeErrorToCache(key, hashedKey string, ttl time.Duration, apiErr *apierror.APIError, spanLog *spanlogger.SpanLogger) {
@@ -187,11 +186,12 @@ func (e *errorCachingHandler) storeErrorToCache(key, hashedKey string, ttl time.
187186
}
188187

189188
func (e *errorCachingHandler) isCacheable(apiErr *apierror.APIError) (bool, string) {
190-
if apiErr.Type != apierror.TypeBadData && apiErr.Type != apierror.TypeExec && apiErr.Type != apierror.TypeTooLargeEntry {
189+
switch apiErr.Type {
190+
case apierror.TypeBadData, apierror.TypeExec, apierror.TypeTooLargeEntry:
191+
return true, ""
192+
default:
191193
return false, reasonNotCacheableError
192194
}
193-
194-
return true, ""
195195
}
196196

197197
func addWithExemplar(ctx context.Context, counter prometheus.Counter, val float64) {

0 commit comments

Comments
 (0)