logs

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLogFileRemovalTimeout = 3 * time.Second

	// A delay before we cancel a "follow" log stream (either completely, or stop the follow mode)
	// in response to a change in the state of the object that is producing the logs.
	// This delay allows us to capture the last lines of logs that were produced just before the object changed state.
	FollowStreamCancellationDelay = 5 * time.Second
)
View Source
const (
	DefaultDescriptorDisposalTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

func DelayCancelFollowStreams

func DelayCancelFollowStreams(streams []*usvc_io.FollowWriter, cancelStream func(*usvc_io.FollowWriter))

func RemoveWithRetry

func RemoveWithRetry(ctx context.Context, path string) error

RemoveWithRetry removes a file with exponential backoff retry.

This function is handy for files that store logs. When an object exposing logs is being deleted, DCP API server closes all associated log streams, but this happens asynchronously, so we might need to wait a bit for the files to be released.

Types

type LogDescriptor

type LogDescriptor struct {
	ResourceName types.NamespacedName
	ResourceUID  types.UID

	// The context for resource logs, to be used by log watchers.
	// When the resource is deleted, the context is cancelled and all log watchers terminate.
	Context       context.Context
	CancelContext context.CancelFunc
	// contains filtered or unexported fields
}

LogDescriptor is a struct that holds information about logs belonging to a single DCP resource (e.g. Container, Executable etc). LogDescriptor manages a set of two files for capturing logs of the resource, (for stdout and stderr output), and tracks the number of active log watchers.

func NewLogDescriptor

func NewLogDescriptor(
	ctx context.Context,
	cancel context.CancelFunc,
	resourceName types.NamespacedName,
	resourceUID types.UID,
) *LogDescriptor

Creates new LogDescriptor. Note: this is separated from log file creation so make sure that NewLogDescriptor() never fails, and as a result, the LogDescriptor is easy to use as a value type in a syncmap.

func (*LogDescriptor) Dispose

func (l *LogDescriptor) Dispose(ctx context.Context, extraTime time.Duration) error

Waits for all log watchers to stop (with a context + extra time serving as deadline) and then deletes the log files (best effort).

func (*LogDescriptor) EnableLogCapturing

func (l *LogDescriptor) EnableLogCapturing(logsFolder string) (usvc_io.WriteSyncerCloser, usvc_io.WriteSyncerCloser, bool, error)

Returns information about destination files for capturing resource logs, creating them as necessary. The returned bool indicates whether the files were created by this call.

func (*LogDescriptor) IsDisposed

func (l *LogDescriptor) IsDisposed() bool

func (*LogDescriptor) LogConsumerStarting

func (l *LogDescriptor) LogConsumerStarting() (string, string, error)

Notifies the log descriptor that another log watcher has started to use the log files. Returns the paths to the log files, or an error if the log descriptor was disposed.

func (*LogDescriptor) LogConsumerStopped

func (l *LogDescriptor) LogConsumerStopped()

Notifies the log descriptor that a log watcher has stopped using the log files.

func (*LogDescriptor) Usage

func (l *LogDescriptor) Usage() (uint32, time.Time)

Returns the number of active log watchers and last use time.

type LogDescriptorSet

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

A LogDescriptorSet is a set of log descriptors for specific kind of a resource. We have one descriptor set for Containers and another for Executables. LogDescriptorSet ensures that there is at most one log descriptor per resource UID, and that the descriptors are disposed when there are no clients interested in logs from a corresponding resource.

func NewLogDescriptorSet

func NewLogDescriptorSet(lifetimeCtx context.Context, logsFolder string, log logr.Logger) *LogDescriptorSet

func (*LogDescriptorSet) AcquireForResource

func (lds *LogDescriptorSet) AcquireForResource(
	descriptorCtx context.Context,
	cancel context.CancelFunc,
	resourceName types.NamespacedName,
	resourceUID types.UID,
) (*LogDescriptor, usvc_io.WriteSyncerCloser, usvc_io.WriteSyncerCloser, bool, error)

Acquires a log descriptor for the given resource UID. If the descriptor does not exist, it is created. Apart from the log descriptor, the function returns the stdOut and stdErr writers which are used for log capturing and log reading.

The returned bool indicates whether the descriptor was created. This allows the caller to know whether they should start the log capturing process.

func (*LogDescriptorSet) Dispose

func (lds *LogDescriptorSet) Dispose() error

func (*LogDescriptorSet) ReleaseForResource

func (lds *LogDescriptorSet) ReleaseForResource(resourceUID types.UID)

type LogStreamID

type LogStreamID uint64

type LogStreamMop

type LogStreamMop map[types.UID]map[LogStreamID]*usvc_io.FollowWriter

A map of streams for DCP resources. For each resource UID, it holds a bunch of streams represented by follow writer for writing resource logs to the destination.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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