sampling

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package sampling provides the sampling strategy.

Index

Constants

This section is empty.

Variables

View Source
var DefaultSamplingRule = &Manifest{
	Version: 2,
	Default: &Rule{
		FixedTarget: 1,
		Rate:        0.05,
	},
	Rules: []*Rule{},
}

DefaultSamplingRule is default sampling rule, if centralized sampling rule is not available.

Functions

func WildcardMatch

func WildcardMatch(pattern, text string, caseInsensitive bool) bool

WildcardMatch returns whether the text matchers the pattern.

func WildcardMatchCaseInsensitive

func WildcardMatchCaseInsensitive(pattern, text string) bool

WildcardMatchCaseInsensitive returns whether the text matchers the pattern.

Types

type CentralizedStrategy

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

CentralizedStrategy is an implementation of SamplingStrategy.

func NewCentralizedStrategy

func NewCentralizedStrategy(addr string, manifest *Manifest) (*CentralizedStrategy, error)

NewCentralizedStrategy returns new centralized sampling strategy with a fallback on the local rule. If local rule is nil, the DefaultSamplingRule is used.

func (*CentralizedStrategy) Close

func (s *CentralizedStrategy) Close()

Close stops polling.

func (*CentralizedStrategy) ShouldTrace

func (s *CentralizedStrategy) ShouldTrace(req *Request) *Decision

ShouldTrace implements Strategy.

type Decision

type Decision struct {
	Sample bool
	Rule   *string
}

Decision contains sampling decision and the rule matched for an incoming request.

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(manifest *Manifest) (*LocalizedStrategy, error)

NewLocalizedStrategy returns new LocalizedStrategy.

func (*LocalizedStrategy) ShouldTrace

func (s *LocalizedStrategy) ShouldTrace(req *Request) *Decision

ShouldTrace implements Strategy.

type Manifest

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

Manifest is a list of sampling rules.

func DecodeManifest

func DecodeManifest(r io.Reader) (*Manifest, error)

DecodeManifest decodes json-encoded manifest file.

func (*Manifest) Copy

func (m *Manifest) Copy() *Manifest

Copy returns deep copy of the manifest.

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate checks whether the manifest is valid.

type Request

type Request struct {
	Host        string
	Method      string
	URL         string
	ServiceName string
	ServiceType string
}

Request represents parameters used to make a sampling decision.

type Rule

type Rule struct {
	// Description
	Description string `json:"description"`

	// The hostname from the HTTP host header.
	Host string `json:"host"`

	// The method of the HTTP request.
	HTTPMethod string `json:"http_method"`

	// The URL path of the request.
	URLPath string `json:"url_path"`

	// The name of the instrumented service, as it appears in the service map.
	ServiceName string `json:"service_name"`

	// FixedTarget
	FixedTarget int64 `json:"fixed_target"`

	// The rate of matching requests to instrument, after the reservoir is exhausted.
	Rate float64 `json:"rate"`
}

Rule is a sampling rule.

func (*Rule) Match

func (r *Rule) Match(req *Request) bool

Match returns whether the sampling rule matches against given parameters.

type Strategy

type Strategy interface {
	// ShouldTrace returns a sampling decision for an incoming request.
	ShouldTrace(request *Request) *Decision
}

Strategy provides an interface for implementing trace sampling strategies.

func NewAllStrategy

func NewAllStrategy() Strategy

NewAllStrategy returns the strategy that samples all segments.

type StrategyFunc added in v1.7.0

type StrategyFunc func(request *Request) *Decision

StrategyFunc is an adapter to allow the use of ordinary functions as sampling strategies.

func (StrategyFunc) ShouldTrace added in v1.7.0

func (s StrategyFunc) ShouldTrace(request *Request) *Decision

Jump to

Keyboard shortcuts

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