mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
d742edfe0d
Large delta values often imply a difference between a large base value and the large delta value, potentially resulting in small numbers with a huge precision error. Since large delta values need 8 bytes anyway, we are not even saving memory. As a solution, always save the absoluto value rather than a delta once 8 bytes would be needed for the delta. Timestamps are then saved as 8 byte integers, while values are always saved as float64 in that case. Change-Id: I01100d600515e16df58ce508b50982ffd762cc49
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package storage_ng
|
|
|
|
import (
|
|
"io"
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
|
)
|
|
|
|
type chunks []chunk
|
|
|
|
type chunk interface {
|
|
add(*metric.SamplePair) chunks
|
|
clone() chunk
|
|
firstTime() clientmodel.Timestamp
|
|
lastTime() clientmodel.Timestamp
|
|
newIterator() chunkIterator
|
|
marshal(io.Writer) error
|
|
unmarshal(io.Reader) error
|
|
close()
|
|
|
|
// TODO: remove?
|
|
values() <-chan *metric.SamplePair
|
|
}
|
|
|
|
type chunkIterator interface {
|
|
getValueAtTime(clientmodel.Timestamp) metric.Values
|
|
getBoundaryValues(metric.Interval) metric.Values
|
|
getRangeValues(metric.Interval) metric.Values
|
|
contains(clientmodel.Timestamp) bool
|
|
}
|
|
|
|
func transcodeAndAdd(dst chunk, src chunk, s *metric.SamplePair) chunks {
|
|
numTranscodes.Inc()
|
|
defer src.close()
|
|
|
|
head := dst
|
|
body := chunks{}
|
|
for v := range src.values() {
|
|
newChunks := head.add(v)
|
|
body = append(body, newChunks[:len(newChunks)-1]...)
|
|
head = newChunks[len(newChunks)-1]
|
|
}
|
|
newChunks := head.add(s)
|
|
body = append(body, newChunks[:len(newChunks)-1]...)
|
|
head = newChunks[len(newChunks)-1]
|
|
return append(body, head)
|
|
}
|
|
|
|
func chunkType(c chunk) byte {
|
|
switch c.(type) {
|
|
case *deltaEncodedChunk:
|
|
return 0
|
|
default:
|
|
panic("unknown chunk type")
|
|
}
|
|
}
|
|
|
|
func chunkForType(chunkType byte) chunk {
|
|
switch chunkType {
|
|
case 0:
|
|
return newDeltaEncodedChunk(d1, d0, true)
|
|
default:
|
|
panic("unknown chunk type")
|
|
}
|
|
}
|