diff --git a/CHANGELOG.md b/CHANGELOG.md index 26af0ed271..c8804367c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [8971](https://github.com/grafana/loki/pull/8971) **dannykopping**: Stats: fix `Cache.Chunk.BytesSent` statistic and loki_chunk_fetcher_fetched_size_bytes metric with correct chunk size. * [8979](https://github.com/grafana/loki/pull/8979) **slim-bean**: Fix the case where a logs query with start time == end time was returning logs when none should be returned. +* [9099](https://github.com/grafana/loki/pull/9099) **salvacorts**: Fix the estimated size of chunks when writing a new TSDB file during compaction. ### All Changes diff --git a/pkg/storage/stores/tsdb/compactor.go b/pkg/storage/stores/tsdb/compactor.go index 11f66ed320..f8f833b95f 100644 --- a/pkg/storage/stores/tsdb/compactor.go +++ b/pkg/storage/stores/tsdb/compactor.go @@ -360,11 +360,12 @@ func (c *compactedIndex) ToIndexFile() (index_shipper.Index, error) { b.Del(labels.MetricName) ls := b.Labels(nil) + approxKB := math.Round(float64(chk.Data.UncompressedSize()) / float64(1<<10)) err := c.builder.InsertChunk(ls.String(), index.ChunkMeta{ Checksum: chk.Checksum, MinTime: int64(chk.From), MaxTime: int64(chk.Through), - KB: uint32(chk.Size()) / (1 << 10), + KB: uint32(approxKB), Entries: uint32(chk.Data.Entries()), }) if err != nil { diff --git a/pkg/storage/stores/tsdb/compactor_test.go b/pkg/storage/stores/tsdb/compactor_test.go index e8d4acdd7e..cb7ee9a85c 100644 --- a/pkg/storage/stores/tsdb/compactor_test.go +++ b/pkg/storage/stores/tsdb/compactor_test.go @@ -202,6 +202,7 @@ func buildChunkMetas(from, to int64) index.ChunkMetas { MaxTime: i + 1, Checksum: uint32(i), Entries: 1, + KB: 1, }) } @@ -897,6 +898,10 @@ type dummyChunkData struct { chunk.Data } +func (d dummyChunkData) UncompressedSize() int { + return 1 << 10 // 1KB +} + func (d dummyChunkData) Entries() int { return 1 }