mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Add Chunk.Utilization() methods
When using the chunking code in other projects (both Weave Prism and ChronixDB ingester), you sometimes want to know how well you are utilizing your chunks when closing/storing them.
This commit is contained in:
parent
0dbcf55bd2
commit
c212ef0326
|
@ -273,6 +273,7 @@ type Chunk interface {
|
|||
Unmarshal(io.Reader) error
|
||||
UnmarshalFromBuf([]byte) error
|
||||
Encoding() Encoding
|
||||
Utilization() float64
|
||||
}
|
||||
|
||||
// Iterator enables efficient access to the content of a chunk. It is
|
||||
|
|
|
@ -267,6 +267,11 @@ func (c *deltaEncodedChunk) UnmarshalFromBuf(buf []byte) error {
|
|||
// encoding implements chunk.
|
||||
func (c deltaEncodedChunk) Encoding() Encoding { return Delta }
|
||||
|
||||
// Utilization implements chunk.
|
||||
func (c deltaEncodedChunk) Utilization() float64 {
|
||||
return float64(len(c)) / float64(cap(c))
|
||||
}
|
||||
|
||||
func (c deltaEncodedChunk) timeBytes() deltaBytes {
|
||||
return deltaBytes(c[deltaHeaderTimeBytesOffset])
|
||||
}
|
||||
|
|
|
@ -277,6 +277,11 @@ func (c *doubleDeltaEncodedChunk) UnmarshalFromBuf(buf []byte) error {
|
|||
// encoding implements chunk.
|
||||
func (c doubleDeltaEncodedChunk) Encoding() Encoding { return DoubleDelta }
|
||||
|
||||
// Utilization implements chunk.
|
||||
func (c doubleDeltaEncodedChunk) Utilization() float64 {
|
||||
return float64(len(c)) / float64(cap(c))
|
||||
}
|
||||
|
||||
func (c doubleDeltaEncodedChunk) baseTime() model.Time {
|
||||
return model.Time(
|
||||
binary.LittleEndian.Uint64(
|
||||
|
|
|
@ -322,6 +322,12 @@ func (c varbitChunk) UnmarshalFromBuf(buf []byte) error {
|
|||
// encoding implements chunk.
|
||||
func (c varbitChunk) Encoding() Encoding { return Varbit }
|
||||
|
||||
// Utilization implements chunk.
|
||||
func (c varbitChunk) Utilization() float64 {
|
||||
// 15 bytes is the length of the chunk footer.
|
||||
return math.Min(float64(c.nextSampleOffset()/8+15)/float64(cap(c)), 1)
|
||||
}
|
||||
|
||||
// FirstTime implements chunk.
|
||||
func (c varbitChunk) FirstTime() model.Time {
|
||||
return model.Time(
|
||||
|
|
Loading…
Reference in a new issue