tailer

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

tailer manages objects which tail the logs of a collection of pods specified by a label selector. This is similar to what the cli tool `stern` does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchLogs added in v0.0.14

func FetchLogs(ctx context.Context, logChan chan ContainerLogLine, wg *sync.WaitGroup, config *Config, cluster *kubernetes.Cluster) error

FetchLogs writes all the logs of the matching containers to the logChan. If ctx is Done() the method stops even if not all logs are fetched.

func StreamLogs added in v0.0.14

func StreamLogs(ctx context.Context, logChan chan ContainerLogLine, wg *sync.WaitGroup, config *Config, cluster *kubernetes.Cluster) error

StreamLogs writes the logs of all matching containers to the logChan. The containers are determined by an internal watcher polling the cluster for pod __changes__.

func Watch

func Watch(ctx context.Context, i v1.PodInterface, podFilter *regexp.Regexp,
	containerFilter *regexp.Regexp, containerExcludeFilter *regexp.Regexp,
	containerState ContainerState, labelSelector labels.Selector) (chan *Target, chan *Target, error)

Watch starts listening to Kubernetes events and emits modified containers/pods. The first result is targets added, the second is targets removed

Types

type Config

type Config struct {
	Namespace             string           // Name of the namespace to monitor
	PodQuery              *regexp.Regexp   // Limit monitoring to pods matching the RE
	Timestamps            bool             // Print timestamps before each entry.
	ContainerQuery        *regexp.Regexp   // Limit monitoring to containers matching the RE
	ExcludeContainerQuery *regexp.Regexp   // Exclusion list if the above alone is not enough.
	ContainerState        ContainerState   // Limit monitoring to containers in this state.
	Exclude               []*regexp.Regexp // If specified suppress all log entries matching the RE
	Include               []*regexp.Regexp // If specified show only log entries matching this RE
	Since                 time.Duration    // Show only log entries younger than the duration.
	AllNamespaces         bool
	LabelSelector         labels.Selector
	TailLines             *int64
	Template              *template.Template // Template to apply to log entries for formatting
	Ordered               bool               // Featch/stream logs in container order, synchronously
}

type ContainerLogLine added in v0.0.14

type ContainerLogLine struct {
	Message       string
	ContainerName string
	PodName       string
	Namespace     string
}

ContainerLogLine is an object that represents a line from the logs of a container. It is what the Run() method returns through a channel

type ContainerState

type ContainerState string

type Tail

type Tail struct {
	Namespace     string
	PodName       string
	ContainerName string
	Options       *TailOptions
	// contains filtered or unexported fields
}

func NewTail

func NewTail(namespace, podName, containerName string, logger logr.Logger, clientSet *kubernetes.Clientset, options *TailOptions) *Tail

NewTail returns a new tail for a Kubernetes container inside a pod

func (*Tail) Start

func (t *Tail) Start(ctx context.Context, logChan chan ContainerLogLine, follow bool) error

Start writes log lines to the logChan. It can be stopped using the ctx. It's the caller's responsibility to close the logChan (because there may be more instances of this method (go routines) writing to the same channel.

type TailOptions

type TailOptions struct {
	Timestamps   bool
	Follow       bool
	SinceSeconds int64
	Exclude      []*regexp.Regexp
	Include      []*regexp.Regexp
	Namespace    bool
	TailLines    *int64
	Logger       logr.Logger
}

type Target

type Target struct {
	Namespace string
	Pod       string
	Container string
}

Target is a thing to watch the logs of. It is specified by namespace, pod, and container

func (*Target) GetID

func (t *Target) GetID() string

GetID returns the ID of the object

Jump to

Keyboard shortcuts

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