logsource

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SystemdNoMoreEntries = errors.New("No more journal entries") // nolint:staticcheck
)

Functions

func InitLogSourceFactories

func InitLogSourceFactories(app *kingpin.Application)

InitLogSourceFactories runs Init on all factories. The initialization order is arbitrary, except `fileLogSourceFactory` is always last (the fallback). The file log source must be last since it's enabled by default.

func IsWatchdogUnhealthy added in v0.16.0

func IsWatchdogUnhealthy(ctx context.Context) bool

IsWatchdogUnhealthy returns true if any of the log sources report being unhealthy.

func RegisterLogSourceFactory

func RegisterLogSourceFactory(lsf LogSourceFactory)

RegisterLogSourceFactory can be called from module `init` functions to register factories.

Types

type DockerClient

type DockerClient interface {
	io.Closer
	ContainerLogs(context.Context, string, container.LogsOptions) (io.ReadCloser, error)
}

A DockerClient is the client interface that client.Client provides. See https://pkg.go.dev/github.com/docker/docker/client

type DockerLogSource

type DockerLogSource struct {
	LogSourceDefaults
	// contains filtered or unexported fields
}

A DockerLogSource reads log records from the given Docker journal.

func NewDockerLogSource

func NewDockerLogSource(ctx context.Context, c DockerClient, containerID string) (*DockerLogSource, error)

NewDockerLogSource returns a log source for reading Docker logs.

func (*DockerLogSource) Close

func (s *DockerLogSource) Close() error

func (*DockerLogSource) Path

func (s *DockerLogSource) Path() string

func (*DockerLogSource) Read

func (s *DockerLogSource) Read(ctx context.Context) (string, error)

type FileLogSource

type FileLogSource struct {
	LogSourceDefaults
	// contains filtered or unexported fields
}

A FileLogSource can read lines from a file.

func NewFileLogSource

func NewFileLogSource(path string, config tail.Config) (*FileLogSource, error)

NewFileLogSource creates a new log source, tailing the given file.

func (*FileLogSource) Close

func (s *FileLogSource) Close() error

func (*FileLogSource) Path

func (s *FileLogSource) Path() string

func (*FileLogSource) Read

func (s *FileLogSource) Read(ctx context.Context) (string, error)

type KubernetesLogSource

type KubernetesLogSource struct {
	LogSourceDefaults
	// contains filtered or unexported fields
}

A KubernetesLogSource can read lines from Kubernetes pod logs.

func NewKubernetesLogSource

func NewKubernetesLogSource(ctx context.Context, namespace, serviceName, containerName string, pod corev1.Pod, clientset *kubernetes.Clientset) []*KubernetesLogSource

NewKubernetesLogSource creates a new log source that reads from Kubernetes pod logs.

func (*KubernetesLogSource) Close

func (s *KubernetesLogSource) Close() error

func (*KubernetesLogSource) ConstLabels

func (s *KubernetesLogSource) ConstLabels() prometheus.Labels

func (*KubernetesLogSource) Path

func (s *KubernetesLogSource) Path() string

func (*KubernetesLogSource) Read

func (*KubernetesLogSource) RemoteAddr

func (s *KubernetesLogSource) RemoteAddr() string

type LogSource

type LogSource interface {
	// Path returns a representation of the log location.
	Path() string

	// Read returns the next log line. Returns `io.EOF` at the end of
	// the log.
	Read(context.Context) (string, error)

	ConstLabels() prometheus.Labels
	RemoteAddr() string
	// contains filtered or unexported methods
}

A LogSource is an interface to read log lines.

type LogSourceCloser

type LogSourceCloser interface {
	io.Closer
	LogSource
}

func NewLogSourceFromFactories

func NewLogSourceFromFactories(ctx context.Context) ([]LogSourceCloser, error)

NewLogSourceFromFactories iterates through the factories and attempts to instantiate a log source. The first factory to return success wins.

type LogSourceDefaults

type LogSourceDefaults struct{}

func (LogSourceDefaults) ConstLabels

func (LogSourceDefaults) ConstLabels() prometheus.Labels

func (LogSourceDefaults) RemoteAddr

func (LogSourceDefaults) RemoteAddr() string

type LogSourceFactory

type LogSourceFactory interface {
	// Init adds the factory's struct fields as flags in the
	// application.
	Init(*kingpin.Application)

	// New attempts to create a new log source. This is called after
	// flags have been parsed. Returning `nil, nil`, means the user
	// didn't want this log source.
	New(context.Context) ([]LogSourceCloser, error)

	// Watchdog indicates whether this log source is unhealthy.
	Watchdog(context.Context) bool
	// contains filtered or unexported methods
}

A LogSourceFactory provides a repository of log sources that can be instantiated from command line flags.

type LogSourceFactoryDefaults added in v0.16.0

type LogSourceFactoryDefaults struct{}

func (LogSourceFactoryDefaults) Watchdog added in v0.16.0

type SystemdJournal

type SystemdJournal interface {
	io.Closer
	AddMatch(match string) error
	GetEntry() (*sdjournal.JournalEntry, error)
	Next() (uint64, error)
	SeekTail() error
	PreviousSkip(skip uint64) (uint64, error)
	Wait(timeout time.Duration) int
}

A SystemdJournal is the journal interface that sdjournal.Journal provides. See https://pkg.go.dev/github.com/coreos/go-systemd/sdjournal?tab=doc

type SystemdLogSource

type SystemdLogSource struct {
	LogSourceDefaults
	// contains filtered or unexported fields
}

A SystemdLogSource reads log records from the given Systemd journal.

func NewSystemdLogSource

func NewSystemdLogSource(j SystemdJournal, path, unit, slice string) (*SystemdLogSource, error)

NewSystemdLogSource returns a log source for reading Systemd journal entries. `unit` and `slice` provide filtering if non-empty (with `slice` taking precedence).

func (*SystemdLogSource) Close

func (s *SystemdLogSource) Close() error

func (*SystemdLogSource) Path

func (s *SystemdLogSource) Path() string

func (*SystemdLogSource) Read

func (s *SystemdLogSource) Read(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

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