From e87461265d15f9c15414510da0f8c210f0c241bb Mon Sep 17 00:00:00 2001 From: Ed Welch Date: Mon, 12 Feb 2024 10:23:46 -0500 Subject: [PATCH] Backport chunk_refs_fetch_time to 2.9.x branch (#11891) This backports https://github.com/grafana/loki/pull/10362 into the 2.9.x branch I recently talked about this metric in a blogpost on query performance not realizing it wasn't available in the latest release. Would like to make it available sooner than 3.0 Signed-off-by: Edward Welch --- pkg/logql/metrics.go | 1 + pkg/logqlmodel/stats/context.go | 11 ++ pkg/logqlmodel/stats/stats.pb.go | 184 +++++++++++++--------- pkg/logqlmodel/stats/stats.proto | 3 + pkg/querier/http_test.go | 6 +- pkg/querier/queryrange/codec_test.go | 7 +- pkg/querier/queryrange/prometheus_test.go | 2 + pkg/storage/store.go | 3 + pkg/util/marshal/legacy/marshal_test.go | 2 + pkg/util/marshal/marshal_test.go | 6 + 10 files changed, 150 insertions(+), 75 deletions(-) diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 3a9eae13e2f0..60799e2d0266 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -138,6 +138,7 @@ func RecordRangeAndInstantQueryMetrics( "queue_time", logql_stats.ConvertSecondsToNanoseconds(stats.Summary.QueueTime), "splits", stats.Summary.Splits, "shards", stats.Summary.Shards, + "chunk_refs_fetch_time", stats.ChunkRefsFetchTime(), "cache_chunk_req", stats.Caches.Chunk.EntriesRequested, "cache_chunk_hit", stats.Caches.Chunk.EntriesFound, "cache_chunk_bytes_stored", stats.Caches.Chunk.BytesSent, diff --git a/pkg/logqlmodel/stats/context.go b/pkg/logqlmodel/stats/context.go index 6ed39f130b16..05bc5925430b 100644 --- a/pkg/logqlmodel/stats/context.go +++ b/pkg/logqlmodel/stats/context.go @@ -173,6 +173,7 @@ func (s *Store) Merge(m Store) { s.TotalChunksRef += m.TotalChunksRef s.TotalChunksDownloaded += m.TotalChunksDownloaded s.ChunksDownloadTime += m.ChunksDownloadTime + s.ChunkRefsFetchTime += m.ChunkRefsFetchTime s.Chunk.HeadChunkBytes += m.Chunk.HeadChunkBytes s.Chunk.HeadChunkStructuredMetadataBytes += m.Chunk.HeadChunkStructuredMetadataBytes s.Chunk.HeadChunkLines += m.Chunk.HeadChunkLines @@ -247,6 +248,10 @@ func (r Result) ChunksDownloadTime() time.Duration { return time.Duration(r.Querier.Store.ChunksDownloadTime + r.Ingester.Store.ChunksDownloadTime) } +func (r Result) ChunkRefsFetchTime() time.Duration { + return time.Duration(r.Querier.Store.ChunkRefsFetchTime + r.Ingester.Store.ChunkRefsFetchTime) +} + func (r Result) TotalDuplicates() int64 { return r.Querier.Store.Chunk.TotalDuplicates + r.Ingester.Store.Chunk.TotalDuplicates } @@ -320,6 +325,10 @@ func (c *Context) AddChunksDownloadTime(i time.Duration) { atomic.AddInt64(&c.store.ChunksDownloadTime, int64(i)) } +func (c *Context) AddChunkRefsFetchTime(i time.Duration) { + atomic.AddInt64(&c.store.ChunkRefsFetchTime, int64(i)) +} + func (c *Context) AddChunksDownloaded(i int64) { atomic.AddInt64(&c.store.TotalChunksDownloaded, i) } @@ -433,6 +442,7 @@ func (r Result) Log(log log.Logger) { "Ingester.TotalChunksRef", r.Ingester.Store.TotalChunksRef, "Ingester.TotalChunksDownloaded", r.Ingester.Store.TotalChunksDownloaded, "Ingester.ChunksDownloadTime", time.Duration(r.Ingester.Store.ChunksDownloadTime), + "Ingester.ChunkRefsFetchTime", time.Duration(r.Ingester.Store.ChunkRefsFetchTime), "Ingester.HeadChunkBytes", humanize.Bytes(uint64(r.Ingester.Store.Chunk.HeadChunkBytes)), "Ingester.HeadChunkLines", r.Ingester.Store.Chunk.HeadChunkLines, "Ingester.DecompressedBytes", humanize.Bytes(uint64(r.Ingester.Store.Chunk.DecompressedBytes)), @@ -444,6 +454,7 @@ func (r Result) Log(log log.Logger) { "Querier.TotalChunksRef", r.Querier.Store.TotalChunksRef, "Querier.TotalChunksDownloaded", r.Querier.Store.TotalChunksDownloaded, "Querier.ChunksDownloadTime", time.Duration(r.Querier.Store.ChunksDownloadTime), + "Querier.ChunkRefsFetchTime", time.Duration(r.Querier.Store.ChunkRefsFetchTime), "Querier.HeadChunkBytes", humanize.Bytes(uint64(r.Querier.Store.Chunk.HeadChunkBytes)), "Querier.HeadChunkLines", r.Querier.Store.Chunk.HeadChunkLines, "Querier.DecompressedBytes", humanize.Bytes(uint64(r.Querier.Store.Chunk.DecompressedBytes)), diff --git a/pkg/logqlmodel/stats/stats.pb.go b/pkg/logqlmodel/stats/stats.pb.go index 400a1a4d2b0a..be2630d969cf 100644 --- a/pkg/logqlmodel/stats/stats.pb.go +++ b/pkg/logqlmodel/stats/stats.pb.go @@ -440,6 +440,8 @@ type Store struct { // Time spent fetching chunks in nanoseconds. ChunksDownloadTime int64 `protobuf:"varint,3,opt,name=chunksDownloadTime,proto3" json:"chunksDownloadTime"` Chunk Chunk `protobuf:"bytes,4,opt,name=chunk,proto3" json:"chunk"` + // Time spent fetching chunk refs from index. + ChunkRefsFetchTime int64 `protobuf:"varint,5,opt,name=chunkRefsFetchTime,proto3" json:"chunkRefsFetchTime"` } func (m *Store) Reset() { *m = Store{} } @@ -502,6 +504,13 @@ func (m *Store) GetChunk() Chunk { return Chunk{} } +func (m *Store) GetChunkRefsFetchTime() int64 { + if m != nil { + return m.ChunkRefsFetchTime + } + return 0 +} + type Chunk struct { // Total bytes processed but was already in memory (found in the headchunk). Includes structured metadata bytes. HeadChunkBytes int64 `protobuf:"varint,4,opt,name=headChunkBytes,proto3" json:"headChunkBytes"` @@ -723,76 +732,77 @@ func init() { func init() { proto.RegisterFile("pkg/logqlmodel/stats/stats.proto", fileDescriptor_6cdfe5d2aea33ebb) } var fileDescriptor_6cdfe5d2aea33ebb = []byte{ - // 1090 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0x4d, 0x6f, 0xe4, 0x44, - 0x13, 0x1e, 0x27, 0xaf, 0x67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0xf6, 0xbd, 0x3c, 0xb3, 0xea, 0x0e, 0xa8, 0x9b, 0x42, 0x88, 0x8f, 0x1c, 0x60, - 0x2e, 0xf3, 0xbf, 0x2f, 0x5e, 0x08, 0x28, 0xac, 0x39, 0xa0, 0x6e, 0x8a, 0xbb, 0x1e, 0x01, 0xac, - 0x92, 0x32, 0xbd, 0xf0, 0xae, 0x2f, 0x40, 0x28, 0xbb, 0xe2, 0x09, 0x11, 0xcb, 0xb5, 0xca, 0x5c, - 0xd2, 0xe5, 0x13, 0x62, 0x86, 0x41, 0xd1, 0x13, 0x01, 0xf4, 0xaa, 0x55, 0xa7, 0x57, 0xd6, 0xed, - 0x2a, 0x0e, 0x35, 0xcb, 0xbe, 0xb8, 0xb9, 0x35, 0x3b, 0x2f, 0x6e, 0xcd, 0xce, 0xcb, 0x5b, 0x53, - 0xfb, 0x69, 0x6a, 0x6a, 0xbf, 0x4e, 0x4d, 0xed, 0xf9, 0xd4, 0xd4, 0x6e, 0xa6, 0xa6, 0xf6, 0xe7, - 0xd4, 0xd4, 0xfe, 0x9a, 0x9a, 0x9d, 0x97, 0x53, 0x53, 0xfb, 0xe5, 0xce, 0xec, 0xdc, 0xdc, 0x99, - 0x9d, 0x17, 0x77, 0x66, 0xe7, 0xbb, 0xf7, 0x87, 0x3e, 0x1f, 0xa5, 0x17, 0x47, 0x6e, 0x34, 0x1e, - 0x0c, 0x63, 0xe7, 0xa9, 0x13, 0x3a, 0x83, 0x20, 0xba, 0xf4, 0x07, 0x6d, 0xff, 0x30, 0x2e, 0xba, - 0xf8, 0xff, 0xe1, 0xa3, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x9a, 0xb8, 0xf1, 0x80, 0x0c, - 0x00, 0x00, + // 1107 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0xcd, 0x6e, 0xe4, 0x44, + 0x10, 0x1e, 0x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 0x7b, 0x37, 0xcf, 0xac, 0x39, 0x1f, 0xcc, 0x21, 0xf4, 0x33, 0xb2, 0xa1, 0x30, 0xec, + 0x4b, 0xf2, 0xee, 0xa1, 0xdb, 0xf7, 0xf2, 0xcc, 0xaa, 0x3b, 0xa0, 0x6e, 0x0a, 0x21, 0x5e, 0x96, + 0x80, 0xb9, 0xcc, 0xff, 0xb1, 0xb8, 0x69, 0xa0, 0xb0, 0xe6, 0x80, 0xba, 0x29, 0xee, 0x0c, 0x08, + 0x60, 0xb7, 0x95, 0xe5, 0x85, 0x77, 0x86, 0x02, 0x84, 0x72, 0x2a, 0xae, 0x22, 0xb1, 0xdc, 0xab, + 0xac, 0x25, 0x5d, 0x5e, 0x45, 0x66, 0x18, 0x14, 0x33, 0x91, 0x40, 0xaf, 0xda, 0xbd, 0x7a, 0x65, + 0xff, 0xaf, 0xe2, 0x50, 0xb3, 0xec, 0xb3, 0xeb, 0x1b, 0xb3, 0xf3, 0xfc, 0xc6, 0xec, 0xbc, 0xb8, + 0x31, 0xb5, 0x5f, 0xa6, 0xa6, 0xf6, 0xdb, 0xd4, 0xd4, 0x9e, 0x4d, 0x4d, 0xed, 0x7a, 0x6a, 0x6a, + 0x7f, 0x4f, 0x4d, 0xed, 0x9f, 0xa9, 0xd9, 0x79, 0x31, 0x35, 0xb5, 0x5f, 0x6f, 0xcd, 0xce, 0xf5, + 0xad, 0xd9, 0x79, 0x7e, 0x6b, 0x76, 0x7e, 0xf8, 0x70, 0xe8, 0xf3, 0x51, 0x7a, 0x76, 0xe0, 0x46, + 0xe3, 0xc1, 0x30, 0x76, 0xce, 0x9d, 0xd0, 0x19, 0x04, 0xd1, 0x85, 0x3f, 0x68, 0xfb, 0xa7, 0x72, + 0xd6, 0xc5, 0xff, 0x21, 0x9f, 0xbc, 0x0c, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x6e, 0x03, 0xf3, 0xc8, + 0x0c, 0x00, 0x00, } func (this *Result) Equal(that interface{}) bool { @@ -1009,6 +1019,9 @@ func (this *Store) Equal(that interface{}) bool { if !this.Chunk.Equal(&that1.Chunk) { return false } + if this.ChunkRefsFetchTime != that1.ChunkRefsFetchTime { + return false + } return true } func (this *Chunk) Equal(that interface{}) bool { @@ -1176,12 +1189,13 @@ func (this *Store) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 9) s = append(s, "&stats.Store{") s = append(s, "TotalChunksRef: "+fmt.Sprintf("%#v", this.TotalChunksRef)+",\n") s = append(s, "TotalChunksDownloaded: "+fmt.Sprintf("%#v", this.TotalChunksDownloaded)+",\n") s = append(s, "ChunksDownloadTime: "+fmt.Sprintf("%#v", this.ChunksDownloadTime)+",\n") s = append(s, "Chunk: "+strings.Replace(this.Chunk.GoString(), `&`, ``, 1)+",\n") + s = append(s, "ChunkRefsFetchTime: "+fmt.Sprintf("%#v", this.ChunkRefsFetchTime)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1544,6 +1558,11 @@ func (m *Store) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ChunkRefsFetchTime != 0 { + i = encodeVarintStats(dAtA, i, uint64(m.ChunkRefsFetchTime)) + i-- + dAtA[i] = 0x28 + } { size, err := m.Chunk.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -1839,6 +1858,9 @@ func (m *Store) Size() (n int) { } l = m.Chunk.Size() n += 1 + l + sovStats(uint64(l)) + if m.ChunkRefsFetchTime != 0 { + n += 1 + sovStats(uint64(m.ChunkRefsFetchTime)) + } return n } @@ -1994,6 +2016,7 @@ func (this *Store) String() string { `TotalChunksDownloaded:` + fmt.Sprintf("%v", this.TotalChunksDownloaded) + `,`, `ChunksDownloadTime:` + fmt.Sprintf("%v", this.ChunksDownloadTime) + `,`, `Chunk:` + strings.Replace(strings.Replace(this.Chunk.String(), "Chunk", "Chunk", 1), `&`, ``, 1) + `,`, + `ChunkRefsFetchTime:` + fmt.Sprintf("%v", this.ChunkRefsFetchTime) + `,`, `}`, }, "") return s @@ -3042,6 +3065,25 @@ func (m *Store) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ChunkRefsFetchTime", wireType) + } + m.ChunkRefsFetchTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStats + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ChunkRefsFetchTime |= 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 6d5656f9519a..f336205da880 100644 --- a/pkg/logqlmodel/stats/stats.proto +++ b/pkg/logqlmodel/stats/stats.proto @@ -115,6 +115,9 @@ message Store { (gogoproto.nullable) = false, (gogoproto.jsontag) = "chunk" ]; + + // Time spent fetching chunk refs from index. + int64 chunkRefsFetchTime = 5 [(gogoproto.jsontag) = "chunkRefsFetchTime"]; } message Chunk { diff --git a/pkg/querier/http_test.go b/pkg/querier/http_test.go index d54b9e15079f..84d657d3bd82 100644 --- a/pkg/querier/http_test.go +++ b/pkg/querier/http_test.go @@ -41,7 +41,8 @@ var ( }, "chunksDownloadTime": 0, "totalChunksRef": 0, - "totalChunksDownloaded": 0 + "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0 }, "totalBatches": 6, "totalChunksMatched": 7, @@ -63,7 +64,8 @@ var ( }, "chunksDownloadTime": 16, "totalChunksRef": 17, - "totalChunksDownloaded": 18 + "totalChunksDownloaded": 18, + "chunkRefsFetchTime": 0 } }, "cache": { diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index 255a9bfe5938..f48b6716ce72 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1349,7 +1349,8 @@ var ( }, "chunksDownloadTime": 0, "totalChunksRef": 0, - "totalChunksDownloaded": 0 + "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0 }, "totalBatches": 6, "totalChunksMatched": 7, @@ -1371,7 +1372,8 @@ var ( }, "chunksDownloadTime": 16, "totalChunksRef": 17, - "totalChunksDownloaded": 18 + "totalChunksDownloaded": 18, + "chunkRefsFetchTime": 19 } }, "cache": { @@ -1607,6 +1609,7 @@ var ( ChunksDownloadTime: 16, TotalChunksRef: 17, TotalChunksDownloaded: 18, + ChunkRefsFetchTime: 19, }, }, diff --git a/pkg/querier/queryrange/prometheus_test.go b/pkg/querier/queryrange/prometheus_test.go index 98d13973f003..6efb1138ebf5 100644 --- a/pkg/querier/queryrange/prometheus_test.go +++ b/pkg/querier/queryrange/prometheus_test.go @@ -18,6 +18,7 @@ var emptyStats = `"stats": { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -40,6 +41,7 @@ var emptyStats = `"stats": { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, diff --git a/pkg/storage/store.go b/pkg/storage/store.go index b9e5be9bf6a0..85c4bcc02308 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -379,7 +379,10 @@ func (s *store) lazyChunks(ctx context.Context, matchers []*labels.Matcher, from stats := stats.FromContext(ctx) + start := time.Now() chks, fetchers, err := s.GetChunkRefs(ctx, userID, from, through, matchers...) + stats.AddChunkRefsFetchTime(time.Since(start)) + if err != nil { return nil, err } diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index 40eed27fbfd5..78f310b8706c 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -65,6 +65,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -87,6 +88,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index d412c00a58ce..adcacb31047a 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -67,6 +67,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -89,6 +90,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -221,6 +223,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -243,6 +246,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -396,6 +400,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0, @@ -418,6 +423,7 @@ var queryTests = []struct { "chunksDownloadTime": 0, "totalChunksRef": 0, "totalChunksDownloaded": 0, + "chunkRefsFetchTime": 0, "chunk" :{ "compressedBytes": 0, "decompressedBytes": 0,