cache

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CurrentLoadFactor = "cuckoo_current_load_factor"
	FutureLoadFactor  = "cuckoo_future_load_factor"
	CurrentCapacity   = "cuckoo_current_capacity"
)

These are the names of metrics tracked for the cuckoo filter

View Source
const DefaultInMemCacheCapacity = 10000

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set adds the trace to the cache. If it is kicking out a trace from the cache
	// that has not yet been sent, it will return that trace. Otherwise returns nil.
	Set(trace *types.Trace) *types.Trace
	Get(traceID string) *types.Trace
	// GetAll is used during shutdown to get all in-flight traces to flush them
	GetAll() []*types.Trace

	// Retrieve and remove all traces which are past their SendBy date.
	// Does not check whether they've been sent.
	TakeExpiredTraces(now time.Time) []*types.Trace
}

Cache is a non-threadsafe cache. It must not be used for concurrent access.

type CuckooTraceChecker added in v1.20.0

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

This wraps a cuckoo filter implementation in a way that lets us keep it running forever without filling up. A cuckoo filter can't be emptied (you can delete individual items if you know what they are, but you can't get their names from the filter). Consequently, what we do is keep *two* filters, current and future. The current one is the one we use to check against, and when we add, we add to both. But the future one is started *after* the current one, so that when the current gets too full, we can discard it, replace it with future, and then start a new, empty future. This is why the future filter is nil until the current filter reaches .5. You must call Maintain() periodically, most likely from a goroutine. The call is cheap, and the timing isn't very critical. The effect of going above "capacity" is an increased false positive rate, but the filter continues to function.

func NewCuckooTraceChecker added in v1.20.0

func NewCuckooTraceChecker(capacity uint, m metrics.Metrics) *CuckooTraceChecker

func (*CuckooTraceChecker) Add added in v1.20.0

func (c *CuckooTraceChecker) Add(traceID string)

Add puts a traceID into the filter.

func (*CuckooTraceChecker) Check added in v1.20.0

func (c *CuckooTraceChecker) Check(traceID string) bool

Check tests if a traceID is (very probably) in the filter.

func (*CuckooTraceChecker) Maintain added in v1.20.0

func (c *CuckooTraceChecker) Maintain()

Maintain should be called periodically; if the current filter is full, it replaces it with the future filter and creates a new future filter.

func (*CuckooTraceChecker) SetNextCapacity added in v1.20.0

func (c *CuckooTraceChecker) SetNextCapacity(capacity uint)

SetNextCapacity adjusts the capacity that will be set for the future filter on the next replacement.

type DefaultInMemCache

type DefaultInMemCache struct {
	Metrics metrics.Metrics
	Logger  logger.Logger
	// contains filtered or unexported fields
}

DefaultInMemCache keeps a bounded number of entries to avoid growing memory forever. Traces are expunged from the cache in insertion order (not access order) so it is important to have a cache larger than trace throughput * longest trace.

func NewInMemCache

func NewInMemCache(
	capacity int,
	metrics metrics.Metrics,
	logger logger.Logger,
) *DefaultInMemCache

func (*DefaultInMemCache) Get

func (d *DefaultInMemCache) Get(traceID string) *types.Trace

func (*DefaultInMemCache) GetAll

func (d *DefaultInMemCache) GetAll() []*types.Trace

GetAll is not thread safe and should only be used when that's ok Returns all non-nil trace entries.

func (*DefaultInMemCache) GetCacheSize

func (d *DefaultInMemCache) GetCacheSize() int

func (*DefaultInMemCache) RemoveTraces added in v1.19.0

func (d *DefaultInMemCache) RemoveTraces(toDelete map[string]struct{})

RemoveTraces accepts a set of trace IDs and removes any matching ones from the insertion list. This is used in the case of a cache overrun.

func (*DefaultInMemCache) Set

func (d *DefaultInMemCache) Set(trace *types.Trace) *types.Trace

Set adds the trace to the ring. If it is kicking out a trace from the ring that has not yet been sent, it will return that trace. Otherwise returns nil.

func (*DefaultInMemCache) TakeExpiredTraces

func (d *DefaultInMemCache) TakeExpiredTraces(now time.Time) []*types.Trace

TakeExpiredTraces should be called to decide which traces are past their expiration time; It removes and returns them.

type TraceSentCache added in v1.20.0

type TraceSentCache interface {
	// Record preserves the record of a trace being sent or not.
	Record(trace *types.Trace, keep bool)
	// Check tests if a trace corresponding to the span is in the cache; if found, it returns the appropriate TraceSentRecord and true,
	// else nil and false.
	Check(span *types.Span) (TraceSentRecord, bool)
	// Stop halts the cache in preparation for shutdown
	Stop()
	// Resize adjusts the size of the cache according to the Config passed in
	Resize(cfg config.SampleCacheConfig) error
}

func NewCuckooSentCache added in v1.20.0

func NewCuckooSentCache(cfg config.SampleCacheConfig, met metrics.Metrics) (TraceSentCache, error)

func NewLegacySentCache added in v1.20.0

func NewLegacySentCache(capacity int) (TraceSentCache, error)

type TraceSentRecord added in v1.20.0

type TraceSentRecord interface {
	// Kept returns whether the trace was kept (sampled and sent to honeycomb) or dropped.
	Kept() bool
	// Rate() returns the sample rate for the trace
	Rate() uint
	// DescendantCount returns the count of items associated with the trace, including all types of children like span links and span events.
	DescendantCount() uint
	// Count records additional spans in the totals
	Count(*types.Span)
}

Jump to

Keyboard shortcuts

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