percentile

package
v0.0.0-...-1d9613f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EPSILON float64 = 0.01

EPSILON represents the accuracy of the sketch.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entries

type Entries []Entry

Entries is a slice of Entry

func (Entries) Len

func (slice Entries) Len() int

func (Entries) Less

func (slice Entries) Less(i, j int) bool

func (Entries) Swap

func (slice Entries) Swap(i, j int)

type Entry

type Entry struct {
	V     float64 `json:"v"`
	G     uint32  `json:"g"`
	Delta uint32  `json:"d"`
}

Entry is an element of the sketch. For the definition of g and delta, see the original paper http://infolab.stanford.edu/~datar/courses/cs361a/papers/quantiles.pdf

func (*Entry) MarshalJSON

func (e *Entry) MarshalJSON() ([]byte, error)

MarshalJSON encodes an Entry into an array of values

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes an Entry from an array of values

type GKArray

type GKArray struct {
	// the last item of Entries will always be the max inserted value
	Entries  Entries   `json:"entries"`
	Incoming []float64 `json:"buf"`
	// TODO[Charles]: incorporate min in entries so that we can get rid of the field.
	Min   float64 `json:"min"`
	Max   float64 `json:"max"`
	Count int64   `json:"cnt"`
	Sum   float64 `json:"sum"`
	Avg   float64 `json:"avg"`
}

GKArray is a version of GK with a buffer for the incoming values. The expected usage is that Add() is called in the agent, while Merge() and Quantile() are called in the backend; in other words, values are added to the sketch in the agent, sketches are sent to the backend where they are merged with other sketches, and quantile queries are made to the merged sketches only. This allows us to ignore the Incoming buffer once the sketch goes through a Merge. GKArray therefore has two versions of compress:

  1. compressWithIncoming(incomingEntries []Entry) is used during Merge(), and sets Incoming to nil after compressing so that merged sketches do not allocate unnecessary storage.
  2. compressAndAllocateBuf() is used during Add(), and allocates Incoming after compressing for further addition of values to the sketch.

func NewGKArray

func NewGKArray() GKArray

NewGKArray allocates a new GKArray summary.

func (GKArray) Add

func (s GKArray) Add(v float64) GKArray

Add a new value to the summary.

func (GKArray) IsValid

func (s GKArray) IsValid() bool

IsValid checks that the object is a minimally valid GKArray, i.e., won't cause a panic when calling Add or Merge.

func (GKArray) Merge

func (s GKArray) Merge(o GKArray) GKArray

Merge another GKArray into this in-place.

func (GKArray) Quantile

func (s GKArray) Quantile(q float64) float64

Quantile returns an epsilon estimate of the element at quantile q. The incoming buffer should be empty during the quantile query phase, so the check for Incoming/Compress() should not run.

func (GKArray) Quantiles

func (s GKArray) Quantiles(qValues []float64) []float64

Quantiles accepts a sorted slice of quantile values and returns the epsilon estimates of elements at those quantiles.

type NoSketchError

type NoSketchError struct{}

NoSketchError is the error returned when not enough samples have been submitted to generate a sketch

func (NoSketchError) Error

func (e NoSketchError) Error() string

type Sketch

type Sketch struct {
	Timestamp int64   `json:"timestamp"`
	Sketch    GKArray `json:"qsketch"`
}

Sketch represents a quantile sketch at a specific time

type SketchSeries

type SketchSeries struct {
	Name       string          `json:"metric"`
	Tags       []string        `json:"tags"`
	Host       string          `json:"host"`
	Interval   int64           `json:"interval"`
	Sketches   []Sketch        `json:"sketches"`
	ContextKey ckey.ContextKey `json:"-"`
}

SketchSeries holds an array of sketches.

type SketchSeriesList

type SketchSeriesList []*SketchSeries

SketchSeriesList represents a list of SketchSeries ready to be serialized

func (SketchSeriesList) Marshal

func (sl SketchSeriesList) Marshal() ([]byte, error)

Marshal serializes sketch series using protocol buffers

func (SketchSeriesList) MarshalJSON

func (sl SketchSeriesList) MarshalJSON() ([]byte, error)

MarshalJSON serializes sketch series to JSON so it can be sent to v1 endpoints

func (SketchSeriesList) SplitPayload

func (sl SketchSeriesList) SplitPayload(times int) ([]marshaler.Marshaler, error)

SplitPayload breaks the payload into times number of pieces

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL