filters

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSamplingCacheCapacity is the default capacity for LRU caches used in sampling
	DefaultSamplingCacheCapacity = 10000

	// DefaultBackoffFactor is the default multiplication factor for exponential backoff when invalid values are provided
	DefaultBackoffFactor = 2.0
)

Default constants for sampling configurations

Variables

This section is empty.

Functions

func ByExcluding

func ByExcluding(predicate func(*core.LogEvent) bool) core.LogEventFilter

ByExcluding creates a filter that excludes events matching the predicate.

func ByIncluding

func ByIncluding(predicate func(*core.LogEvent) bool) core.LogEventFilter

ByIncluding creates a filter that includes only events matching the predicate.

func IsSamplingDebugEnabled added in v0.10.0

func IsSamplingDebugEnabled() bool

IsSamplingDebugEnabled returns whether sampling debug is enabled

func MatchAllProperties

func MatchAllProperties(matchers ...core.LogEventFilter) core.LogEventFilter

MatchAllProperties creates a filter that matches when all properties match.

func MatchAnyProperty

func MatchAnyProperty(matchers ...core.LogEventFilter) core.LogEventFilter

MatchAnyProperty creates a filter that matches when any of the properties match.

func MatchProperty

func MatchProperty(propertyName string, expectedValue any) core.LogEventFilter

MatchProperty creates a filter that matches when a property equals a specific value.

func MatchPropertyAbsent

func MatchPropertyAbsent(propertyName string) core.LogEventFilter

MatchPropertyAbsent creates a filter that matches when a property does not exist.

func MatchPropertyContains

func MatchPropertyContains(propertyName string, substring string) core.LogEventFilter

MatchPropertyContains creates a filter that matches when a property contains a substring.

func MatchPropertyExists

func MatchPropertyExists(propertyName string) core.LogEventFilter

MatchPropertyExists creates a filter that matches when a property exists.

func MatchPropertyRegex

func MatchPropertyRegex(propertyName string, pattern string) core.LogEventFilter

MatchPropertyRegex creates a filter that matches when a property matches a regex pattern.

func MinimumLevelFilter

func MinimumLevelFilter(level core.LogEventLevel) core.LogEventFilter

MinimumLevelFilter is a convenience function that creates a level filter.

func SetSamplingDebugEnabled added in v0.10.0

func SetSamplingDebugEnabled(enabled bool)

SetSamplingDebugEnabled sets the sampling debug flag in a thread-safe manner

func When

func When(condition bool, filter core.LogEventFilter) core.LogEventFilter

When creates a conditional filter that applies when the condition is true.

Types

type BackoffCounter added in v0.10.0

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

BackoffCounter tracks state for exponential backoff sampling.

type BackoffState added in v0.10.0

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

BackoffState manages exponential backoff sampling state with LRU eviction.

func NewBackoffState added in v0.10.0

func NewBackoffState(capacity int) *BackoffState

NewBackoffState creates a new backoff state manager with the specified capacity.

func (*BackoffState) GetOrCreateCounter added in v0.10.0

func (b *BackoffState) GetOrCreateCounter(key string, factor float64) *BackoffCounter

GetOrCreateCounter returns the backoff counter for a key.

func (*BackoffState) Warmup added in v0.10.0

func (b *BackoffState) Warmup(keys []string, defaultFactor float64)

Warmup pre-populates the cache with common backoff keys to avoid cold-start spikes.

type CompositeFilter

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

CompositeFilter combines multiple filters with AND logic.

func NewCompositeFilter

func NewCompositeFilter(filters ...core.LogEventFilter) *CompositeFilter

NewCompositeFilter creates a filter that requires all sub-filters to pass.

func (*CompositeFilter) Add

func (f *CompositeFilter) Add(filter core.LogEventFilter)

Add adds a new filter to the composite.

func (*CompositeFilter) IsEnabled

