Skip to content

Commit

Permalink
add approximate series size to index stats (thanos-io#6425)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored and HC Zhu committed Jun 27, 2023
1 parent 4e69ba7 commit bc59229
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/block/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type HealthStats struct {
ChunkAvgSize int64
ChunkMaxSize int64

SeriesMinSize int64
SeriesAvgSize int64
SeriesMaxSize int64

SingleSampleSeries int64
SingleSampleChunks int64

Expand Down Expand Up @@ -231,6 +235,7 @@ func GatherIndexHealthStats(logger log.Logger, fn string, minTime, maxTime int64
seriesChunks = newMinMaxSumInt64()
chunkDuration = newMinMaxSumInt64()
chunkSize = newMinMaxSumInt64()
seriesSize = newMinMaxSumInt64()
)

lnames, err := r.LabelNames()
Expand All @@ -245,11 +250,25 @@ func GatherIndexHealthStats(logger log.Logger, fn string, minTime, maxTime int64
}
stats.MetricLabelValuesCount = int64(len(lvals))

// As of version two all series entries are 16 byte padded. All references
// we get have to account for that to get the correct offset.
offsetMultiplier := 1
version := r.Version()
if version >= 2 {
offsetMultiplier = 16
}

// Per series.
var prevId storage.SeriesRef
for p.Next() {
lastLset = append(lastLset[:0], lset...)

id := p.At()
if prevId != 0 {
// Approximate size.
seriesSize.Add(int64(id-prevId) * int64(offsetMultiplier))
}
prevId = id
stats.TotalSeries++

if err := r.Series(id, &builder, &chks); err != nil {
Expand Down Expand Up @@ -362,6 +381,10 @@ func GatherIndexHealthStats(logger log.Logger, fn string, minTime, maxTime int64
stats.ChunkAvgSize = chunkSize.Avg()
stats.ChunkMinSize = chunkSize.min

stats.SeriesMaxSize = seriesSize.max
stats.SeriesAvgSize = seriesSize.Avg()
stats.SeriesMinSize = seriesSize.min

stats.ChunkMaxDuration = time.Duration(chunkDuration.max) * time.Millisecond
stats.ChunkAvgDuration = time.Duration(chunkDuration.Avg()) * time.Millisecond
stats.ChunkMinDuration = time.Duration(chunkDuration.min) * time.Millisecond
Expand Down

0 comments on commit bc59229

Please sign in to comment.