kubetail

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package kubetail implements a log file tailer using the Kubernetes API.

Index

Constants

View Source
const (
	LabelPodNamespace     = "__pod_namespace__"
	LabelPodName          = "__pod_name__"
	LabelPodContainerName = "__pod_container_name__"
	LabelPodUID           = "__pod_uid__"
)

Internal labels which indicate what container to tail logs from.

Variables

This section is empty.

Functions

func PrepareLabels

func PrepareLabels(lset labels.Labels, defaultJob string) (res labels.Labels, err error)

PrepareLabels builds a label set with default labels applied from the default label set. It validates that the input label set is valid.

The namespace of the pod to tail logs from is determined by the LabelPodNamespace label. If this label isn't present, PrepareLabels falls back to __meta_kubernetes_namespace.

The name of the pod to tail logs from is determined by the LabelPodName label. If this label isn't present, PrepareLabels falls back to __meta_kubernetes_pod_name.

The name of the container to tail logs from is determined by the LabelPodContainerName label. If this label isn't present, PrepareLabels falls back to __meta_kubernetes_pod_container_name.

Validation of lset fails if there is no label indicating the pod namespace, pod name, or container name.

Types

type Manager

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

A Manager manages a set of running Tailers.

func NewManager

func NewManager(l log.Logger, opts *Options) *Manager

NewManager returns a new Manager which manages a set of running tailers. Options must not be modified after passing it to a Manager.

If NewManager is called with a nil set of options, no targets will be scheduled for running until UpdateOptions is called.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the manager and all running Tailers. It blocks until all Tailers have exited.

func (*Manager) SyncTargets

func (m *Manager) SyncTargets(ctx context.Context, targets []*Target) error

SyncTargets synchronizes the set of running tailers to the set specified by targets.

func (*Manager) Targets

func (m *Manager) Targets() []*Target

Targets returns the set of targets which are actively being tailed. Targets for tailers which have terminated are not included. The returned set of targets are deduplicated.

func (*Manager) UpdateOptions

func (m *Manager) UpdateOptions(ctx context.Context, newOptions *Options) error

UpdateOptions updates the Options shared with all Tailers. All Tailers will be updated with the new set of Options. Options should not be modified after passing to UpdateOptions.

If newOptions is nil, all tasks will be cleared until UpdateOptions is called again with a non-nil set of options.

type Options

type Options struct {
	// Client to use to request logs from Kubernetes.
	Client *kubernetes.Clientset

	// Handler to send discovered logs to.
	Handler loki.EntryHandler

	// Positions interface so tailers can save/restore offsets in log files.
	Positions positions.Positions
}

Options passed to all tailers.

type Target

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

Target represents an individual container being tailed for logs.

func NewTarget

func NewTarget(origLabels labels.Labels, lset labels.Labels) *Target

NewTarget creates a new Target which can be passed to a tailer.

func (*Target) ContainerName

func (t *Target) ContainerName() string

ContainerName returns the container name being targeted.

func (*Target) DiscoveryLabels

func (t *Target) DiscoveryLabels() labels.Labels

DiscoveryLabels returns the set of original labels prior to processing or relabeling.

func (*Target) Hash

func (t *Target) Hash() uint64

Hash returns an identifying hash for the target.

func (*Target) Labels

func (t *Target) Labels() labels.Labels

Labels returns the set of public labels for the target.

func (*Target) LastEntry

func (t *Target) LastEntry() time.Time

LastEntry returns the time the most recent log line was read or when the most recent error occurred.

func (*Target) LastError

func (t *Target) LastError() error

LastError returns the most recent error if the target is unhealthy.

func (*Target) NamespacedName

func (t *Target) NamespacedName() types.NamespacedName

NamespacedName returns the key of the Pod being targeted.

func (*Target) Report

func (t *Target) Report(time time.Time, err error)

Report reports information about the target.

func (*Target) String

func (t *Target) String() string

String returns a string representing the target in the form "namespace/name:container".

func (*Target) UID

func (t *Target) UID() string

UID returns the UID for this target, based on the pod's UID.

Jump to

Keyboard shortcuts

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