From 3ff24d7ea65aac76396664917e36ea6848d0cf64 Mon Sep 17 00:00:00 2001 From: Nick Pillitteri Date: Thu, 18 Jul 2024 11:49:48 -0400 Subject: [PATCH] Cache non-transient error responses from the query-frontend Create a new query-frontend middleware that caches errors returned by queries if they are non-transient and will fail again if executed again. This allows us to save work when running a query that hits, e.g., a limit error: running the query again will not help and is a waste of work. See #2676 See #7340 --- cmd/mimir/config-descriptor.json | 10 + .../configuration-parameters/index.md | 3 + pkg/frontend/querymiddleware/error_caching.go | 182 +++++++ pkg/frontend/querymiddleware/model.pb.go | 472 +++++++++++++++--- pkg/frontend/querymiddleware/model.proto | 6 + pkg/frontend/querymiddleware/results_cache.go | 28 +- .../querymiddleware/results_cache_test.go | 2 +- pkg/frontend/querymiddleware/roundtrip.go | 12 +- .../querymiddleware/split_and_cache.go | 2 +- 9 files changed, 623 insertions(+), 94 deletions(-) create mode 100644 pkg/frontend/querymiddleware/error_caching.go diff --git a/cmd/mimir/config-descriptor.json b/cmd/mimir/config-descriptor.json index 88bb2838294..9b7797a2b4c 100644 --- a/cmd/mimir/config-descriptor.json +++ b/cmd/mimir/config-descriptor.json @@ -6291,6 +6291,16 @@ "fieldFlag": "query-frontend.cache-results", "fieldType": "boolean" }, + { + "kind": "field", + "name": "cache_errors", + "required": false, + "desc": "", + "fieldValue": null, + "fieldDefaultValue": false, + "fieldType": "boolean", + "fieldCategory": "experimental" + }, { "kind": "field", "name": "max_retries", diff --git a/docs/sources/mimir/configure/configuration-parameters/index.md b/docs/sources/mimir/configure/configuration-parameters/index.md index c86217eb6a6..f2802fdbfba 100644 --- a/docs/sources/mimir/configure/configuration-parameters/index.md +++ b/docs/sources/mimir/configure/configuration-parameters/index.md @@ -1649,6 +1649,9 @@ results_cache: # CLI flag: -query-frontend.cache-results [cache_results: | default = false] +# (experimental) +[cache_errors: | default = ] + # (advanced) Maximum number of retries for a single request; beyond this, the # downstream error is returned. # CLI flag: -query-frontend.max-retries-per-request diff --git a/pkg/frontend/querymiddleware/error_caching.go b/pkg/frontend/querymiddleware/error_caching.go new file mode 100644 index 00000000000..046ec48c41c --- /dev/null +++ b/pkg/frontend/querymiddleware/error_caching.go @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +package querymiddleware + +import ( + "context" + "errors" + "fmt" + "time" + + "github.com/go-kit/log" + "github.com/go-kit/log/level" + "github.com/gogo/protobuf/proto" + "github.com/grafana/dskit/cache" + "github.com/grafana/dskit/tenant" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/prometheus/common/model" + + apierror "github.com/grafana/mimir/pkg/api/error" + "github.com/grafana/mimir/pkg/util/spanlogger" + "github.com/grafana/mimir/pkg/util/validation" +) + +const ( + reasonDisabledByOption = "disable-by-option" + reasonNotAPIError = "not-api-error" + reasonNotCacheableError = "not-cacheable-api-error" +) + +func newErrorCachingMiddleware(cache cache.Cache, limits Limits, ttl time.Duration, shouldCacheReq shouldCacheFn, logger log.Logger, reg prometheus.Registerer) MetricsQueryMiddleware { + cacheAttempted := promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Name: "cortex_frontend_query_error_cache_requests_total", + Help: "", + }) + cacheHits := promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Name: "cortex_frontend_query_error_cache_hits_total", + Help: "", + }) + cacheStoreSkipped := promauto.With(reg).NewCounterVec(prometheus.CounterOpts{ + Name: "cortex_frontend_query_error_cache_skipped_total", + Help: "", + }, []string{"reason"}) + + return MetricsQueryMiddlewareFunc(func(next MetricsQueryHandler) MetricsQueryHandler { + return &errorCachingHandler{ + next: next, + cache: cache, + limits: limits, + ttl: ttl, + shouldCacheReq: shouldCacheReq, + logger: logger, + cacheAttempted: cacheAttempted, + cacheHits: cacheHits, + cacheStoreSkipped: cacheStoreSkipped, + } + }) +} + +type errorCachingHandler struct { + next MetricsQueryHandler + cache cache.Cache + limits Limits + ttl time.Duration + shouldCacheReq shouldCacheFn + logger log.Logger + + cacheAttempted prometheus.Counter + cacheHits prometheus.Counter + cacheStoreSkipped *prometheus.CounterVec + + // TODO: Cache store attempted metric? skipped vs stored? +} + +func (e *errorCachingHandler) Do(ctx context.Context, request MetricsQueryRequest) (Response, error) { + spanLog := spanlogger.FromContext(ctx, e.logger) + tenantIDs, err := tenant.TenantIDs(ctx) + if err != nil { + return e.next.Do(ctx, request) + } + + // Check if caching has disabled via an option on the request + if !e.shouldCacheReq(request) { + e.cacheStoreSkipped.WithLabelValues(reasonDisabledByOption).Inc() + return e.next.Do(ctx, request) + } + + e.cacheAttempted.Inc() + key := e.cacheKey(tenant.JoinTenantIDs(tenantIDs), request) + hashedKey := cacheHashKey(key) + + if cachedErr := e.loadErrorFromCache(ctx, key, hashedKey); cachedErr != nil { + e.cacheHits.Inc() + spanLog.DebugLog( + "msg", "returned cached API error", + "error_type", cachedErr.Type, + "key", key, + "hashed_key", hashedKey, + ) + + return nil, cachedErr + } + + res, err := e.next.Do(ctx, request) + if err != nil { + var apiErr *apierror.APIError + if !errors.As(err, &apiErr) { + e.cacheStoreSkipped.WithLabelValues(reasonNotAPIError).Inc() + return res, err + } + + if cacheable, reason := e.isCacheable(apiErr, request, tenantIDs); !cacheable { + e.cacheStoreSkipped.WithLabelValues(reason).Inc() + spanLog.DebugLog( + "msg", "error result from request is not cacheable", + "error_type", apiErr.Type, + "reason", reason, + ) + return res, err + } + + e.storeErrorToCache(key, hashedKey, apiErr) + } + + return res, err +} + +func (e *errorCachingHandler) loadErrorFromCache(ctx context.Context, key, hashedKey string) *apierror.APIError { + res := e.cache.GetMulti(ctx, []string{hashedKey}) + if cached, ok := res[hashedKey]; ok { + var cachedError CachedError + if err := proto.Unmarshal(cached, &cachedError); err != nil { + level.Warn(e.logger).Log("msg", "unable to unmarshall cached error", "err", err) + return nil + } + + if cachedError.GetKey() != key { + level.Debug(e.logger).Log( + "msg", "cached error key does not match", + "expected_key", key, + "actual_key", cachedError.GetKey(), + "hashed_key", hashedKey, + ) + return nil + } + + return apierror.New(apierror.Type(cachedError.Type), cachedError.Message) + } + + return nil +} + +func (e *errorCachingHandler) storeErrorToCache(key, hashedKey string, apiErr *apierror.APIError) { + bytes, err := proto.Marshal(&CachedError{ + Key: key, + Type: string(apiErr.Type), + Message: apiErr.Message, + }) + + if err != nil { + level.Warn(e.logger).Log("msg", "unable to marshal cached error", "err", err) + return + } + + e.cache.SetAsync(hashedKey, bytes, e.ttl) +} + +func (e *errorCachingHandler) cacheKey(tenantID string, r MetricsQueryRequest) string { + return fmt.Sprintf("EC:%s:%s:%d:%d:%d", tenantID, r.GetQuery(), r.GetStart(), r.GetEnd(), r.GetStep()) +} + +func (e *errorCachingHandler) isCacheable(apiErr *apierror.APIError, req MetricsQueryRequest, tenantIDs []string) (bool, string) { + if apiErr.Type != apierror.TypeBadData && apiErr.Type != apierror.TypeExec { + return false, reasonNotCacheableError + } + + maxCacheFreshness := validation.MaxDurationPerTenant(tenantIDs, e.limits.MaxCacheFreshness) + maxCacheTime := int64(model.Now().Add(-maxCacheFreshness)) + cacheUnalignedRequests := validation.AllTrueBooleansPerTenant(tenantIDs, e.limits.ResultsCacheForUnalignedQueryEnabled) + + return isRequestCachable(req, maxCacheTime, cacheUnalignedRequests, e.logger) +} diff --git a/pkg/frontend/querymiddleware/model.pb.go b/pkg/frontend/querymiddleware/model.pb.go index 51f4239f768..3801292e400 100644 --- a/pkg/frontend/querymiddleware/model.pb.go +++ b/pkg/frontend/querymiddleware/model.pb.go @@ -276,6 +276,65 @@ func (m *SampleStream) GetHistograms() []mimirpb.FloatHistogramPair { return nil } +type CachedError struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"errorType"` + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"error"` +} + +func (m *CachedError) Reset() { *m = CachedError{} } +func (*CachedError) ProtoMessage() {} +func (*CachedError) Descriptor() ([]byte, []int) { + return fileDescriptor_4c16552f9fdb66d8, []int{4} +} +func (m *CachedError) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CachedError) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CachedError.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CachedError) XXX_Merge(src proto.Message) { + xxx_messageInfo_CachedError.Merge(m, src) +} +func (m *CachedError) XXX_Size() int { + return m.Size() +} +func (m *CachedError) XXX_DiscardUnknown() { + xxx_messageInfo_CachedError.DiscardUnknown(m) +} + +var xxx_messageInfo_CachedError proto.InternalMessageInfo + +func (m *CachedError) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *CachedError) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *CachedError) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + type CachedResponse struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key"` // List of cached responses; non-overlapping and in order. @@ -285,7 +344,7 @@ type CachedResponse struct { func (m *CachedResponse) Reset() { *m = CachedResponse{} } func (*CachedResponse) ProtoMessage() {} func (*CachedResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{4} + return fileDescriptor_4c16552f9fdb66d8, []int{5} } func (m *CachedResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -342,7 +401,7 @@ type Extent struct { func (m *Extent) Reset() { *m = Extent{} } func (*Extent) ProtoMessage() {} func (*Extent) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{5} + return fileDescriptor_4c16552f9fdb66d8, []int{6} } func (m *Extent) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -418,7 +477,7 @@ type Options struct { func (m *Options) Reset() { *m = Options{} } func (*Options) ProtoMessage() {} func (*Options) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{6} + return fileDescriptor_4c16552f9fdb66d8, []int{7} } func (m *Options) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -489,7 +548,7 @@ type QueryStatistics struct { func (m *QueryStatistics) Reset() { *m = QueryStatistics{} } func (*QueryStatistics) ProtoMessage() {} func (*QueryStatistics) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{7} + return fileDescriptor_4c16552f9fdb66d8, []int{8} } func (m *QueryStatistics) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -541,7 +600,7 @@ type CachedHTTPResponse struct { func (m *CachedHTTPResponse) Reset() { *m = CachedHTTPResponse{} } func (*CachedHTTPResponse) ProtoMessage() {} func (*CachedHTTPResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{8} + return fileDescriptor_4c16552f9fdb66d8, []int{9} } func (m *CachedHTTPResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -607,7 +666,7 @@ type CachedHTTPHeader struct { func (m *CachedHTTPHeader) Reset() { *m = CachedHTTPHeader{} } func (*CachedHTTPHeader) ProtoMessage() {} func (*CachedHTTPHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_4c16552f9fdb66d8, []int{9} + return fileDescriptor_4c16552f9fdb66d8, []int{10} } func (m *CachedHTTPHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -655,6 +714,7 @@ func init() { proto.RegisterType((*PrometheusResponse)(nil), "queryrange.PrometheusResponse") proto.RegisterType((*PrometheusData)(nil), "queryrange.PrometheusData") proto.RegisterType((*SampleStream)(nil), "queryrange.SampleStream") + proto.RegisterType((*CachedError)(nil), "queryrange.CachedError") proto.RegisterType((*CachedResponse)(nil), "queryrange.CachedResponse") proto.RegisterType((*Extent)(nil), "queryrange.Extent") proto.RegisterType((*Options)(nil), "queryrange.Options") @@ -666,71 +726,73 @@ func init() { func init() { proto.RegisterFile("model.proto", fileDescriptor_4c16552f9fdb66d8) } var fileDescriptor_4c16552f9fdb66d8 = []byte{ - // 1015 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xcf, 0x6e, 0x23, 0xc5, - 0x13, 0xf6, 0xc4, 0x7f, 0x53, 0xde, 0x5f, 0x62, 0x75, 0xa2, 0x1f, 0x4e, 0x80, 0x19, 0x6b, 0xc4, - 0x21, 0xa0, 0x5d, 0x07, 0x82, 0xe0, 0x80, 0x00, 0xb1, 0xce, 0x06, 0x25, 0xb0, 0x40, 0x68, 0x47, - 0x20, 0x71, 0x89, 0xda, 0x9e, 0x8e, 0x3d, 0xec, 0xcc, 0xf4, 0xd0, 0xdd, 0xde, 0x5d, 0xdf, 0x10, - 0x0f, 0x80, 0x78, 0x02, 0xce, 0x3c, 0xca, 0x1e, 0x73, 0x5c, 0xed, 0x61, 0x44, 0x1c, 0x21, 0x21, - 0x9f, 0xf6, 0x01, 0x38, 0xa0, 0xa9, 0x9e, 0x19, 0xcf, 0xee, 0xe6, 0xc0, 0xc5, 0xd3, 0xfd, 0xd5, - 0xf7, 0x55, 0x55, 0x57, 0x57, 0x97, 0xa1, 0x1d, 0x0a, 0x8f, 0x07, 0xfd, 0x58, 0x0a, 0x2d, 0x08, - 0xfc, 0x34, 0xe3, 0x72, 0x2e, 0x59, 0x34, 0xe1, 0xbb, 0x77, 0x26, 0xbe, 0x9e, 0xce, 0x46, 0xfd, - 0xb1, 0x08, 0xf7, 0x27, 0x62, 0x22, 0xf6, 0x91, 0x32, 0x9a, 0x5d, 0xe0, 0x0e, 0x37, 0xb8, 0x32, - 0xd2, 0xdd, 0x77, 0xcb, 0x74, 0xc9, 0x2e, 0x58, 0xc4, 0xf6, 0x43, 0x3f, 0xf4, 0xe5, 0x7e, 0xfc, - 0x60, 0x62, 0x56, 0xf1, 0xc8, 0x7c, 0x33, 0xc5, 0xce, 0x44, 0x88, 0x49, 0xc0, 0x57, 0x7e, 0x59, - 0x34, 0x37, 0x26, 0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0x58, 0xab, 0x5b, 0x14, - 0xd7, 0xee, 0xc7, 0xd0, 0x79, 0x59, 0x90, 0xf2, 0xa2, 0xe2, 0xbf, 0x87, 0xe2, 0x9a, 0x6c, 0x43, - 0x1d, 0x5f, 0x29, 0xa6, 0xb3, 0x4e, 0xcd, 0x66, 0x70, 0x74, 0x79, 0x65, 0x57, 0x9e, 0x5e, 0xd9, - 0x95, 0xe7, 0x57, 0xb6, 0xf5, 0xf3, 0xc2, 0xb6, 0xfe, 0x58, 0xd8, 0xd6, 0x93, 0x85, 0x6d, 0x5d, - 0x2e, 0x6c, 0xeb, 0xcf, 0x85, 0x6d, 0xfd, 0xbd, 0xb0, 0x2b, 0xcf, 0x17, 0xb6, 0xf5, 0xdb, 0xb5, - 0x5d, 0xb9, 0xbc, 0xb6, 0x2b, 0x4f, 0xaf, 0xed, 0xca, 0x0f, 0x9b, 0x98, 0x6d, 0xe8, 0x7b, 0x5e, - 0xc0, 0x1f, 0x31, 0xc9, 0x47, 0x0d, 0x6c, 0xd7, 0xf7, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xab, - 0x90, 0x68, 0x82, 0x9e, 0x07, 0x00, 0x00, + // 1055 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0xfa, 0x7f, 0x9e, 0xdb, 0xc4, 0x9a, 0x46, 0xe0, 0x04, 0xd8, 0x35, 0x0b, 0x87, 0x80, + 0x5a, 0x07, 0x82, 0xe0, 0x80, 0x28, 0xa2, 0x4e, 0x83, 0x12, 0x28, 0x10, 0xc6, 0x11, 0x48, 0x5c, + 0xa2, 0xb1, 0x77, 0x62, 0x2f, 0xdd, 0x7f, 0xcc, 0x8c, 0xdb, 0xfa, 0x86, 0xf8, 0x00, 0x88, 0x4f, + 0xc0, 0x99, 0x8f, 0xd2, 0x63, 0x8e,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0xe7, 0x17, 0x66, 0xe5, 0xc9, 0x85, 0x59, 0x79, 0x76, 0x61, 0x1a, 0x3f, 0x2f, 0x4d, 0xe3, + 0x8f, 0xa5, 0x69, 0x3c, 0x5e, 0x9a, 0xc6, 0xf9, 0xd2, 0x34, 0xfe, 0x5c, 0x9a, 0xc6, 0xdf, 0x4b, + 0xb3, 0xf2, 0x6c, 0x69, 0x1a, 0xbf, 0x5d, 0x9a, 0x95, 0xf3, 0x4b, 0xb3, 0xf2, 0xe4, 0xd2, 0xac, + 0xfc, 0xb0, 0x81, 0xd9, 0xfa, 0xae, 0xe3, 0x78, 0xfc, 0x21, 0x13, 0x7c, 0xdc, 0xc4, 0x71, 0xfd, + 0xe0, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x7c, 0xfc, 0x98, 0x10, 0x08, 0x00, 0x00, } func (this *PrometheusHeader) Equal(that interface{}) bool { @@ -899,6 +961,36 @@ func (this *SampleStream) Equal(that interface{}) bool { } return true } +func (this *CachedError) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*CachedError) + if !ok { + that2, ok := that.(CachedError) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Key != that1.Key { + return false + } + if this.Type != that1.Type { + return false + } + if this.Message != that1.Message { + return false + } + return true +} func (this *CachedResponse) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1164,6 +1256,18 @@ func (this *SampleStream) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *CachedError) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&querymiddleware.CachedError{") + s = append(s, "Key: "+fmt.Sprintf("%#v", this.Key)+",\n") + s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") + s = append(s, "Message: "+fmt.Sprintf("%#v", this.Message)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *CachedResponse) GoString() string { if this == nil { return "nil" @@ -1491,6 +1595,50 @@ func (m *SampleStream) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CachedError) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CachedError) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CachedError) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Message) > 0 { + i -= len(m.Message) + copy(dAtA[i:], m.Message) + i = encodeVarintModel(dAtA, i, uint64(len(m.Message))) + i-- + dAtA[i] = 0x1a + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintModel(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintModel(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *CachedResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1895,6 +2043,27 @@ func (m *SampleStream) Size() (n int) { return n } +func (m *CachedError) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovModel(uint64(l)) + } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovModel(uint64(l)) + } + l = len(m.Message) + if l > 0 { + n += 1 + l + sovModel(uint64(l)) + } + return n +} + func (m *CachedResponse) Size() (n int) { if m == nil { return 0 @@ -2095,6 +2264,18 @@ func (this *SampleStream) String() string { }, "") return s } +func (this *CachedError) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CachedError{`, + `Key:` + fmt.Sprintf("%v", this.Key) + `,`, + `Type:` + fmt.Sprintf("%v", this.Type) + `,`, + `Message:` + fmt.Sprintf("%v", this.Message) + `,`, + `}`, + }, "") + return s +} func (this *CachedResponse) String() string { if this == nil { return "nil" @@ -2860,6 +3041,155 @@ func (m *SampleStream) Unmarshal(dAtA []byte) error { } return nil } +func (m *CachedError) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CachedError: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CachedError: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Key = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModel + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModel + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModel + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModel(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthModel + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthModel + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *CachedResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/pkg/frontend/querymiddleware/model.proto b/pkg/frontend/querymiddleware/model.proto index bd181763c06..5ad6d137376 100644 --- a/pkg/frontend/querymiddleware/model.proto +++ b/pkg/frontend/querymiddleware/model.proto @@ -43,6 +43,12 @@ message SampleStream { repeated cortexpb.FloatHistogramPair histograms = 3 [(gogoproto.nullable) = false, (gogoproto.jsontag) = "histograms"]; } +message CachedError { + string key = 1 [(gogoproto.jsontag) = "key"]; + string type = 2 [(gogoproto.jsontag) = "errorType"]; + string message = 3 [(gogoproto.jsontag) = "error"]; +} + message CachedResponse { string key = 1 [(gogoproto.jsontag) = "key"]; diff --git a/pkg/frontend/querymiddleware/results_cache.go b/pkg/frontend/querymiddleware/results_cache.go index 9102bdd3a43..ae6d6609332 100644 --- a/pkg/frontend/querymiddleware/results_cache.go +++ b/pkg/frontend/querymiddleware/results_cache.go @@ -12,6 +12,7 @@ import ( "fmt" "hash/fnv" "net/http" + "slices" "sort" "strings" "time" @@ -263,13 +264,12 @@ func isRequestCachable(req MetricsQueryRequest, maxCacheTime int64, cacheUnalign return true, "" } -// isResponseCachable says whether the response should be cached or not. -func isResponseCachable(r Response, logger log.Logger) bool { - headerValues := getHeaderValuesWithName(r, cacheControlHeader) - for _, v := range headerValues { - if v == noStoreValue { - level.Debug(logger).Log("msg", fmt.Sprintf("%s header in response is equal to %s, not caching the response", cacheControlHeader, noStoreValue)) - return false +// isResponseCachable returns true if a response hasn't explicitly disabled caching +// via an HTTP header, false otherwise. +func isResponseCachable(r Response) bool { + for _, hv := range r.GetHeaders() { + if hv.GetName() == cacheControlHeader { + return !slices.Contains(hv.GetValues(), noStoreValue) } } @@ -331,18 +331,6 @@ func areEvaluationTimeModifiersCachable(r MetricsQueryRequest, maxCacheTime int6 return cachable } -func getHeaderValuesWithName(r Response, headerName string) (headerValues []string) { - for _, hv := range r.GetHeaders() { - if hv.GetName() != headerName { - continue - } - - headerValues = append(headerValues, hv.GetValues()...) - } - - return -} - // mergeCacheExtentsForRequest merges the provided cache extents for the input request and returns merged extents. // The input extents can be overlapping and are not required to be sorted. func mergeCacheExtentsForRequest(ctx context.Context, r MetricsQueryRequest, merger Merger, extents []Extent) ([]Extent, error) { @@ -642,6 +630,6 @@ func cacheHashKey(key string) string { hasher := fnv.New64a() _, _ = hasher.Write([]byte(key)) // This'll never error. - // Hex because memcache errors for the bytes produced by the hash. + // Hex because memcache keys must be non-whitespace non-control ASCII return hex.EncodeToString(hasher.Sum(nil)) } diff --git a/pkg/frontend/querymiddleware/results_cache_test.go b/pkg/frontend/querymiddleware/results_cache_test.go index ab0391a4ef6..cccd7233888 100644 --- a/pkg/frontend/querymiddleware/results_cache_test.go +++ b/pkg/frontend/querymiddleware/results_cache_test.go @@ -363,7 +363,7 @@ func TestIsResponseCachable(t *testing.T) { } { { t.Run(tc.name, func(t *testing.T) { - ret := isResponseCachable(tc.response, log.NewNopLogger()) + ret := isResponseCachable(tc.response) require.Equal(t, tc.expected, ret) }) } diff --git a/pkg/frontend/querymiddleware/roundtrip.go b/pkg/frontend/querymiddleware/roundtrip.go index 7d8ab832f60..8b305f50c63 100644 --- a/pkg/frontend/querymiddleware/roundtrip.go +++ b/pkg/frontend/querymiddleware/roundtrip.go @@ -62,6 +62,7 @@ type Config struct { SplitQueriesByInterval time.Duration `yaml:"split_queries_by_interval" category:"advanced"` ResultsCacheConfig `yaml:"results_cache"` CacheResults bool `yaml:"cache_results"` + CacheErrors bool `yaml:"cache_errors" category:"experimental"` MaxRetries int `yaml:"max_retries" category:"advanced"` NotRunningTimeout time.Duration `yaml:"not_running_timeout" category:"advanced"` ShardedQueries bool `yaml:"parallelize_shardable_queries"` @@ -106,7 +107,7 @@ func (cfg *Config) Validate() error { } } - if cfg.CacheResults || cfg.cardinalityBasedShardingEnabled() { + if cfg.CacheResults || cfg.CacheErrors || cfg.cardinalityBasedShardingEnabled() { if err := cfg.ResultsCacheConfig.Validate(); err != nil { return errors.Wrap(err, "invalid query-frontend results cache config") } @@ -339,6 +340,15 @@ func newQueryMiddlewares( newStepAlignMiddleware(limits, log, registerer), ) + if cfg.CacheResults && cfg.CacheErrors { + // TODO: Use a real TTL + queryRangeMiddleware = append( + queryRangeMiddleware, + newInstrumentMiddleware("error_caching", metrics), + newErrorCachingMiddleware(cacheClient, limits, 5*time.Minute, resultsCacheEnabledByOption, log, registerer), + ) + } + // Inject the middleware to split requests by interval + results cache (if at least one of the two is enabled). if cfg.SplitQueriesByInterval > 0 || cfg.CacheResults { queryRangeMiddleware = append(queryRangeMiddleware, newInstrumentMiddleware("split_by_interval_and_results_cache", metrics), newSplitAndCacheMiddleware( diff --git a/pkg/frontend/querymiddleware/split_and_cache.go b/pkg/frontend/querymiddleware/split_and_cache.go index 12b3c82d4b4..c1be5bace57 100644 --- a/pkg/frontend/querymiddleware/split_and_cache.go +++ b/pkg/frontend/querymiddleware/split_and_cache.go @@ -262,7 +262,7 @@ func (s *splitAndCacheMiddleware) Do(ctx context.Context, req MetricsQueryReques for downstreamIdx, downstreamReq := range splitReq.downstreamRequests { downstreamRes := splitReq.downstreamResponses[downstreamIdx] - if !isResponseCachable(downstreamRes, s.logger) { + if !isResponseCachable(downstreamRes) { continue }