stream

package
v0.0.0-...-bcbb9e7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxMultilines = 500

DefaultMaxMultilines is the default maximum number of lines in a multiline log

Variables

This section is empty.

Functions

func NewScanner

func NewScanner(r io.Reader) *scanner

NewScanner creates a new scanner for reading log lines

Types

type ExternalLogFormatter

type ExternalLogFormatter interface {
	Format(interface{}) string
}

ExternalLogFormatter is an interface that represents external log formatters

type ExternalLogHandler

type ExternalLogHandler interface {
	OnLog(interface{})
	OnError(error)
	OnEnd()
}

ExternalLogHandler is an interface that represents external log handlers

type ExternalMatcher

type ExternalMatcher interface {
	ShouldMerge(previous, next string) bool
}

ExternalMatcher is an interface that represents external multiline matchers

type FormatterAdapter

type FormatterAdapter struct {
	ExternalFormatter ExternalLogFormatter
}

FormatterAdapter adapts internal LogMessage to external formatters

func NewFormatterAdapter

func NewFormatterAdapter(formatter ExternalLogFormatter) *FormatterAdapter

NewFormatterAdapter creates a new FormatterAdapter

func (*FormatterAdapter) Format

func (a *FormatterAdapter) Format(msg LogMessage) string

Format forwards the log message to the external formatter

type FormatterWrapper

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

FormatterWrapper is a wrapper for external LogFormatter implementations

func NewFormatterWrapper

func NewFormatterWrapper(formatter interface {
	Format(interface{}) string
}) *FormatterWrapper

NewFormatterWrapper creates a new FormatterWrapper

func (*FormatterWrapper) Format

func (w *FormatterWrapper) Format(msg LogMessage) string

Format formats a log message

type HandlerAdapter

type HandlerAdapter struct {
	ExternalHandler ExternalLogHandler
}

HandlerAdapter adapts internal LogMessage to external handlers

func NewHandlerAdapter

func NewHandlerAdapter(handler ExternalLogHandler) *HandlerAdapter

NewHandlerAdapter creates a new HandlerAdapter

func (*HandlerAdapter) OnEnd

func (a *HandlerAdapter) OnEnd()

OnEnd forwards the end signal to the external handler

func (*HandlerAdapter) OnError

func (a *HandlerAdapter) OnError(err error)

OnError forwards the error to the external handler

func (*HandlerAdapter) OnLog

func (a *HandlerAdapter) OnLog(msg LogMessage)

OnLog forwards the log message to the external handler

type HandlerWrapper

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

HandlerWrapper is a wrapper for external LogHandler implementations

func NewHandlerWrapper

func NewHandlerWrapper(handler interface {
	OnLog(interface{})
	OnError(error)
	OnEnd()
}) *HandlerWrapper

NewHandlerWrapper creates a new HandlerWrapper

func (*HandlerWrapper) OnEnd

func (w *HandlerWrapper) OnEnd()

OnEnd signals the end of streaming

func (*HandlerWrapper) OnError

func (w *HandlerWrapper) OnError(err error)

OnError handles an error

func (*HandlerWrapper) OnLog

func (w *HandlerWrapper) OnLog(msg LogMessage)

OnLog handles a log message

type LogFormatter

type LogFormatter interface {
	Format(LogMessage) string
}

LogFormatter is an interface for formatting log messages

type LogHandler

type LogHandler interface {
	OnLog(LogMessage)
	OnError(error)
	OnEnd()
}

LogHandler is an interface for handling log messages and errors

type LogMessage

type LogMessage struct {
	Namespace     string
	PodName       string
	ContainerName string
	Timestamp     time.Time
	Message       string
	Raw           []byte
}

LogMessage represents a single log entry from a kubernetes pod/container

type LogStreamError

type LogStreamError struct {
	Err       error
	Permanent bool
	Reason    string
}

LogStreamError represents an error that occurred during log streaming

func NewLogStreamError

func NewLogStreamError(err error, permanent bool, reason string) *LogStreamError

NewLogStreamError creates a new LogStreamError

func (*LogStreamError) Error

func (e *LogStreamError) Error() string

Error implements the error interface

func (*LogStreamError) Unwrap

func (e *LogStreamError) Unwrap() error

Unwrap returns the underlying error

type MatcherAdapter

type MatcherAdapter struct {
	ExternalMatcher ExternalMatcher
}

MatcherAdapter adapts external multiline matchers to internal interface

func NewMatcherAdapter

func NewMatcherAdapter(matcher ExternalMatcher) *MatcherAdapter

NewMatcherAdapter creates a new MatcherAdapter

func (*MatcherAdapter) ShouldMerge

func (a *MatcherAdapter) ShouldMerge(previous, next string) bool

ShouldMerge forwards the call to the external matcher

type MatcherWrapper

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

MatcherWrapper is a wrapper for external MultilineMatcher implementations

func NewMatcherWrapper

func NewMatcherWrapper(matcher interface {
	ShouldMerge(previous, next string) bool
}) *MatcherWrapper

NewMatcherWrapper creates a new MatcherWrapper

func (*MatcherWrapper) ShouldMerge

func (w *MatcherWrapper) ShouldMerge(previous, next string) bool

ShouldMerge determines if the next line should be merged with the previous line

type MultilineMatcher

type MultilineMatcher interface {
	ShouldMerge(previous, next string) bool
}

MultilineMatcher is an interface for matching multiline log entries

type RetryPolicy

type RetryPolicy struct {
	MaxRetries      int
	InitialInterval time.Duration
	MaxInterval     time.Duration
	Multiplier      float64
}

RetryPolicy configures the retry behavior for transient errors

type Streamer

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

Streamer handles streaming logs from multiple pods

func NewStreamer

func NewStreamer(config *StreamerConfig) (*Streamer, error)

NewStreamer creates a new Streamer with the provided configuration

func (*Streamer) Start

func (s *Streamer) Start(ctx context.Context) error

Start begins streaming logs for matching pods

func (*Streamer) Stop

func (s *Streamer) Stop()

Stop stops all log streaming activity

type StreamerConfig

type StreamerConfig struct {
	KubeClientProvider *kube.ClientProvider
	Filter             *filter.LogFilter
	Handler            LogHandler
	Formatter          LogFormatter
	Matcher            MultilineMatcher
	RetryPolicy        RetryPolicy
	MaxMultilines      int
}

StreamerConfig contains configuration for the streamer

Jump to

Keyboard shortcuts

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