mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Remove unnecessary code in encoding/decoding histograms (#11252)
* Remove unnecessary code in encoding/decoding histograms Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * Fix review comments Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
4f7f5cdfd7
commit
b2d01cbc57
|
@ -377,8 +377,7 @@ func (a *HistogramAppender) AppendHistogram(t int64, h *histogram.Histogram) {
|
||||||
h = &histogram.Histogram{Sum: h.Sum}
|
h = &histogram.Histogram{Sum: h.Sum}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch num {
|
if num == 0 {
|
||||||
case 0:
|
|
||||||
// The first append gets the privilege to dictate the layout
|
// The first append gets the privilege to dictate the layout
|
||||||
// but it's also responsible for encoding it into the chunk!
|
// but it's also responsible for encoding it into the chunk!
|
||||||
writeHistogramChunkLayout(a.b, h.Schema, h.ZeroThreshold, h.PositiveSpans, h.NegativeSpans)
|
writeHistogramChunkLayout(a.b, h.Schema, h.ZeroThreshold, h.PositiveSpans, h.NegativeSpans)
|
||||||
|
@ -425,36 +424,10 @@ func (a *HistogramAppender) AppendHistogram(t int64, h *histogram.Histogram) {
|
||||||
for _, b := range h.NegativeBuckets {
|
for _, b := range h.NegativeBuckets {
|
||||||
putVarbitInt(a.b, b)
|
putVarbitInt(a.b, b)
|
||||||
}
|
}
|
||||||
case 1:
|
} else {
|
||||||
tDelta = t - a.t
|
// The case for the 2nd sample with single deltas is implicitly handled correctly with the double delta code,
|
||||||
if tDelta < 0 {
|
// so we don't need a separate single delta logic for the 2nd sample.
|
||||||
panic("out of order timestamp")
|
|
||||||
}
|
|
||||||
cntDelta = int64(h.Count) - int64(a.cnt)
|
|
||||||
zCntDelta = int64(h.ZeroCount) - int64(a.zCnt)
|
|
||||||
|
|
||||||
if value.IsStaleNaN(h.Sum) {
|
|
||||||
cntDelta, zCntDelta = 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
putVarbitUint(a.b, uint64(tDelta))
|
|
||||||
putVarbitInt(a.b, cntDelta)
|
|
||||||
putVarbitInt(a.b, zCntDelta)
|
|
||||||
|
|
||||||
a.writeSumDelta(h.Sum)
|
|
||||||
|
|
||||||
for i, b := range h.PositiveBuckets {
|
|
||||||
delta := b - a.pBuckets[i]
|
|
||||||
putVarbitInt(a.b, delta)
|
|
||||||
a.pBucketsDelta[i] = delta
|
|
||||||
}
|
|
||||||
for i, b := range h.NegativeBuckets {
|
|
||||||
delta := b - a.nBuckets[i]
|
|
||||||
putVarbitInt(a.b, delta)
|
|
||||||
a.nBucketsDelta[i] = delta
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
tDelta = t - a.t
|
tDelta = t - a.t
|
||||||
cntDelta = int64(h.Count) - int64(a.cnt)
|
cntDelta = int64(h.Count) - int64(a.cnt)
|
||||||
zCntDelta = int64(h.ZeroCount) - int64(a.zCnt)
|
zCntDelta = int64(h.ZeroCount) - int64(a.zCnt)
|
||||||
|
@ -788,6 +761,9 @@ func (it *histogramIterator) Next() ValueType {
|
||||||
return ValHistogram
|
return ValHistogram
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The case for the 2nd sample with single deltas is implicitly handled correctly with the double delta code,
|
||||||
|
// so we don't need a separate single delta logic for the 2nd sample.
|
||||||
|
|
||||||
// Recycle bucket slices that have not been returned yet. Otherwise,
|
// Recycle bucket slices that have not been returned yet. Otherwise,
|
||||||
// copy them.
|
// copy them.
|
||||||
if it.atHistogramCalled {
|
if it.atHistogramCalled {
|
||||||
|
@ -822,71 +798,6 @@ func (it *histogramIterator) Next() ValueType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if it.numRead == 1 {
|
|
||||||
tDelta, err := readVarbitUint(&it.br)
|
|
||||||
if err != nil {
|
|
||||||
it.err = err
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
it.tDelta = int64(tDelta)
|
|
||||||
it.t += it.tDelta
|
|
||||||
|
|
||||||
cntDelta, err := readVarbitInt(&it.br)
|
|
||||||
if err != nil {
|
|
||||||
it.err = err
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
it.cntDelta = cntDelta
|
|
||||||
it.cnt = uint64(int64(it.cnt) + it.cntDelta)
|
|
||||||
|
|
||||||
zcntDelta, err := readVarbitInt(&it.br)
|
|
||||||
if err != nil {
|
|
||||||
it.err = err
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
it.zCntDelta = zcntDelta
|
|
||||||
it.zCnt = uint64(int64(it.zCnt) + it.zCntDelta)
|
|
||||||
|
|
||||||
ok := it.readSum()
|
|
||||||
if !ok {
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
|
|
||||||
if value.IsStaleNaN(it.sum) {
|
|
||||||
it.numRead++
|
|
||||||
return ValHistogram
|
|
||||||
}
|
|
||||||
|
|
||||||
var current int64
|
|
||||||
for i := range it.pBuckets {
|
|
||||||
delta, err := readVarbitInt(&it.br)
|
|
||||||
if err != nil {
|
|
||||||
it.err = err
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
it.pBucketsDelta[i] = delta
|
|
||||||
it.pBuckets[i] += delta
|
|
||||||
current += it.pBuckets[i]
|
|
||||||
it.pFloatBuckets[i] = float64(current)
|
|
||||||
}
|
|
||||||
|
|
||||||
current = 0
|
|
||||||
for i := range it.nBuckets {
|
|
||||||
delta, err := readVarbitInt(&it.br)
|
|
||||||
if err != nil {
|
|
||||||
it.err = err
|
|
||||||
return ValNone
|
|
||||||
}
|
|
||||||
it.nBucketsDelta[i] = delta
|
|
||||||
it.nBuckets[i] += delta
|
|
||||||
current += it.nBuckets[i]
|
|
||||||
it.nFloatBuckets[i] = float64(current)
|
|
||||||
}
|
|
||||||
|
|
||||||
it.numRead++
|
|
||||||
return ValHistogram
|
|
||||||
}
|
|
||||||
|
|
||||||
tDod, err := readVarbitInt(&it.br)
|
tDod, err := readVarbitInt(&it.br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
it.err = err
|
it.err = err
|
||||||
|
|
Loading…
Reference in a new issue