pod

package
v0.0.0-...-7c3836c Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 27 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 log file. This matters only if the log file is too large to be loaded completely.

Variables

View Source
var (
	ErrProjectPodsList   = errors.New("该项目的pods列表获取错误,请查看是否存在")
	ErrPodLogGet         = errors.New("容器日志获取错误,请重试")
	ErrPodGet            = errors.New("容器获取错误,可能不存在,请重试")
	ErrPodDelete         = errors.New("pod删除错误,请重试")
	ErrPodDownloadLogGet = errors.New("容器日志流获取错误,请重试")
	ErrPodDeploymentGet  = errors.New("项目获取错误,请重试")
)
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 MakeHandler

func MakeHandler(svc Service, logger log.Logger, repository repository.Repository) http.Handler

Types

type LogDetails

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

type LogInfo struct {
	// Pod name.
	PodName string `json:"podName"`

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

	// The name of the init container the logs are for.
	InitContainerName string `json:"initContainerName"`

	// 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

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

A single log line. Split into timestamp 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. Proper log lines start with a timestamp which is chopped off. In error cases the server returns a message without a timestamp

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

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.

type Service

type Service interface {
	// pod详情页数据
	Detail(ctx context.Context, podName string) (res map[string]interface{}, err error)

	// Pods 列表
	ProjectPods(ctx context.Context) (res []map[string]interface{}, err error)

	// 获取容器日志
	GetLog(ctx context.Context, podName, container string, previous bool) (res *LogDetails, err error)

	// 下载pod 容器日志
	DownloadLog(ctx context.Context, podName, container string, previous bool) (res io.ReadCloser, err error)

	// 删除pod
	Delete(ctx context.Context, podName string) (err error)

	// pods的内存及CPU使用
	PodsMetrics(ctx context.Context) (res map[string]interface{}, err error)

	PodsNetwork(ctx context.Context) (res map[string]interface{}, err error)
}

func NewLoggingService

func NewLoggingService(logger log.Logger, s Service) Service

func NewService

func NewService(logger log.Logger, k8sClient kubernetes.K8sClient, config *config.Config, hookQueueSvc hooks.ServiceHookQueue) Service

Jump to

Keyboard shortcuts

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