Signed-off-by: Carrie Edwards <edwrdscarrie@gmail.com>
This commit is contained in:
Carrie Edwards 2026-05-05 09:52:50 -07:00
parent ccdf9f71d2
commit fe4e31ef55
4 changed files with 20 additions and 19 deletions

View file

@ -77,10 +77,10 @@ func (c *FloatHistogramSTChunk) Appender() (Appender, error) {
if len(c.b.stream) == histogramSTHeaderSize {
return &FloatHistogramSTAppender{
FloatHistogramAppender: FloatHistogramAppender{
b: &c.b,
t: math.MinInt64,
sum: xorValue{leading: 0xff},
cnt: xorValue{leading: 0xff},
b: &c.b,
t: math.MinInt64,
sum: xorValue{leading: 0xff},
cnt: xorValue{leading: 0xff},
zCnt: xorValue{leading: 0xff},
},
}, nil
@ -183,8 +183,8 @@ type FloatHistogramSTAppender struct {
func (a *FloatHistogramSTAppender) encodeST(prevT, st int64) {
num := binary.BigEndian.Uint16(a.b.bytes())
switch {
case num == 1: // First sample (count was just incremented from 0).
switch num {
case 1: // First sample (count was just incremented from 0).
if st != 0 {
buf := make([]byte, binary.MaxVarintLen64)
for _, b := range buf[:binary.PutVarint(buf, a.t-st)] {
@ -193,7 +193,7 @@ func (a *FloatHistogramSTAppender) encodeST(prevT, st int64) {
a.firstSTKnown = true
writeHeaderFirstSTKnown(a.b.bytes()[histogramSTHeaderSize-1:])
}
case num == 2: // Second sample.
case 2: // Second sample.
if st != a.st {
stDiff := prevT - st
a.firstSTChangeOn = 1
@ -476,8 +476,8 @@ func (it *floatHistogramSTIterator) Seek(t int64) ValueType {
// numRead is the number of samples read so far (already incremented by floatHistogramIterator.Next()).
// prevT is the timestamp of the previous sample (before floatHistogramIterator.Next() updated it.t).
func (it *floatHistogramSTIterator) decodeST(numRead uint16, prevT int64) error {
switch {
case numRead == 1: // After sample 0.
switch numRead {
case 1: // After sample 0.
if it.firstSTKnown {
stDiff, err := it.br.readVarint()
if err != nil {
@ -486,7 +486,7 @@ func (it *floatHistogramSTIterator) decodeST(numRead uint16, prevT int64) error
it.stDiff = stDiff
it.st = it.t - stDiff
}
case numRead == 2: // After sample 1.
case 2: // After sample 1.
if it.firstSTChangeOn == 1 {
sdod, err := readVarbitInt(&it.br)
if err != nil {

View file

@ -390,7 +390,7 @@ func TestFloatHistogramSTChunkStaleSamples(t *testing.T) {
require.NoError(t, err)
_, _, app, err = app.AppendFloatHistogram(nil, 200, 2000, stale1, false)
require.NoError(t, err)
_, _, app, err = app.AppendFloatHistogram(nil, 0, 3000, stale2, false)
_, _, _, err = app.AppendFloatHistogram(nil, 0, 3000, stale2, false)
require.NoError(t, err)
it := c.Iterator(nil)

View file

@ -80,7 +80,8 @@ func (c *HistogramSTChunk) Appender() (Appender, error) {
HistogramAppender: HistogramAppender{
b: &c.b,
t: math.MinInt64,
leading: 0xff},
leading: 0xff,
},
}, nil
}
@ -172,8 +173,8 @@ type HistogramSTAppender struct {
func (a *HistogramSTAppender) encodeST(prevT, st int64) {
num := binary.BigEndian.Uint16(a.b.bytes())
switch {
case num == 1: // First sample (count was just incremented from 0).
switch num {
case 1: // First sample (count was just incremented from 0).
if st != 0 {
buf := make([]byte, binary.MaxVarintLen64)
for _, b := range buf[:binary.PutVarint(buf, a.t-st)] {
@ -182,7 +183,7 @@ func (a *HistogramSTAppender) encodeST(prevT, st int64) {
a.firstSTKnown = true
writeHeaderFirstSTKnown(a.b.bytes()[histogramSTHeaderSize-1:])
}
case num == 2: // Second sample.
case 2: // Second sample.
if st != a.st {
stDiff := prevT - st
a.firstSTChangeOn = 1
@ -465,8 +466,8 @@ func (it *histogramSTIterator) Seek(t int64) ValueType {
// numRead is the number of samples read so far (already incremented by histogramIterator.Next()).
// prevT is the timestamp of the previous sample (before histogramIterator.Next() updated it.t).
func (it *histogramSTIterator) decodeST(numRead uint16, prevT int64) error {
switch {
case numRead == 1: // After sample 0.
switch numRead {
case 1: // After sample 0.
if it.firstSTKnown {
stDiff, err := it.br.readVarint()
if err != nil {
@ -475,7 +476,7 @@ func (it *histogramSTIterator) decodeST(numRead uint16, prevT int64) error {
it.stDiff = stDiff
it.st = it.t - stDiff
}
case numRead == 2: // After sample 1.
case 2: // After sample 1.
if it.firstSTChangeOn == 1 {
sdod, err := readVarbitInt(&it.br)
if err != nil {

View file

@ -387,7 +387,7 @@ func TestHistogramSTChunkStaleSamples(t *testing.T) {
require.NoError(t, err)
_, _, app, err = app.AppendHistogram(nil, 200, 2000, stale1, false)
require.NoError(t, err)
_, _, app, err = app.AppendHistogram(nil, 0, 3000, stale2, false)
_, _, _, err = app.AppendHistogram(nil, 0, 3000, stale2, false)
require.NoError(t, err)
it := c.Iterator(nil)