Skip to content

Commit

Permalink
Merge pull request grafana#1202 from cortexproject/bigchunk-size-cap
Browse files Browse the repository at this point in the history
Add a cap on bigChunk size
  • Loading branch information
tomwilkie authored Feb 5, 2019
2 parents b311ae7 + a350d41 commit 9200617
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions encoding/bigchunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func newBigchunk() *bigchunk {

func (b *bigchunk) Add(sample model.SamplePair) ([]Chunk, error) {
if b.remainingSamples == 0 {
if bigchunkSizeCapBytes > 0 && b.Size() > bigchunkSizeCapBytes {
return addToOverflowChunk(b, sample)
}
if err := b.addNextChunk(sample.Timestamp); err != nil {
return nil, err
}
Expand Down
19 changes: 17 additions & 2 deletions encoding/factory.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package encoding

import (
"flag"
"fmt"
"strconv"
)

// Encoding defines which encoding we are using, delta, doubledelta, or varbit
type Encoding byte

// DefaultEncoding can be changed via a flag.
var DefaultEncoding = DoubleDelta
// Config configures the behaviour of chunk encoding
type Config struct{}

var (
// DefaultEncoding exported for use in unit tests elsewhere
DefaultEncoding = DoubleDelta
alwaysMarshalFullsizeChunks = true
bigchunkSizeCapBytes = 0
)

// RegisterFlags registers configuration settings.
func (Config) RegisterFlags(f *flag.FlagSet) {
f.Var(&DefaultEncoding, "ingester.chunk-encoding", "Encoding version to use for chunks.")
flag.BoolVar(&alwaysMarshalFullsizeChunks, "store.fullsize-chunks", alwaysMarshalFullsizeChunks, "When saving varbit chunks, pad to 1024 bytes")
flag.IntVar(&bigchunkSizeCapBytes, "store.bigchunk-size-cap-bytes", bigchunkSizeCapBytes, "When using bigchunk encoding, start a new bigchunk if over this size (0 = unlimited)")
}

// String implements flag.Value.
func (e Encoding) String() string {
Expand Down
11 changes: 0 additions & 11 deletions encoding/varbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package encoding

import (
"encoding/binary"
"flag"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -315,16 +314,6 @@ func (c varbitChunk) Utilization() float64 {
return math.Min(float64(c.nextSampleOffset()/8+15)/float64(cap(c)), 1)
}

// MarshalConfig configures the behaviour of marshalling
type MarshalConfig struct{}

var alwaysMarshalFullsizeChunks = true

// RegisterFlags registers configuration settings.
func (MarshalConfig) RegisterFlags(f *flag.FlagSet) {
flag.BoolVar(&alwaysMarshalFullsizeChunks, "store.fullsize-chunks", alwaysMarshalFullsizeChunks, "When saving varbit chunks, pad to 1024 bytes")
}

// marshalLen returns the number of bytes that should be marshalled for this chunk
func (c varbitChunk) marshalLen() int {
bits := c.nextSampleOffset()
Expand Down

0 comments on commit 9200617

Please sign in to comment.