drain

package
v3.6.7 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatLogfmt  = "logfmt"
	FormatJSON    = "json"
	FormatUnknown = "unknown"
	TooFewTokens  = "too_few_tokens"
	TooManyTokens = "too_many_tokens"
	LineTooLong   = "line_too_long"
)
View Source
const (
	TimeResolution = model.Time(int64(time.Second*10) / 1e6)
)

Variables

This section is empty.

Functions

func DetectLogFormat added in v3.2.0

func DetectLogFormat(line string) string

DetectLogFormat guesses at how the logs are encoded based on some simple heuristics. It only runs on the first log line when a new stream is created, so it could do some more complex parsing or regex.

func TruncateTimestamp added in v3.6.0

func TruncateTimestamp(ts, step model.Time) model.Time

Types

type Chunk

type Chunk struct {
	Samples []logproto.PatternSample
}

func (Chunk) ForRange

func (c Chunk) ForRange(start, end, step, sampleInterval model.Time) []logproto.PatternSample

ForRange returns samples with only the values in the given range [start:end) and aggregates them by step duration. start and end are in milliseconds since epoch. step is a duration in milliseconds. sampleInterval is the configured sample interval for this chunk.

type Chunks

type Chunks []Chunk

func (*Chunks) Add

func (c *Chunks) Add(ts model.Time, maxChunkAge time.Duration, sampleInterval time.Duration) *logproto.PatternSample

Add records the sample by incrementing the value of the current sample or creating a new sample if past the time resolution of the current one. Returns the previous sample if a new sample was created, nil otherwise.

func (Chunks) Iterator

func (c Chunks) Iterator(pattern, lvl string, from, through, step, sampleInterval model.Time) iter.Iterator

type Config

type Config struct {
	LogClusterDepth      int
	SimTh                float64
	MaxChildren          int
	ExtraDelimiters      []string
	MaxClusters          int
	ParamString          string
	MaxEvictionRatio     float64
	MaxAllowedLineLength int
	MaxChunkAge          time.Duration
	SampleInterval       time.Duration
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

type DedupingTokenizer added in v3.2.0

type DedupingTokenizer struct {
	LineTokenizer
	// contains filtered or unexported fields
}

func (DedupingTokenizer) Join added in v3.2.0

func (d DedupingTokenizer) Join(tokens []string, state interface{}) string

type Drain

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

func New

func New(tenantID string, config *Config, limits Limits, format string, metrics *Metrics) *Drain

func (*Drain) Clusters

func (d *Drain) Clusters() []*LogCluster

func (*Drain) Delete

func (d *Drain) Delete(cluster *LogCluster)

func (*Drain) Prune added in v3.2.0

func (d *Drain) Prune()

func (*Drain) Train

func (d *Drain) Train(content string, ts int64) *LogCluster

type Limits added in v3.3.0

type Limits interface {
	PatternIngesterTokenizableJSONFields(userID string) []string
}

type LineTokenizer added in v3.1.0

type LineTokenizer interface {
	Tokenize(line string, tokens []string, state interface{}, linesDropped *prometheus.CounterVec) ([]string, interface{})
	Join(tokens []string, state interface{}) string
	Clone(tokens []string, state interface{}) ([]string, interface{})
}

type LogCluster

type LogCluster struct {
	Size        int
	Tokens      []string
	TokenState  interface{}
	Stringer    func([]string, interface{}) string
	Volume      int64
	SampleCount int64

	Chunks Chunks
	// contains filtered or unexported fields
}

func (*LogCluster) Iterator

func (c *LogCluster) Iterator(lvl string, from, through, step, sampleInterval model.Time) iter.Iterator

func (*LogCluster) Prune

func (c *LogCluster) Prune(olderThan time.Duration) []*logproto.PatternSample

func (*LogCluster) Samples

func (c *LogCluster) Samples() []*logproto.PatternSample

func (*LogCluster) String

func (c *LogCluster) String() string

type LogClusterCache

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

func (*LogClusterCache) Get

func (c *LogClusterCache) Get(key int) *LogCluster

func (*LogClusterCache) Set

func (c *LogClusterCache) Set(key int, cluster *LogCluster)

func (*LogClusterCache) Values

func (c *LogClusterCache) Values() []*LogCluster

type Metrics added in v3.1.0

type Metrics struct {
	PatternsEvictedTotal  prometheus.Counter
	PatternsPrunedTotal   prometheus.Counter
	PatternsDetectedTotal prometheus.Counter
	LinesSkipped          *prometheus.CounterVec
	TokensPerLine         prometheus.Observer
	StatePerLine          prometheus.Observer
}

type Node

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

Jump to

Keyboard shortcuts

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