Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimate chunk size on compaction looking at data uncompressed size #9099

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/stores/tsdb/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/storage/stores/tsdb/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func buildChunkMetas(from, to int64) index.ChunkMetas {
MaxTime: i + 1,
Checksum: uint32(i),
Entries: 1,
KB: 1,
})
}

Expand Down Expand Up @@ -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
}