sampling

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalizedStrategy

type LocalizedStrategy struct {
	// contains filtered or unexported fields
}

LocalizedStrategy makes trace sampling decisions based on a set of rules provided in a local JSON file. Trace sampling decisions are made by the root node in the trace. If a sampling decision is made by the root service, it will be passed to downstream services through the trace header.

func NewLocalizedStrategy

func NewLocalizedStrategy() (*LocalizedStrategy, error)

NewLocalizedStrategy initializes an instance of LocalizedStrategy with the default trace sampling rules. The default rules sample the first request per second, and 5% of requests thereafter.

func NewLocalizedStrategyFromFilePath

func NewLocalizedStrategyFromFilePath(fp string) (*LocalizedStrategy, error)

NewLocalizedStrategyFromFilePath initializes an instance of LocalizedStrategy using a custom ruleset found at the filepath fp.

func NewLocalizedStrategyFromJSONBytes

func NewLocalizedStrategyFromJSONBytes(b []byte) (*LocalizedStrategy, error)

NewLocalizedStrategyFromJSONBytes initializes an instance of LocalizedStrategy using a custom ruleset provided in the json bytes b.

func (*LocalizedStrategy) ShouldTrace

func (lss *LocalizedStrategy) ShouldTrace(serviceName string, path string, method string) bool

ShouldTrace consults the LocalizedStrategy's rule set to determine if the given request should be traced or not.

type Reservoir

type Reservoir struct {
	// contains filtered or unexported fields
}

Reservoir allows a specified amount of `Take()`s per second. Support for atomic operations on uint64 is required. More information: https://golang.org/pkg/sync/atomic/#pkg-note-BUG

func NewReservoir

func NewReservoir(perSecond uint64) (*Reservoir, error)

NewReservoir creates a new reservoir with a specified perSecond sampling capacity. The maximum supported sampling capacity per second is currently 100,000,000. An error is returned if the desired capacity is greater than this maximum value.

func (*Reservoir) Take

func (r *Reservoir) Take() bool

Take returns true when the reservoir has remaining sampling capacity for the current epoch. Take returns false when the reservoir has no remaining sampling capacity for the current epoch. The sampling capacity decrements by one each time Take returns true.

type Rule

type Rule struct {
	ServiceName string  `json:"service_name"`
	HTTPMethod  string  `json:"http_method"`
	URLPath     string  `json:"url_path"`
	FixedTarget uint64  `json:"fixed_target"`
	Rate        float64 `json:"rate"`
	// contains filtered or unexported fields
}

Rule represents a single entry in a sampling ruleset.

func (*Rule) AppliesTo

func (sr *Rule) AppliesTo(serviceName string, path string, method string) bool

AppliesTo returns true when the rule applies to the given parameters

func (*Rule) Sample

func (sr *Rule) Sample() bool

Sample returns true when the rule's reservoir is not full or when a randomly generated float is less than the rule's rate

type RuleManifest

type RuleManifest struct {
	Version int     `json:"version"`
	Default *Rule   `json:"default"`
	Rules   []*Rule `json:"rules"`
}

RuleManifest represents a full sampling ruleset, with a list of custom rules and default values for incoming requests that do not match any of the provided rules.

func ManifestFromFilePath

func ManifestFromFilePath(fp string) (*RuleManifest, error)

ManifestFromFilePath creates a sampling ruleset from a given filepath fp.

func ManifestFromJSONBytes

func ManifestFromJSONBytes(b []byte) (*RuleManifest, error)

ManifestFromJSONBytes creates a sampling ruleset from given JSON bytes b.

type Strategy

type Strategy interface {
	ShouldTrace(serviceName string, path string, method string) bool
}

Strategy provides an interface for implementing trace sampling strategies.

Jump to

Keyboard shortcuts

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