logs

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewestTimestamp = "newest"
	OldestTimestamp = "oldest"
)
View Source
const (
	Beginning = "beginning"
	End       = "end"
)

Load logs from the beginning or the end of the of the log file. This matters only if the log file is too large to be loaded completely.

Variables

View Source
var AllSelection = &Selection{
	OffsetFrom:     -MaxLogLines,
	OffsetTo:       MaxLogLines,
	ReferencePoint: NewestLogLineId,
}

Returns all logs.

View Source
var DefaultDisplayNumLogLines = 100

Default number of lines that should be returned in case of invalid request.

View Source
var DefaultSelection = &Selection{
	OffsetFrom:      1 - DefaultDisplayNumLogLines,
	OffsetTo:        1,
	ReferencePoint:  NewestLogLineId,
	LogFilePosition: End,
}

Default log view selector that is used in case of invalid request Downloads newest DefaultDisplayNumLogLines lines.

View Source
var LINE_INDEX_NOT_FOUND = -1

LINE_INDEX_NOT_FOUND is returned if requested line could not be found

View Source
var MaxLogLines int = 2000000000

MaxLogLines is a number that will be certainly bigger than any number of logs. Here 2 billion logs is certainly much larger number of log lines than we can handle.

View Source
var NewestLogLineId = LogLineId{
	LogTimestamp: NewestTimestamp,
}

NewestLogLineId is the reference Id of the newest line.

View Source
var OldestLogLineId = LogLineId{
	LogTimestamp: OldestTimestamp,
}

OldestLogLineId is the reference Id of the oldest line.

Functions

func GetLogSources added in v1.6.2

func GetLogSources(k8sClient *client.Clientset, ns string, resourceName string, resourceType string) (controller.LogSources, error)

GetLogSources returns all log sources for a given resource. A log source identifies a log file through the combination of pod & container

Types

type LogDetails added in v1.6.1

type LogDetails struct {

	// Additional information of the logs e.g. container name, dates,...
	Info LogInfo `json:"info"`

	// Reference point to keep track of the position of all the logs
	Selection `json:"selection"`

	// Actual log lines of this page
	LogLines `json:"logs"`
}

Representation of log lines

type LogInfo added in v1.6.1

type LogInfo struct {

	// Pod name.
	PodName string `json:"podName"`

	// The name of the container the logs are for.
	ContainerName string `json:"containerName"`

	// Date of the first log line
	FromDate LogTimestamp `json:"fromDate"`

	// Date of the last log line
	ToDate LogTimestamp `json:"toDate"`

	// Some log lines in the middle of the log file could not be loaded, because the log file is too large.
	Truncated bool `json:"truncated"`
}

Meta information about the selected log lines

type LogLine added in v1.6.1

type LogLine struct {
	Timestamp LogTimestamp `json:"timestamp"`
	Content   string       `json:"content"`
}

A single log line. Split into timestamp and and the actual content

type LogLineId

type LogLineId struct {
	// timestamp of this line.
	LogTimestamp `json:"timestamp"`
	// in case of timestamp duplicates (rather unlikely) it gives the index of the duplicate.
	// For example if this LogTimestamp appears 3 times in the logs and the line is 1nd line with this timestamp,
	// then line num will be 1 or -3 (1st from beginning or 3rd from the end).
	// If timestamp is unique then it will be simply 1 or -1 (first from the beginning or first from the end, both mean the same).
	LineNum int `json:"lineNum"`
}

LogLineId uniquely identifies a line in logs - immune to log addition/deletion.

type LogLines

type LogLines []LogLine

LogLines provides means of selecting log views. Problem with logs is that new logs are constantly added. Therefore the number of logs constantly changes and we cannot use normal indexing. For example if certain line has index N then it may not have index N anymore 1 second later as logs at the beginning of the list are being deleted. Therefore it is necessary to reference log indices relative to some line that we are certain will not be deleted. For example line in the middle of logs should have lifetime sufficiently long for the purposes of log visualisation. On average its lifetime is equal to half of the log retention time. Therefore line in the middle of logs would serve as a good reference point. LogLines allows to get ID of any line - this ID later allows to uniquely identify this line. Also it allows to get any slice of logs relatively to certain reference line ID.

func ToLogLines

func ToLogLines(rawLogs string) LogLines

ToLogLines converts rawLogs (string) to LogLines. This might be slow as we have to split ALL logs by \n. The solution could be to split only required part of logs. To find reference line - do smart binary search on raw string - select the middle, search slightly left and slightly right to find timestamp, eliminate half of the raw string, repeat until found required timestamp. Later easily find and split N subsequent/preceding lines.

func (LogLines) SelectLogs

func (self LogLines) SelectLogs(logSelection *Selection) (LogLines, LogTimestamp, LogTimestamp, Selection, bool)

SelectLogs returns selected part of LogLines as required by logSelector, moreover it returns IDs of first and last of returned lines and the information of the resulting logView.

type LogTimestamp

type LogTimestamp string

LogTimestamp is a timestamp that appears on the beginning of each log line.

type Selection added in v1.6.1

type Selection struct {
	// ReferencePoint is the ID of a line which should serve as a reference point for this selector.
	// You can set it to last or first line if needed. Setting to the first line will result in standard slicing.
	ReferencePoint LogLineId `json:"referencePoint"`
	// First index of the slice relatively to the reference line(this one will be included).
	OffsetFrom int `json:"offsetFrom"`
	// Last index of the slice relatively to the reference line (this one will not be included).
	OffsetTo int `json:"offsetTo"`
	// The log file is loaded either from the beginning or from the end. This matters only if the log file is too
	// large to be handled and must be truncated (to avoid oom)
	LogFilePosition string `json:"logFilePosition"`
}

Selection of a slice of logs. It works just like normal slicing, but indices are referenced relatively to certain reference line. So for example if reference line has index n and we want to download first 10 elements in array we have to use from -n to -n+10. Setting ReferenceLogLineId the first line will result in standard slicing.

Jump to

Keyboard shortcuts

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