mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix last timestamp initialization
This initializes the chunkDesc's last timestamp to the minimum value so initial samples with a timestamp of 0 (e.g. in tests) are not accidentally dropped.
This commit is contained in:
parent
40cf215fba
commit
3f72d5d027
10
db.go
10
db.go
|
@ -538,17 +538,17 @@ type chunkDesc struct {
|
||||||
chunk chunks.Chunk
|
chunk chunks.Chunk
|
||||||
|
|
||||||
// Caching fields.
|
// Caching fields.
|
||||||
firsTimestamp int64
|
firstTimestamp int64
|
||||||
lastTimestamp int64
|
lastTimestamp int64
|
||||||
lastValue float64
|
lastValue float64
|
||||||
numSamples int
|
numSamples int
|
||||||
|
|
||||||
app chunks.Appender // Current appender for the chunks.
|
app chunks.Appender // Current appender for the chunks.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cd *chunkDesc) append(ts int64, v float64) {
|
func (cd *chunkDesc) append(ts int64, v float64) {
|
||||||
if cd.numSamples == 0 {
|
if cd.numSamples == 0 {
|
||||||
cd.firsTimestamp = ts
|
cd.firstTimestamp = ts
|
||||||
}
|
}
|
||||||
cd.app.Append(ts, v)
|
cd.app.Append(ts, v)
|
||||||
|
|
||||||
|
|
11
head.go
11
head.go
|
@ -2,6 +2,7 @@ package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ func (h *HeadBlock) Series(ref uint32) (labels.Labels, []ChunkMeta, error) {
|
||||||
cd := h.descs[ref]
|
cd := h.descs[ref]
|
||||||
|
|
||||||
meta := ChunkMeta{
|
meta := ChunkMeta{
|
||||||
MinTime: cd.firsTimestamp,
|
MinTime: cd.firstTimestamp,
|
||||||
MaxTime: cd.lastTimestamp,
|
MaxTime: cd.lastTimestamp,
|
||||||
Ref: ref,
|
Ref: ref,
|
||||||
}
|
}
|
||||||
|
@ -155,9 +156,11 @@ func (h *HeadBlock) create(hash uint64, lset labels.Labels) *chunkDesc {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
cd := &chunkDesc{
|
cd := &chunkDesc{
|
||||||
lset: lset,
|
lset: lset,
|
||||||
chunk: chunks.NewXORChunk(),
|
chunk: chunks.NewXORChunk(),
|
||||||
|
lastTimestamp: math.MinInt64,
|
||||||
}
|
}
|
||||||
|
|
||||||
cd.app, err = cd.chunk.Appender()
|
cd.app, err = cd.chunk.Appender()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Getting an Appender for a new chunk must not panic.
|
// Getting an Appender for a new chunk must not panic.
|
||||||
|
@ -276,7 +279,7 @@ func (h *HeadBlock) persist(indexw IndexWriter, chunkw SeriesWriter) error {
|
||||||
for ref, cd := range h.descs {
|
for ref, cd := range h.descs {
|
||||||
if err := chunkw.WriteSeries(uint32(ref), cd.lset, []ChunkMeta{
|
if err := chunkw.WriteSeries(uint32(ref), cd.lset, []ChunkMeta{
|
||||||
{
|
{
|
||||||
MinTime: cd.firsTimestamp,
|
MinTime: cd.firstTimestamp,
|
||||||
MaxTime: cd.lastTimestamp,
|
MaxTime: cd.lastTimestamp,
|
||||||
Chunk: cd.chunk,
|
Chunk: cd.chunk,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue