logs

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 License: Apache-2.0 Imports: 1 Imported by: 80

Documentation

Index

Constants

View Source
const (
	NewestTimestamp = "newest"
	OldestTimestamp = "oldest"
)

Variables

View Source
var AllLogViewSelector = &LogViewSelector{
	RelativeFrom:       -MaxLogLines,
	RelativeTo:         MaxLogLines,
	ReferenceLogLineId: 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 DefaultLogViewSelector = &LogViewSelector{
	RelativeFrom:       1 - DefaultDisplayNumLogLines,
	RelativeTo:         1,
	ReferenceLogLineId: NewestLogLineId,
}

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

View Source
var LINE_INDEX_NOT_FOUND = -1

Number that 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

This section is empty.

Types

type LogLineId

type LogLineId struct {
	// timestamp of this line.
	LogTimestamp `json:"logTimestamp"`
	// 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 []string

LogLines is a list of strings that provides means of selecting log views. Problem with logs is that old logs are being deleted and 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) GetLineIndex

func (self LogLines) GetLineIndex(logLineId *LogLineId) int

GetLineIndex returns the index of the line (referenced from beginning of log array) with provided logLineId.

func (LogLines) GetLogLineId

func (self LogLines) GetLogLineId(lineIndex int) *LogLineId

GetLogLineId returns ID of the line with provided lineIndex.

func (LogLines) SelectLogs

func (self LogLines) SelectLogs(logSelector *LogViewSelector) (LogLines, LogLineId, LogLineId, LogViewInfo)

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 LogViewInfo

type LogViewInfo struct {
	ReferenceLogLineId LogLineId `json:"referenceLogLineId"`
	RelativeFrom       int       `json:"relativeFrom"`
	RelativeTo         int       `json:"relativeTo"`
}

LogViewInfo provides information on the current log view. Fields have the same meaning as in LogViewSelector.

type LogViewSelector

type LogViewSelector struct {
	// ReferenceLogLineId 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.
	ReferenceLogLineId LogLineId
	// First index of the slice relatively to the reference line(this one will be included).
	RelativeFrom int
	// Last index of the slice relatively to the reference line (this one will not be included).
	RelativeTo int
}

LogViewSelector selects 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.

type Logs

type Logs struct {
	// Pod name.
	PodId string `json:"podId"`

	// Logs string lines.
	LogLines `json:"logs"`

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

	// Reference of the first log line in LogLines
	FirstLogLineReference LogLineId `json:"firstLogLineReference"`

	// Reference of the last log line in LogLines
	LastLogLineReference LogLineId `json:"lastLogLineReference"`

	// Structure holding information about current log view
	LogViewInfo `json:"logViewInfo"`
}

Logs is a representation of logs response structure.

Jump to

Keyboard shortcuts

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