source

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("skip source")

ErrSkip is used to indicate that a particular source should not be scheduled.

Functions

func Reconcile

func Reconcile[Key comparable, Input any](
	logger log.Logger,
	s *Scheduler[Key],
	it iter.Seq[Input],
	keyFn KeyFn[Key, Input],
	sourceFactoryFn SourceFactoryFn[Key, Input],
)

Reconcile synchronizes the scheduler's set of running sources with a desired state. It iterates over inputs, creates sources for new items, and stops sources that are no longer needed.

Types

type DebugSource

type DebugSource interface {
	DebugInfo() any
}

DebugSource is an optional interface with debug information.

type DefaultLogsResponseWriter added in v1.16.0

type DefaultLogsResponseWriter struct{}

func (DefaultLogsResponseWriter) WriteResponse added in v1.16.0

func (d DefaultLogsResponseWriter) WriteResponse(w http.ResponseWriter, r *http.Request, status int, err error)

type HTTPRoute added in v1.16.0

type HTTPRoute interface {
	Path() string
	Method() string
}

type HandlerRoute added in v1.16.0

type HandlerRoute interface {
	HTTPRoute
	http.Handler
}

HandlerRoute describes an HTTP endpoint handled directly with an http.Handler.

type KeyFn

type KeyFn[Key comparable, Input any] func(Input) Key

KeyFn extracts a comparable key of type Key from an input value of type Input. The key is used to uniquely identify sources in the scheduler.

type LogsConfig added in v1.16.0

type LogsConfig struct {
	FixedLabels          model.LabelSet
	RelabelRules         []*relabel.Config
	UseIncomingTimestamp bool
}

type LogsResponseWriter added in v1.16.0

type LogsResponseWriter interface {
	WriteResponse(w http.ResponseWriter, r *http.Request, status int, err error)
}

LogsResponseWriter can customize the HTTP response written for a LogsRoute after entries have been forwarded or a request has been rejected.

type LogsRoute added in v1.16.0

type LogsRoute interface {
	HTTPRoute
	// Logs converts a request into log entries and an HTTP status code.
	// If it returns no entries and a non-nil error, the request is rejected.
	// If it returns entries, they are forwarded before the status code is written.
	// Returning both entries and an error reports partial success using the returned status.
	Logs(r *http.Request, opts *LogsConfig) ([]loki.Entry, int, error)
}

LogsRoute describes an HTTP endpoint that produces log entries.

type Scheduler

type Scheduler[Key comparable] struct {
	// contains filtered or unexported fields
}

Scheduler manages the lifecycle of sources. It is not safe for concurrent use: callers must ensure proper synchronization when accessing or modifying Scheduler and its sources from multiple goroutines.

func NewScheduler

func NewScheduler[Key comparable]() *Scheduler[Key]

func (*Scheduler[Key]) Contains

func (s *Scheduler[Key]) Contains(k Key) bool

Contains returns true if a source with provided k already exists.

func (*Scheduler[Key]) Len

func (s *Scheduler[Key]) Len() int

Len returns number of scheduled sources

func (*Scheduler[Key]) Reset

func (s *Scheduler[Key]) Reset()

Reset will stop all running sources and wait for them to finish and reset Scheduler to a usable state.

func (*Scheduler[Key]) ScheduleSource

func (s *Scheduler[Key]) ScheduleSource(source Source[Key])

ScheduleSource will register and run the provided source in a goroutine. If a source with the same key already exists it will do nothing.

func (*Scheduler[Key]) Sources

func (s *Scheduler[Key]) Sources() iter.Seq[Source[Key]]

Sources returns an iterator of all scheduled sources.

func (*Scheduler[Key]) Stop

func (s *Scheduler[Key]) Stop()

Stop will stop all running sources and wait for them to finish. Scheduler should not be reused after Stop is called.

func (*Scheduler[Key]) StopSource

func (s *Scheduler[Key]) StopSource(source Source[Key])

StopSource will unregister provided source and cancel it without waiting for it to stop.

type Server added in v1.16.0

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

Server exposes HTTP routes that ingest log entries and forward them in batches.

func NewServer added in v1.16.0

func NewServer(logger log.Logger, reg prometheus.Registerer, recv loki.LogsBatchReceiver, cfg ServerConfig) (*Server, error)

func (*Server) ForceShutdown added in v1.16.0

func (s *Server) ForceShutdown()

ForceShutdown stops the server without waiting for in-flight requests.

func (*Server) HTTPAddr added in v1.16.0

func (s *Server) HTTPAddr() string

HTTPAddr returns the server HTTP listen address.

func (*Server) NeedsRestart added in v1.16.0

func (s *Server) NeedsRestart(netConfig *fnet.ServerConfig) bool

NeedsRestart reports whether a new server instance is required.

func (*Server) Run added in v1.16.0

func (s *Server) Run(logs []LogsRoute, handlers []HandlerRoute) error

Run registers the configured routes and starts the server.

func (*Server) Shutdown added in v1.16.0

func (s *Server) Shutdown()

Shutdown stops the server.

func (*Server) Update added in v1.16.0

func (s *Server) Update(logsConfig *LogsConfig)

Update replaces the configuration used for incoming log requests.

type ServerConfig added in v1.16.0

type ServerConfig struct {
	Namespace      string
	EntriesWritten prometheus.Counter
	NetConfig      *fnet.ServerConfig
	LogsConfig     *LogsConfig
}

type Source

type Source[Key comparable] interface {
	// Run should start the source.
	// It should run until there is no more work or context is canceled.
	Run(ctx context.Context)
	// Key is used to uniquely identify the source.
	Key() Key
}

type SourceFactoryFn

type SourceFactoryFn[Key comparable, Input any] func(Key, Input) (Source[Key], error)

SourceFactoryFn creates a Source[Key] from a key and input value. It returns the created source (or nil if creation failed or should be skipped) and an error. Return ErrSkip to indicate that the source should not be scheduled without logging an error.

type SourceWithRetry

type SourceWithRetry[Key comparable] struct {
	// contains filtered or unexported fields
}

SourceWithRetry is used to wrap another source and apply retries when running.

func NewSourceWithRetry

func NewSourceWithRetry[Key comparable](source Source[Key], config backoff.Config) *SourceWithRetry[Key]

func (*SourceWithRetry[Key]) DebugInfo

func (s *SourceWithRetry[Key]) DebugInfo() any

func (*SourceWithRetry[Key]) Key

func (s *SourceWithRetry[Key]) Key() Key

func (*SourceWithRetry[Key]) Run

func (s *SourceWithRetry[Key]) Run(ctx context.Context)

Directories

Path Synopsis
api
internal
Package kubernetes implements the loki.source.kubernetes component.
Package kubernetes implements the loki.source.kubernetes component.
kubetail
Package kubetail implements a log file tailer using the Kubernetes API.
Package kubetail implements a log file tailer using the Kubernetes API.
Package kubernetes_events implements the loki.source.kubernetes_events component.
Package kubernetes_events implements the loki.source.kubernetes_events component.
win_eventlog
Package win_eventlog Input plugin to collect Windows Event Log messages
Package win_eventlog Input plugin to collect Windows Event Log messages

Jump to

Keyboard shortcuts

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