Skip to content

Commit

Permalink
Merge pull request prometheus#2055 from prometheus/utilization
Browse files Browse the repository at this point in the history
Add Chunk.Utilization() methods
  • Loading branch information
juliusv authored Oct 6, 2016
2 parents 0dbcf55 + c212ef0 commit 2844a8c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions storage/local/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions storage/local/chunk/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
5 changes: 5 additions & 0 deletions storage/local/chunk/doubledelta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions storage/local/chunk/varbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2844a8c

Please sign in to comment.