func (f *CompositeFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true only if all sub-filters return true.

type ExpressionFilter

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

ExpressionFilter filters log events based on property values.

func NewExpressionFilter

func NewExpressionFilter(propertyName string, matcher func(any) bool) *ExpressionFilter

NewExpressionFilter creates a filter that matches based on a property value.

func (*ExpressionFilter) IsEnabled

func (f *ExpressionFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true if the property matches the expression.

type HashSamplingFilter

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

HashSamplingFilter samples events based on a hash of a property value. This ensures consistent sampling for the same property values.

func NewHashSamplingFilter

func NewHashSamplingFilter(propertyName string, rate float32) *HashSamplingFilter

NewHashSamplingFilter creates a filter that samples based on property value hash.

func (*HashSamplingFilter) IsEnabled

func (f *HashSamplingFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true if the property hash falls within the sampling range.

type LevelFilter

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

LevelFilter filters log events based on their level.

func NewLevelFilter

func NewLevelFilter(minimumLevel core.LogEventLevel) *LevelFilter

NewLevelFilter creates a filter that only allows events at or above the specified level.

func (*LevelFilter) IsEnabled

func (f *LevelFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true if the event level is at or above the minimum level.

type NotFilter

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

NotFilter inverts the result of another filter.

func NewNotFilter

func NewNotFilter(inner core.LogEventFilter) *NotFilter

NewNotFilter creates a filter that inverts another filter's result.

func (*NotFilter) IsEnabled

func (f *NotFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns the inverse of the inner filter's result.

type OrFilter

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

OrFilter combines multiple filters with OR logic.

func NewOrFilter

func NewOrFilter(filters ...core.LogEventFilter) *OrFilter

NewOrFilter creates a filter that passes if any sub-filter passes.

func (*OrFilter) IsEnabled

func (f *OrFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true if any sub-filter returns true.

type PerMessageSamplingFilter added in v0.10.0

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

PerMessageSamplingFilter provides per-message sampling capabilities.

func NewBackoffSamplingFilter added in v0.10.0

func NewBackoffSamplingFilter(key string, factor float64, state *BackoffState) *PerMessageSamplingFilter

NewBackoffSamplingFilter creates a filter with exponential backoff sampling.

func NewConditionalSamplingFilter added in v0.10.0

func NewConditionalSamplingFilter(predicate func() bool, n uint64) *PerMessageSamplingFilter

NewConditionalSamplingFilter creates a filter that samples based on a predicate.

func NewCounterSamplingFilter added in v0.10.0

func NewCounterSamplingFilter(n uint64) *PerMessageSamplingFilter

NewCounterSamplingFilter creates a filter that samples every nth message.

func NewDurationSamplingFilter added in v0.10.0

func NewDurationSamplingFilter(duration time.Duration) *PerMessageSamplingFilter

NewDurationSamplingFilter creates a filter that samples at most once per duration.

func NewFirstNSamplingFilter added in v0.10.0

func NewFirstNSamplingFilter(n uint64) *PerMessageSamplingFilter

NewFirstNSamplingFilter creates a filter that logs only the first n occurrences.

func NewGroupSamplingFilter added in v0.10.0

func NewGroupSamplingFilter(groupName string, n uint64, manager *SamplingGroupManager) *PerMessageSamplingFilter

NewGroupSamplingFilter creates a filter that samples within a named group.

func NewRateSamplingFilter added in v0.10.0

func NewRateSamplingFilter(rate float32) *PerMessageSamplingFilter

NewRateSamplingFilter creates a filter that samples a percentage of messages.

func (*PerMessageSamplingFilter) GetStats added in v0.10.0

GetStats returns the current sampling statistics.

func (*PerMessageSamplingFilter) IsEnabled added in v0.10.0

func (f *PerMessageSamplingFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled determines if the event should be logged based on the sampling mode.

func (*PerMessageSamplingFilter) Reset added in v0.10.0

func (f *PerMessageSamplingFilter) Reset()

Reset resets the sampling counters.

type PredicateFilter

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

PredicateFilter filters log events based on a custom predicate function.

func NewPredicateFilter

func NewPredicateFilter(predicate func(*core.LogEvent) bool) *PredicateFilter

NewPredicateFilter creates a filter that uses a custom predicate function.

func (*PredicateFilter) IsEnabled

func (f *PredicateFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns the result of the predicate function.

type RateLimitFilter

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

RateLimitFilter limits the number of events per time window.

func NewRateLimitFilter

func NewRateLimitFilter(maxEvents int, windowNanos int64) *RateLimitFilter

NewRateLimitFilter creates a filter that limits events to maxEvents per window.

func (*RateLimitFilter) IsEnabled

func (f *RateLimitFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true if the event is within the rate limit.

type SamplingFilter

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

SamplingFilter filters log events based on sampling rules.

func NewSamplingFilter

func NewSamplingFilter(rate float32) *SamplingFilter

NewSamplingFilter creates a filter that samples events at the specified rate. Rate should be between 0.0 (no events) and 1.0 (all events).

func (*SamplingFilter) IsEnabled

func (f *SamplingFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled returns true for a percentage of events based on the sampling rate.

type SamplingGroupManager added in v0.10.0

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

SamplingGroupManager manages shared counters for sampling groups with LRU eviction.

func NewSamplingGroupManager added in v0.10.0

func NewSamplingGroupManager(capacity int) *SamplingGroupManager

NewSamplingGroupManager creates a new sampling group manager with the specified capacity.

func (*SamplingGroupManager) CacheHits added in v0.10.0

func (m *SamplingGroupManager) CacheHits() uint64

CacheHits returns the number of cache hits.

func (*SamplingGroupManager) CacheMisses added in v0.10.0

func (m *SamplingGroupManager) CacheMisses() uint64

CacheMisses returns the number of cache misses.

func (*SamplingGroupManager) CacheStats added in v0.10.0

func (m *SamplingGroupManager) CacheStats() (hits, misses uint64)

CacheStats returns both hit and miss statistics.

func (*SamplingGroupManager) GetOrCreateGroup added in v0.10.0

func (m *SamplingGroupManager) GetOrCreateGroup(name string) *atomic.Uint64

GetOrCreateGroup returns the counter for a group, creating it if necessary.

func (*SamplingGroupManager) ResetAll added in v0.10.0

func (m *SamplingGroupManager) ResetAll()

ResetAll resets all group counters by clearing the cache.

func (*SamplingGroupManager) ResetGroup added in v0.10.0

func (m *SamplingGroupManager) ResetGroup(name string)

ResetGroup resets the counter for a specific group.

func (*SamplingGroupManager) Warmup added in v0.10.0

func (m *SamplingGroupManager) Warmup(groupNames []string)

Warmup pre-populates the cache with common group names to avoid cold-start spikes.

type SamplingMode added in v0.10.0

type SamplingMode int

SamplingMode represents the type of sampling active on the filter.

const (
	ModeNone SamplingMode = iota
	ModeCounter
	ModeRate
	ModeDuration
	ModeFirst
	ModeGroup
	ModeConditional
	ModeBackoff
)

type SamplingStats added in v0.10.0

type SamplingStats struct {
	Sampled uint64
	Skipped uint64
}

SamplingStats contains sampling statistics.

type SourceContextLevelFilter

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

SourceContextLevelFilter filters log events based on source context and minimum level.

func NewSourceContextLevelFilter

func NewSourceContextLevelFilter(defaultLevel core.LogEventLevel, overrides map[string]core.LogEventLevel) *SourceContextLevelFilter

NewSourceContextLevelFilter creates a new filter with source context level overrides.

func (*SourceContextLevelFilter) AddOverride

func (f *SourceContextLevelFilter) AddOverride(sourceContext string, level core.LogEventLevel)

AddOverride adds or updates a source context level override.

func (*SourceContextLevelFilter) IsEnabled

func (f *SourceContextLevelFilter) IsEnabled(event *core.LogEvent) bool

IsEnabled determines if a log event should be processed based on its source context and level.

func (*SourceContextLevelFilter) RemoveOverride

func (f *SourceContextLevelFilter) RemoveOverride(sourceContext string)

RemoveOverride removes a source context level override.

func (*SourceContextLevelFilter) SetDefaultLevel

func (f *SourceContextLevelFilter) SetDefaultLevel(level core.LogEventLevel)

SetDefaultLevel updates the default minimum level.

Jump to

Keyboard shortcuts

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