diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9d26a935f37..da2cc01104c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ * [11284](https://github.com/grafana/loki/pull/11284) **ashwanthgoli** Config: Adds `frontend.max-query-capacity` to tune per-tenant query capacity. * [11539](https://github.com/grafana/loki/pull/11539) **kaviraj,ashwanthgoli** Support caching /series and /labels query results * [11545](https://github.com/grafana/loki/pull/11545) **dannykopping** Force correct memcached timeout when fetching chunks. +* [11589](https://github.com/grafana/loki/pull/11589) **ashwanthgoli** Results Cache: Adds `query_length_served` cache stat to measure the length of the query served from cache. ##### Fixes * [11074](https://github.com/grafana/loki/pull/11074) **hainenber** Fix panic in lambda-promtail due to mishandling of empty DROP_LABELS env var. diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 048fe0e0028a2..67cfee24a0567 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -163,6 +163,7 @@ func RecordRangeAndInstantQueryMetrics( "cache_result_req", stats.Caches.Result.EntriesRequested, "cache_result_hit", stats.Caches.Result.EntriesFound, "cache_result_download_time", stats.Caches.Result.CacheDownloadTime(), + "cache_result_query_length_served", stats.Caches.Result.CacheQueryLengthServed(), }...) logValues = append(logValues, tagsToKeyValues(queryTags)...) @@ -228,6 +229,7 @@ func RecordLabelQueryMetrics( "cache_label_results_hit", stats.Caches.LabelResult.EntriesFound, "cache_label_results_stored", stats.Caches.LabelResult.EntriesStored, "cache_label_results_download_time", stats.Caches.LabelResult.CacheDownloadTime(), + "cache_label_results_query_length_served", stats.Caches.LabelResult.CacheQueryLengthServed(), ) execLatency.WithLabelValues(status, queryType, "").Observe(stats.Summary.ExecTime) @@ -341,6 +343,7 @@ func RecordSeriesQueryMetrics(ctx context.Context, log log.Logger, start, end ti "cache_series_results_hit", stats.Caches.SeriesResult.EntriesFound, "cache_series_results_stored", stats.Caches.SeriesResult.EntriesStored, "cache_series_results_download_time", stats.Caches.SeriesResult.CacheDownloadTime(), + "cache_series_results_query_length_served", stats.Caches.SeriesResult.CacheQueryLengthServed(), ) if shard != nil { @@ -428,6 +431,7 @@ func RecordVolumeQueryMetrics(ctx context.Context, log log.Logger, start, end ti "cache_volume_results_hit", stats.Caches.VolumeResult.EntriesFound, "cache_volume_results_stored", stats.Caches.VolumeResult.EntriesStored, "cache_volume_results_download_time", stats.Caches.VolumeResult.CacheDownloadTime(), + "cache_volume_results_query_length_served", stats.Caches.VolumeResult.CacheQueryLengthServed(), ) execLatency.WithLabelValues(status, queryType, "").Observe(stats.Summary.ExecTime) diff --git a/pkg/logql/metrics_test.go b/pkg/logql/metrics_test.go index efaead9afd0dc..c08844eabeabc 100644 --- a/pkg/logql/metrics_test.go +++ b/pkg/logql/metrics_test.go @@ -108,16 +108,17 @@ func TestLogLabelsQuery(t *testing.T) { }, Caches: stats.Caches{ LabelResult: stats.Cache{ - EntriesRequested: 2, - EntriesFound: 1, - EntriesStored: 1, - DownloadTime: 80, + EntriesRequested: 2, + EntriesFound: 1, + EntriesStored: 1, + DownloadTime: 80, + QueryLengthServed: 10, }, }, }) require.Regexp(t, fmt.Sprintf( - "level=info org_id=foo traceID=%s sampled=true latency=slow query_type=labels splits=0 start=.* end=.* start_delta=1h0m0.* end_delta=.* length=1h0m0s duration=25.25s status=200 label=foo query= query_hash=2166136261 total_entries=12 cache_label_results_req=2 cache_label_results_hit=1 cache_label_results_stored=1 cache_label_results_download_time=80ns\n", + "level=info org_id=foo traceID=%s sampled=true latency=slow query_type=labels splits=0 start=.* end=.* start_delta=1h0m0.* end_delta=.* length=1h0m0s duration=25.25s status=200 label=foo query= query_hash=2166136261 total_entries=12 cache_label_results_req=2 cache_label_results_hit=1 cache_label_results_stored=1 cache_label_results_download_time=80ns cache_label_results_query_length_served=10ns\n", sp.Context().(jaeger.SpanContext).SpanID().String(), ), buf.String()) @@ -142,16 +143,17 @@ func TestLogSeriesQuery(t *testing.T) { }, Caches: stats.Caches{ SeriesResult: stats.Cache{ - EntriesRequested: 2, - EntriesFound: 1, - EntriesStored: 1, - DownloadTime: 80, + EntriesRequested: 2, + EntriesFound: 1, + EntriesStored: 1, + DownloadTime: 80, + QueryLengthServed: 10, }, }, }) require.Regexp(t, fmt.Sprintf( - "level=info org_id=foo traceID=%s sampled=true latency=slow query_type=series splits=0 start=.* end=.* start_delta=1h0m0.* end_delta=.* length=1h0m0s duration=25.25s status=200 match=\"{container_name=.*\"}:{app=.*}\" query_hash=23523089 total_entries=10 cache_series_results_req=2 cache_series_results_hit=1 cache_series_results_stored=1 cache_series_results_download_time=80ns\n", + "level=info org_id=foo traceID=%s sampled=true latency=slow query_type=series splits=0 start=.* end=.* start_delta=1h0m0.* end_delta=.* length=1h0m0s duration=25.25s status=200 match=\"{container_name=.*\"}:{app=.*}\" query_hash=23523089 total_entries=10 cache_series_results_req=2 cache_series_results_hit=1 cache_series_results_stored=1 cache_series_results_download_time=80ns cache_series_results_query_length_served=10ns\n", sp.Context().(jaeger.SpanContext).SpanID().String(), ), buf.String()) diff --git a/pkg/logqlmodel/stats/context.go b/pkg/logqlmodel/stats/context.go index 518e7effb59e8..5b25d900c37a8 100644 --- a/pkg/logqlmodel/stats/context.go +++ b/pkg/logqlmodel/stats/context.go @@ -231,12 +231,17 @@ func (c *Cache) Merge(m Cache) { c.BytesSent += m.BytesSent c.BytesReceived += m.BytesReceived c.DownloadTime += m.DownloadTime + c.QueryLengthServed += m.QueryLengthServed } func (c *Cache) CacheDownloadTime() time.Duration { return time.Duration(c.DownloadTime) } +func (c *Cache) CacheQueryLengthServed() time.Duration { + return time.Duration(c.QueryLengthServed) +} + func (r *Result) MergeSplit(m Result) { m.Summary.Splits = 1 r.Merge(m) @@ -429,6 +434,16 @@ func (c *Context) AddCacheRequest(t CacheType, i int) { atomic.AddInt32(&stats.Requests, int32(i)) } +// AddCacheQueryLengthServed measures the length of the query served from cache +func (c *Context) AddCacheQueryLengthServed(t CacheType, i time.Duration) { + stats := c.getCacheStatsByType(t) + if stats == nil { + return + } + + atomic.AddInt64(&stats.QueryLengthServed, int64(i)) +} + func (c *Context) AddSplitQueries(num int64) { atomic.AddInt64(&c.result.Summary.Splits, num) } diff --git a/pkg/logqlmodel/stats/context_test.go b/pkg/logqlmodel/stats/context_test.go index 438cd17b12549..e40a5372a8968 100644 --- a/pkg/logqlmodel/stats/context_test.go +++ b/pkg/logqlmodel/stats/context_test.go @@ -210,7 +210,8 @@ func TestResult_Merge(t *testing.T) { EntriesFound: 2, }, Result: Cache{ - EntriesStored: 3, + EntriesStored: 3, + QueryLengthServed: int64(3 * time.Hour), }, }, Summary: Summary{ @@ -272,7 +273,8 @@ func TestResult_Merge(t *testing.T) { EntriesFound: 2 * 2, }, Result: Cache{ - EntriesStored: 2 * 3, + EntriesStored: 2 * 3, + QueryLengthServed: int64(2 * 3 * time.Hour), }, }, Summary: Summary{ @@ -325,6 +327,7 @@ func TestCaches(t *testing.T) { statsCtx.AddCacheRequest(ChunkCache, 5) statsCtx.AddCacheEntriesStored(ResultCache, 3) + statsCtx.AddCacheQueryLengthServed(ResultCache, 3*time.Hour) statsCtx.AddCacheEntriesRequested(IndexCache, 22) statsCtx.AddCacheBytesRetrieved(ChunkCache, 1024) statsCtx.AddCacheBytesSent(ChunkCache, 512) @@ -341,7 +344,8 @@ func TestCaches(t *testing.T) { EntriesFound: 2, }, Result: Cache{ - EntriesStored: 3, + EntriesStored: 3, + QueryLengthServed: int64(time.Hour * 3), }, }, statsCtx.Caches()) } diff --git a/pkg/logqlmodel/stats/stats.pb.go b/pkg/logqlmodel/stats/stats.pb.go index 7d2df4df33233..75be704020c97 100644 --- a/pkg/logqlmodel/stats/stats.pb.go +++ b/pkg/logqlmodel/stats/stats.pb.go @@ -661,13 +661,14 @@ func (m *Chunk) GetDecompressedStructuredMetadataBytes() int64 { } type Cache struct { - EntriesFound int32 `protobuf:"varint,1,opt,name=entriesFound,proto3" json:"entriesFound"` - EntriesRequested int32 `protobuf:"varint,2,opt,name=entriesRequested,proto3" json:"entriesRequested"` - EntriesStored int32 `protobuf:"varint,3,opt,name=entriesStored,proto3" json:"entriesStored"` - BytesReceived int64 `protobuf:"varint,4,opt,name=bytesReceived,proto3" json:"bytesReceived"` - BytesSent int64 `protobuf:"varint,5,opt,name=bytesSent,proto3" json:"bytesSent"` - Requests int32 `protobuf:"varint,6,opt,name=requests,proto3" json:"requests"` - DownloadTime int64 `protobuf:"varint,7,opt,name=downloadTime,proto3" json:"downloadTime"` + EntriesFound int32 `protobuf:"varint,1,opt,name=entriesFound,proto3" json:"entriesFound"` + EntriesRequested int32 `protobuf:"varint,2,opt,name=entriesRequested,proto3" json:"entriesRequested"` + EntriesStored int32 `protobuf:"varint,3,opt,name=entriesStored,proto3" json:"entriesStored"` + BytesReceived int64 `protobuf:"varint,4,opt,name=bytesReceived,proto3" json:"bytesReceived"` + BytesSent int64 `protobuf:"varint,5,opt,name=bytesSent,proto3" json:"bytesSent"` + Requests int32 `protobuf:"varint,6,opt,name=requests,proto3" json:"requests"` + DownloadTime int64 `protobuf:"varint,7,opt,name=downloadTime,proto3" json:"downloadTime"` + QueryLengthServed int64 `protobuf:"varint,8,opt,name=queryLengthServed,proto3" json:"queryLengthServed"` } func (m *Cache) Reset() { *m = Cache{} } @@ -751,6 +752,13 @@ func (m *Cache) GetDownloadTime() int64 { return 0 } +func (m *Cache) GetQueryLengthServed() int64 { + if m != nil { + return m.QueryLengthServed + } + return 0 +} + func init() { proto.RegisterType((*Result)(nil), "stats.Result") proto.RegisterType((*Caches)(nil), "stats.Caches") @@ -765,82 +773,83 @@ func init() { func init() { proto.RegisterFile("pkg/logqlmodel/stats/stats.proto", fileDescriptor_6cdfe5d2aea33ebb) } var fileDescriptor_6cdfe5d2aea33ebb = []byte{ - // 1193 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0xcf, 0x6f, 0xdc, 0xc4, - 0x17, 0x5f, 0x67, 0xb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, 0xb3, 0xe8, 0x84, 0x39, 0x61, 0xe0, 0xe2, 0x9e, 0xb6, 0xad, 0x37, 0xf3, 0xcc, 0x5c, - 0x46, 0x81, 0x65, 0x0e, 0x1e, 0xd6, 0xf7, 0x82, 0xc6, 0xb0, 0x2b, 0x65, 0xd8, 0x25, 0x14, 0x58, - 0xe6, 0xa0, 0x47, 0x64, 0x3b, 0x09, 0x13, 0xdb, 0xb7, 0x94, 0x6e, 0xf1, 0x58, 0xb4, 0xad, 0x7b, - 0x79, 0x66, 0x36, 0xb9, 0xa1, 0x09, 0x2c, 0x42, 0x3d, 0x56, 0xba, 0xc2, 0x63, 0x52, 0x0d, 0xa5, - 0xba, 0xa1, 0x09, 0xa4, 0x7b, 0x64, 0x95, 0x3d, 0x63, 0xce, 0xb7, 0xde, 0x84, 0xe1, 0x01, 0xd1, - 0xac, 0x35, 0x9e, 0x70, 0x73, 0x0c, 0x8a, 0x16, 0x7d, 0x9f, 0xdc, 0x3a, 0x4f, 0x59, 0xca, 0x90, - 0xda, 0x41, 0xea, 0x7a, 0x9e, 0x99, 0x25, 0x08, 0x65, 0x93, 0xee, 0x13, 0x12, 0xa7, 0x43, 0x91, - 0xea, 0x31, 0x6e, 0x75, 0xdb, 0xda, 0xc8, 0x33, 0xb3, 0x82, 0x42, 0xa5, 0x4d, 0x1f, 0x93, 0x1d, - 0x1c, 0xdd, 0x57, 0x41, 0x22, 0x4e, 0x4c, 0x92, 0x46, 0x01, 0x73, 0x7b, 0xab, 0xa8, 0xec, 0xe5, - 0x99, 0xd9, 0xe8, 0x87, 0x46, 0x94, 0xf6, 0x49, 0x27, 0x9e, 0xfa, 0x5e, 0x12, 0xf7, 0x6e, 0xa1, - 0x9e, 0xf0, 0x14, 0x13, 0x08, 0xc8, 0x2f, 0x72, 0xc6, 0x76, 0xe4, 0xc6, 0x3d, 0x52, 0xe1, 0x20, - 0x02, 0xf2, 0x5b, 0x8c, 0xea, 0x38, 0x8c, 0x93, 0x43, 0xcf, 0x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 0x33, 0x43, 0x7b, - 0x3e, 0x33, 0xb4, 0xcb, 0x99, 0xa1, 0xfd, 0x35, 0x33, 0xb4, 0xbf, 0x67, 0x46, 0xeb, 0xe5, 0xcc, - 0xd0, 0x7e, 0xbe, 0x36, 0x5a, 0x97, 0xd7, 0x46, 0xeb, 0xc5, 0xb5, 0xd1, 0xfa, 0xfe, 0x83, 0x91, - 0x97, 0x8c, 0xd3, 0xe1, 0xbe, 0x13, 0x4e, 0x06, 0xa3, 0xc8, 0x3e, 0xb5, 0x03, 0x7b, 0xe0, 0x87, - 0x67, 0xde, 0xa0, 0xe9, 0x3f, 0xde, 0xb0, 0x83, 0xff, 0xe0, 0x3e, 0xfe, 0x2f, 0x00, 0x00, 0xff, - 0xff, 0x99, 0x60, 0xf2, 0x04, 0x02, 0x0e, 0x00, 0x00, + // 1215 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0x4d, 0x6f, 0xe3, 0x54, + 0x17, 0x8e, 0x27, 0xaf, 0x93, 0xce, 0xed, 0xe7, 0xdc, 0x76, 0xde, 0xc9, 0x80, 0x64, 0x97, 0xc0, + 0x88, 0x22, 0x50, 0x23, 0x3e, 0x24, 0x04, 0x62, 0x24, 0xe4, 0x0e, 0x95, 0x2a, 0x75, 0x44, 0x39, + 0x81, 0x0d, 0x3b, 0xc7, 0xbe, 0x4d, 0xa2, 0x3a, 0x76, 0x6a, 0x5f, 0x97, 0xe9, 0x0a, 0x7e, 0x02, + 0x3f, 0x83, 0x0d, 0x2b, 0x56, 0x48, 0x88, 0x0d, 0x9b, 0x59, 0x76, 0x39, 0x2b, 0x8b, 0xa6, 0x1b, + 0xe4, 0xd5, 0x48, 0xfc, 0x01, 0x74, 0xcf, 0xbd, 0xf1, 0x57, 0x9c, 0x99, 0x6e, 0xe2, 0x7b, 0x9e, + 0xf3, 0x3c, 0xe7, 0x7e, 0x9e, 0x73, 0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, 0x1b, 0xf8, + 0xf1, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xe8, 0xef, 0xe7, 0x47, 0x0e, 0x00, 0x00, } func (this *Result) Equal(that interface{}) bool { @@ -1162,6 +1171,9 @@ func (this *Cache) Equal(that interface{}) bool { if this.DownloadTime != that1.DownloadTime { return false } + if this.QueryLengthServed != that1.QueryLengthServed { + return false + } return true } func (this *Result) GoString() string { @@ -1275,7 +1287,7 @@ func (this *Cache) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 11) + s := make([]string, 0, 12) s = append(s, "&stats.Cache{") s = append(s, "EntriesFound: "+fmt.Sprintf("%#v", this.EntriesFound)+",\n") s = append(s, "EntriesRequested: "+fmt.Sprintf("%#v", this.EntriesRequested)+",\n") @@ -1284,6 +1296,7 @@ func (this *Cache) GoString() string { s = append(s, "BytesSent: "+fmt.Sprintf("%#v", this.BytesSent)+",\n") s = append(s, "Requests: "+fmt.Sprintf("%#v", this.Requests)+",\n") s = append(s, "DownloadTime: "+fmt.Sprintf("%#v", this.DownloadTime)+",\n") + s = append(s, "QueryLengthServed: "+fmt.Sprintf("%#v", this.QueryLengthServed)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1773,6 +1786,11 @@ func (m *Cache) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.QueryLengthServed != 0 { + i = encodeVarintStats(dAtA, i, uint64(m.QueryLengthServed)) + i-- + dAtA[i] = 0x40 + } if m.DownloadTime != 0 { i = encodeVarintStats(dAtA, i, uint64(m.DownloadTime)) i-- @@ -2030,6 +2048,9 @@ func (m *Cache) Size() (n int) { if m.DownloadTime != 0 { n += 1 + sovStats(uint64(m.DownloadTime)) } + if m.QueryLengthServed != 0 { + n += 1 + sovStats(uint64(m.QueryLengthServed)) + } return n } @@ -2158,6 +2179,7 @@ func (this *Cache) String() string { `BytesSent:` + fmt.Sprintf("%v", this.BytesSent) + `,`, `Requests:` + fmt.Sprintf("%v", this.Requests) + `,`, `DownloadTime:` + fmt.Sprintf("%v", this.DownloadTime) + `,`, + `QueryLengthServed:` + fmt.Sprintf("%v", this.QueryLengthServed) + `,`, `}`, }, "") return s @@ -3720,6 +3742,25 @@ func (m *Cache) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryLengthServed", wireType) + } + m.QueryLengthServed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.QueryLengthServed |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipStats(dAtA[iNdEx:]) diff --git a/pkg/logqlmodel/stats/stats.proto b/pkg/logqlmodel/stats/stats.proto index 0be2f2334a00b..8db5b474a7906 100644 --- a/pkg/logqlmodel/stats/stats.proto +++ b/pkg/logqlmodel/stats/stats.proto @@ -163,4 +163,5 @@ message Cache { int64 bytesSent = 5 [(gogoproto.jsontag) = "bytesSent"]; int32 requests = 6 [(gogoproto.jsontag) = "requests"]; int64 downloadTime = 7 [(gogoproto.jsontag) = "downloadTime"]; + int64 queryLengthServed = 8 [(gogoproto.jsontag) = "queryLengthServed"]; } diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index 936a702662c41..976665df95b99 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1592,7 +1592,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "index": { "entriesFound": 0, @@ -1601,7 +1602,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "statsResult": { "entriesFound": 0, @@ -1610,7 +1612,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "seriesResult": { "entriesFound": 0, @@ -1619,7 +1622,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "labelResult": { "entriesFound": 0, @@ -1628,7 +1632,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "volumeResult": { "entriesFound": 0, @@ -1637,7 +1642,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "result": { "entriesFound": 0, @@ -1646,7 +1652,8 @@ var ( "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 } }, "summary": { diff --git a/pkg/querier/queryrange/prometheus_test.go b/pkg/querier/queryrange/prometheus_test.go index 98eb563ca7bd2..a8e09b378bb2c 100644 --- a/pkg/querier/queryrange/prometheus_test.go +++ b/pkg/querier/queryrange/prometheus_test.go @@ -65,7 +65,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "index": { "entriesFound": 0, @@ -74,7 +75,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "statsResult": { "entriesFound": 0, @@ -83,7 +85,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "seriesResult": { "entriesFound": 0, @@ -92,7 +95,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "labelResult": { "entriesFound": 0, @@ -101,7 +105,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "volumeResult": { "entriesFound": 0, @@ -110,7 +115,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "result": { "entriesFound": 0, @@ -119,7 +125,8 @@ var emptyStats = `"stats": { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 } }, "summary": { diff --git a/pkg/storage/chunk/cache/resultscache/cache.go b/pkg/storage/chunk/cache/resultscache/cache.go index 0999ca3271068..527aea84bcd16 100644 --- a/pkg/storage/chunk/cache/resultscache/cache.go +++ b/pkg/storage/chunk/cache/resultscache/cache.go @@ -19,6 +19,7 @@ import ( "github.com/grafana/dskit/tenant" + "github.com/grafana/loki/pkg/logqlmodel/stats" "github.com/grafana/loki/pkg/storage/chunk/cache" "github.com/grafana/loki/pkg/util/math" "github.com/grafana/loki/pkg/util/spanlogger" @@ -187,7 +188,11 @@ func (s ResultsCache) handleHit(ctx context.Context, r Request, extents []Extent if err != nil { return nil, nil, err } + + queryLenFromCache := r.GetEnd().Sub(r.GetStart()) + st := stats.FromContext(ctx) if len(requests) == 0 { + st.AddCacheQueryLengthServed(s.cache.GetCacheType(), queryLenFromCache) response, err := s.merger.MergeResponse(responses...) // No downstream requests so no need to write back to the cache. return response, nil, err @@ -204,6 +209,7 @@ func (s ResultsCache) handleHit(ctx context.Context, r Request, extents []Extent } for _, reqResp := range reqResps { + queryLenFromCache -= reqResp.Request.GetEnd().Sub(reqResp.Request.GetStart()) responses = append(responses, reqResp.Response) if s.shouldCacheRes != nil && !s.shouldCacheRes(ctx, r, reqResp.Response, maxCacheTime) { continue @@ -267,6 +273,7 @@ func (s ResultsCache) handleHit(ctx context.Context, r Request, extents []Extent return nil, nil, err } + st.AddCacheQueryLengthServed(s.cache.GetCacheType(), queryLenFromCache) response, err := s.merger.MergeResponse(responses...) return response, mergedExtents, err } diff --git a/pkg/storage/chunk/cache/resultscache/cache_test.go b/pkg/storage/chunk/cache/resultscache/cache_test.go index db6e9d6c8a4a1..bacedd2dda6ba 100644 --- a/pkg/storage/chunk/cache/resultscache/cache_test.go +++ b/pkg/storage/chunk/cache/resultscache/cache_test.go @@ -370,6 +370,7 @@ func TestHandleHit(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { sut := ResultsCache{ + cache: cache.NewMockCache(), extractor: MockExtractor{}, minCacheExtent: 10, limits: mockLimits{}, @@ -391,6 +392,62 @@ func TestHandleHit(t *testing.T) { } } +func TestHandleHit_queryLengthServed(t *testing.T) { + rc := ResultsCache{ + cache: &mockResultsCache{}, + extractor: MockExtractor{}, + limits: mockLimits{}, + merger: MockMerger{}, + parallelismForReq: func(_ context.Context, tenantIDs []string, r Request) int { return 1 }, + next: HandlerFunc(func(_ context.Context, req Request) (Response, error) { + return mkAPIResponse(req.GetStart().UnixMilli(), req.GetEnd().UnixMilli(), req.GetStep()), nil + }), + } + + statsCtx, ctx := stats.NewContext(context.Background()) + ctx = user.InjectOrgID(ctx, "1") + + input := &MockRequest{ + Start: time.UnixMilli(100), + End: time.UnixMilli(130), + Step: 5, + } + + // no cached response + _, _, err := rc.handleHit(ctx, input, nil, 0) + require.NoError(t, err) + require.Equal(t, int64(0), statsCtx.Caches().Result.QueryLengthServed) + + // partial hit + extents := []Extent{ + mkExtentWithStep(60, 80, 5), + mkExtentWithStep(90, 105, 5), + } + statsCtx, ctx = stats.NewContext(ctx) + _, _, err = rc.handleHit(ctx, input, extents, 0) + require.NoError(t, err) + require.Equal(t, int64(5*time.Millisecond), statsCtx.Caches().Result.QueryLengthServed) + + extents = []Extent{ + mkExtentWithStep(90, 105, 5), + mkExtentWithStep(110, 120, 5), + } + statsCtx, ctx = stats.NewContext(ctx) + _, _, err = rc.handleHit(ctx, input, extents, 0) + require.NoError(t, err) + require.Equal(t, int64(15*time.Millisecond), statsCtx.Caches().Result.QueryLengthServed) + + // entire query served from cache + extents = []Extent{ + mkExtentWithStep(90, 110, 5), + mkExtentWithStep(110, 130, 5), + } + statsCtx, ctx = stats.NewContext(ctx) + _, _, err = rc.handleHit(ctx, input, extents, 0) + require.NoError(t, err) + require.Equal(t, int64(30*time.Millisecond), statsCtx.Caches().Result.QueryLengthServed) +} + func TestResultsCacheMaxFreshness(t *testing.T) { modelNow := model.Now() for i, tc := range []struct { @@ -603,3 +660,20 @@ type mockLimits struct { func (m mockLimits) MaxCacheFreshness(context.Context, string) time.Duration { return m.maxCacheFreshness } + +type mockResultsCache struct{} + +func (m mockResultsCache) Store(context.Context, []string, [][]byte) error { + panic("not implemented") +} +func (m mockResultsCache) Fetch(context.Context, []string) ([]string, [][]byte, []string, error) { + panic("not implemented") +} +func (m mockResultsCache) Stop() { + panic("not implemented") +} + +func (m mockResultsCache) GetCacheType() stats.CacheType { + // returning results cache since we do not support storing stats for "mock" cache + return stats.ResultCache +} diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index bc5ae29cd1085..6e07d84615928 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -108,7 +108,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "index": { "entriesFound": 0, @@ -117,7 +118,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "statsResult": { "entriesFound": 0, @@ -126,7 +128,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "seriesResult": { "entriesFound": 0, @@ -135,7 +138,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "labelResult": { "entriesFound": 0, @@ -144,7 +148,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "volumeResult": { "entriesFound": 0, @@ -153,7 +158,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "result": { "entriesFound": 0, @@ -162,7 +168,8 @@ var queryTests = []struct { "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 } }, "summary": { diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index 87fe3fdca9329..d5336298c37c8 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -76,7 +76,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "index": { "entriesFound": 0, @@ -85,7 +86,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "statsResult": { "entriesFound": 0, @@ -94,7 +96,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "seriesResult": { "entriesFound": 0, @@ -103,7 +106,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "labelResult": { "entriesFound": 0, @@ -112,7 +116,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "volumeResult": { "entriesFound": 0, @@ -121,7 +126,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 }, "result": { "entriesFound": 0, @@ -130,7 +136,8 @@ const emptyStats = `{ "bytesReceived": 0, "bytesSent": 0, "requests": 0, - "downloadTime": 0 + "downloadTime": 0, + "queryLengthServed": 0 } }, "summary": {