Documentation
¶
Index ¶
- Constants
- func DelayCancelFollowStreams(streams []*usvc_io.FollowWriter, cancelStream func(*usvc_io.FollowWriter))
- func RemoveWithRetry(ctx context.Context, path string) error
- func ToTimestampReaderOptions(opts *apiv1.LogOptions) usvc_io.TimestampAwareReaderOptions
- type LogDescriptor
- func (l *LogDescriptor) Dispose(ctx context.Context, extraTime time.Duration) error
- func (l *LogDescriptor) EnableLogCapturing(logsFolder string) (usvc_io.WriteSyncerCloser, usvc_io.WriteSyncerCloser, bool, error)
- func (l *LogDescriptor) IsDisposed() bool
- func (l *LogDescriptor) LogConsumerStarting() (string, string, error)
- func (l *LogDescriptor) LogConsumerStopped()
- func (l *LogDescriptor) Usage() (uint32, time.Time)
- type LogDescriptorSet
- func (lds *LogDescriptorSet) AcquireForResource(descriptorCtx context.Context, cancel context.CancelFunc, ...) (*LogDescriptor, usvc_io.WriteSyncerCloser, usvc_io.WriteSyncerCloser, bool, ...)
- func (lds *LogDescriptorSet) Dispose() error
- func (lds *LogDescriptorSet) ReleaseForResource(resourceUID types.UID)
- type LogStreamID
- type LogStreamMop
Constants ¶
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 )
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 ¶
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.
func ToTimestampReaderOptions ¶
func ToTimestampReaderOptions(opts *apiv1.LogOptions) usvc_io.TimestampAwareReaderOptions
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 ¶
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.
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 (*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.