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

Add series size to index stats #6425

Merged
merged 1 commit into from
Jun 12, 2023
Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it impossible for a series ref to be 0? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use a ref of 0 when appending to new series in tsdb, so I assume it's a reserved value: https://github.com/prometheus/prometheus/blob/394da05dd407f07b592b097ee6a7b4a54d9d9967/storage/interface.go#L220-L228

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r.Series(id, &builder, &chks) will read from the seriesRef as the offset. If seriesRef is 0 that means series section starts at the first byte of index file, this seems impossible.

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
Loading