logs

package
v1.19.6 Latest Latest
Warning

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

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

Documentation

Overview

Package logs contains code to fetch logs from Kubernetes pods

Index

Constants

View Source
const DefaultFollowWaiting time.Duration = 1 * time.Second

DefaultFollowWaiting is the default time the cluster streaming should wait before searching again for new cluster pods

Variables

This section is empty.

Functions

func GetPodLogs

func GetPodLogs(
	ctx context.Context,
	client kubernetes.Interface,
	pod v1.Pod,
	getPrevious bool,
	writer io.Writer,
	requestedLineLength int,
) (
	[]string, error,
)

GetPodLogs streams the pod logs and shunts them to the `writer`, as well as returning the last `requestedLineLength` of lines of logs in a slice. If `getPrevious` was activated, it will get the previous logs

TODO: this function is a bit hacky. The K8s PodLogOptions have a field called `TailLines` that seems to be just what we would like. HOWEVER: we want the full logs too, so we can write them to a file, in addition to the `TailLines` we want to pass along for display

func TailPodLogs added in v1.18.1

func TailPodLogs(
	ctx context.Context,
	client kubernetes.Interface,
	pod v1.Pod,
	writer io.Writer,
	parseTimestamps bool,
) error

TailPodLogs streams the pod logs starting from the current time, and keeps waiting for any new logs, until the context is cancelled by the calling process If `parseTimestamps` is true, the log line will have the timestamp in human-readable prepended. NOTE: this will make log-lines NON-JSON

Types

type ClusterStreamingRequest added in v1.19.4

type ClusterStreamingRequest struct {
	Cluster       *apiv1.Cluster
	Options       *v1.PodLogOptions
	Previous      bool `json:"previous,omitempty"`
	FollowWaiting time.Duration
	// NOTE: the Client argument may be omitted, but it is good practice to pass it
	// Importantly, it makes the logging functions testable
	Client kubernetes.Interface
}

ClusterStreamingRequest represents a request to stream a cluster's pod logs

If the Follow Option is set to true, streaming will sit in a loop looking for any new / regenerated pods, and will only exit when there are no pods streaming

func (*ClusterStreamingRequest) SingleStream added in v1.19.4

func (csr *ClusterStreamingRequest) SingleStream(ctx context.Context, writer io.Writer) error

SingleStream streams the cluster's pod logs and shunts them to a single io.Writer

type StreamingRequest added in v1.18.4

type StreamingRequest struct {
	Pod      *v1.Pod
	Options  *v1.PodLogOptions
	Previous bool `json:"previous,omitempty"`
	// contains filtered or unexported fields
}

StreamingRequest represents a request to stream a pod's logs

func (*StreamingRequest) Stream added in v1.18.4

func (spl *StreamingRequest) Stream(ctx context.Context, writer io.Writer) (err error)

Stream streams the pod logs and shunts them to the `writer`.

Jump to

Keyboard shortcuts

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