mirror of https://github.com/prometheus/prometheus
Clarify computeChunkEndTime's purpose (#9049)
I was struggling to understand the purpose of this method until I tweaked the tests, so I decided to write down my observations. Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>pull/9132/head
parent
ed24e51e7c
commit
f9482c5bf6
13
tsdb/head.go
13
tsdb/head.go
|
@ -2607,8 +2607,9 @@ func (s *memSeries) append(t int64, v float64, appendID uint64, chunkDiskMapper
|
||||||
if c.maxTime >= t {
|
if c.maxTime >= t {
|
||||||
return false, chunkCreated
|
return false, chunkCreated
|
||||||
}
|
}
|
||||||
// If we reach 25% of a chunk's desired sample count, set a definitive time
|
// If we reach 25% of a chunk's desired sample count, predict an end time
|
||||||
// at which to start the next chunk.
|
// for this chunk that will try to make samples equally distributed within
|
||||||
|
// the remaining chunks in the current chunk range.
|
||||||
// At latest it must happen at the timestamp set when the chunk was cut.
|
// At latest it must happen at the timestamp set when the chunk was cut.
|
||||||
if numSamples == samplesPerChunk/4 {
|
if numSamples == samplesPerChunk/4 {
|
||||||
s.nextAt = computeChunkEndTime(c.minTime, c.maxTime, s.nextAt)
|
s.nextAt = computeChunkEndTime(c.minTime, c.maxTime, s.nextAt)
|
||||||
|
@ -2642,12 +2643,14 @@ func (s *memSeries) cleanupAppendIDsBelow(bound uint64) {
|
||||||
// computeChunkEndTime estimates the end timestamp based the beginning of a
|
// computeChunkEndTime estimates the end timestamp based the beginning of a
|
||||||
// chunk, its current timestamp and the upper bound up to which we insert data.
|
// chunk, its current timestamp and the upper bound up to which we insert data.
|
||||||
// It assumes that the time range is 1/4 full.
|
// It assumes that the time range is 1/4 full.
|
||||||
|
// Assuming that the samples will keep arriving at the same rate, it will make the
|
||||||
|
// remaining n chunks within this chunk range (before max) equally sized.
|
||||||
func computeChunkEndTime(start, cur, max int64) int64 {
|
func computeChunkEndTime(start, cur, max int64) int64 {
|
||||||
a := (max - start) / ((cur - start + 1) * 4)
|
n := (max - start) / ((cur - start + 1) * 4)
|
||||||
if a == 0 {
|
if n <= 1 {
|
||||||
return max
|
return max
|
||||||
}
|
}
|
||||||
return start + (max-start)/a
|
return start + (max-start)/n
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator returns a chunk iterator.
|
// iterator returns a chunk iterator.
|
||||||
|
|
Loading…
Reference in New Issue