mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Convert the header into an enum
Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
175ef4ebcf
commit
5d4dc7e413
|
@ -106,45 +106,30 @@ func (c *HistoChunk) Meta() (int32, float64, []histogram.Span, []histogram.Span,
|
||||||
return readHistoChunkMeta(&b)
|
return readHistoChunkMeta(&b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCounterReset sets the counter reset flag to 1 if the passed argument is true, 0 otherwise.
|
// CounterResetHeader defines the first 2 bits of the chunk header.
|
||||||
func (c *HistoChunk) SetCounterReset(counterReset bool) {
|
type CounterResetHeader byte
|
||||||
bytes := c.Bytes()
|
|
||||||
header := bytes[2]
|
const (
|
||||||
if counterReset {
|
CounterReset CounterResetHeader = 0b10000000
|
||||||
header |= counterResetMask
|
NotCounterReset CounterResetHeader = 0b01000000
|
||||||
} else if (header & counterResetMask) != 0 {
|
GaugeType CounterResetHeader = 0b11000000
|
||||||
header ^= counterResetMask
|
UnknownCounterReset CounterResetHeader = 0b00000000
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetCounterResetHeader sets the counter reset header.
|
||||||
|
func (c *HistoChunk) SetCounterResetHeader(h CounterResetHeader) {
|
||||||
|
switch h {
|
||||||
|
case CounterReset, NotCounterReset, GaugeType, UnknownCounterReset:
|
||||||
|
bytes := c.Bytes()
|
||||||
|
bytes[2] = (bytes[2] & 0b00111111) | byte(h)
|
||||||
|
default:
|
||||||
|
panic("invalid CounterResetHeader type")
|
||||||
}
|
}
|
||||||
bytes[2] = header
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CounterReset returns true if this new chunk was created because of a counter reset.
|
// GetCounterResetHeader returns the info about the first 2 bits of the chunk header.
|
||||||
func (c *HistoChunk) CounterReset() bool {
|
func (c *HistoChunk) GetCounterResetHeader() CounterResetHeader {
|
||||||
if c.NumSamples() == 0 {
|
return CounterResetHeader(c.Bytes()[2] & 0b11000000)
|
||||||
panic("HistoChunk.CounterReset() called on an empty chunk")
|
|
||||||
}
|
|
||||||
return (c.Bytes()[2] & counterResetMask) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNotCounterReset sets the "not counter reset" flag to 1 if the passed argument is true, 0 otherwise.
|
|
||||||
func (c *HistoChunk) SetNotCounterReset(notCounterReset bool) {
|
|
||||||
bytes := c.Bytes()
|
|
||||||
header := bytes[2]
|
|
||||||
if notCounterReset {
|
|
||||||
header |= notCounterResetMask
|
|
||||||
} else if (header & notCounterResetMask) != 0 {
|
|
||||||
header ^= notCounterResetMask
|
|
||||||
}
|
|
||||||
bytes[2] = header
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotCounterReset returns true if this new chunk definitely did not have counter reset
|
|
||||||
// from the earlier chunk.
|
|
||||||
func (c *HistoChunk) NotCounterReset() bool {
|
|
||||||
if c.NumSamples() == 0 {
|
|
||||||
panic("HistoChunk.NotCounterReset() called on an empty chunk")
|
|
||||||
}
|
|
||||||
return (c.Bytes()[2] & notCounterResetMask) != 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compact implements the Chunk interface.
|
// Compact implements the Chunk interface.
|
||||||
|
@ -562,8 +547,7 @@ func (a *HistoAppender) Recode(posInterjections, negInterjections []Interjection
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the flags.
|
// Set the flags.
|
||||||
hc.SetCounterReset(byts[2]&counterResetMask != 0)
|
hc.SetCounterResetHeader(CounterResetHeader(byts[2] & 0b11000000))
|
||||||
hc.SetNotCounterReset(byts[2]¬CounterResetMask != 0)
|
|
||||||
return hc, app
|
return hc, app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,6 @@ import (
|
||||||
"github.com/prometheus/prometheus/pkg/histogram"
|
"github.com/prometheus/prometheus/pkg/histogram"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
counterResetMask = 0b10000000
|
|
||||||
notCounterResetMask = 0b01000000
|
|
||||||
)
|
|
||||||
|
|
||||||
func writeHistoChunkMeta(b *bstream, schema int32, zeroThreshold float64, posSpans, negSpans []histogram.Span) {
|
func writeHistoChunkMeta(b *bstream, schema int32, zeroThreshold float64, posSpans, negSpans []histogram.Span) {
|
||||||
putInt64VBBucket(b, int64(schema))
|
putInt64VBBucket(b, int64(schema))
|
||||||
putFloat64VBBucket(b, zeroThreshold)
|
putFloat64VBBucket(b, zeroThreshold)
|
||||||
|
|
|
@ -644,11 +644,13 @@ func (s *memSeries) appendHistogram(t int64, sh histogram.SparseHistogram, appen
|
||||||
|
|
||||||
if chunkCreated {
|
if chunkCreated {
|
||||||
hc := s.headChunk.chunk.(*chunkenc.HistoChunk)
|
hc := s.headChunk.chunk.(*chunkenc.HistoChunk)
|
||||||
|
header := chunkenc.UnknownCounterReset
|
||||||
if counterReset {
|
if counterReset {
|
||||||
hc.SetCounterReset(true)
|
header = chunkenc.CounterReset
|
||||||
} else if okToAppend {
|
} else if okToAppend {
|
||||||
hc.SetNotCounterReset(true)
|
header = chunkenc.NotCounterReset
|
||||||
}
|
}
|
||||||
|
hc.SetCounterResetHeader(header)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.app.AppendHistogram(t, sh)
|
s.app.AppendHistogram(t, sh)
|
||||||
|
|
|
@ -718,8 +718,7 @@ func (p *populateWithDelChunkSeriesIterator) Next() bool {
|
||||||
)
|
)
|
||||||
if p.currDelIter.ChunkEncoding() == chunkenc.EncSHS {
|
if p.currDelIter.ChunkEncoding() == chunkenc.EncSHS {
|
||||||
if hc, ok := p.currChkMeta.Chunk.(*chunkenc.HistoChunk); ok {
|
if hc, ok := p.currChkMeta.Chunk.(*chunkenc.HistoChunk); ok {
|
||||||
newChunk.(*chunkenc.HistoChunk).SetCounterReset(hc.CounterReset())
|
newChunk.(*chunkenc.HistoChunk).SetCounterResetHeader(hc.GetCounterResetHeader())
|
||||||
newChunk.(*chunkenc.HistoChunk).SetNotCounterReset(hc.NotCounterReset())
|
|
||||||
}
|
}
|
||||||
t, h = p.currDelIter.AtHistogram()
|
t, h = p.currDelIter.AtHistogram()
|
||||||
p.curr.MinTime = t
|
p.curr.MinTime = t
|
||||||
|
|
Loading…
Reference in a new issue