utils

package
v1.14.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureLoggingAgentDeployment

func EnsureLoggingAgentDeployment(f *framework.Framework, appName string) error

EnsureLoggingAgentDeployment checks that logging agent is present on each node and returns an error if that's not true.

func EnsureLoggingAgentRestartsCount

func EnsureLoggingAgentRestartsCount(f *framework.Framework, appName string, maxRestarts int) error

EnsureLoggingAgentRestartsCount checks that each logging agent was restarted no more than maxRestarts times and returns an error if there's a pod which exceeds this number of restarts.

func GetNodeIds

func GetNodeIds(cs clientset.Interface) []string

GetNodeIds returns the list of node names and panics in case of failure.

func WaitForLogs

func WaitForLogs(c LogChecker, interval, timeout time.Duration) error

WaitForLogs checks that logs are ingested, as reported by the log checker until the timeout has passed. Function sleeps for interval between two log ingestion checks.

Types

type FiniteLoggingPod

type FiniteLoggingPod interface {
	LoggingPod

	// ExpectedLinesNumber returns the number of lines that are
	// expected to be ingested from this pod.
	ExpectedLineCount() int
}

FiniteLoggingPod is a logging pod that emits a known number of log lines.

func NewLoadLoggingPod

func NewLoadLoggingPod(podName string, nodeName string, totalLines int,
	loggingDuration time.Duration) FiniteLoggingPod

NewLoadLoggingPod returns a logging pod that generates totalLines random lines over period of length loggingDuration. Lines generated by this pod are numbered and have well-defined structure.

type IngestionPred

type IngestionPred func(string, []LogEntry) (bool, error)

IngestionPred is a type of a function that checks whether all required log entries were ingested.

var UntilFirstEntry IngestionPred = func(_ string, entries []LogEntry) (bool, error) {
	return len(entries) > 0, nil
}

UntilFirstEntry is a IngestionPred that checks that at least one entry was ingested.

func UntilFirstEntryFromLocation added in v1.10.0

func UntilFirstEntryFromLocation(location string) IngestionPred

UntilFirstEntryFromLocation is a IngestionPred that checks that at least one entry from the log with a given name was ingested.

func UntilFirstEntryFromLog

func UntilFirstEntryFromLog(log string) IngestionPred

UntilFirstEntryFromLog is a IngestionPred that checks that at least one entry from the log with a given name was ingested.

type LogChecker

type LogChecker interface {
	EntriesIngested() (bool, error)
	Timeout() error
}

LogChecker is an interface for an entity that can check whether logging backend contains all wanted log entries.

func NewFullIngestionPodLogChecker

func NewFullIngestionPodLogChecker(p LogProvider, slack float64, pods ...FiniteLoggingPod) LogChecker

NewFullIngestionPodLogChecker returns a log checks that works with numbered log entries generated by load logging pods and waits until all entries are ingested. If timeout is reached, fraction is lost logs up to slack is considered tolerable.

func NewLogChecker

func NewLogChecker(p LogProvider, pred IngestionPred, timeout TimeoutFun, names ...string) LogChecker

NewLogChecker constructs a LogChecker for a list of names from custom IngestionPred and TimeoutFun.

func NewNumberedLogChecker

func NewNumberedLogChecker(p LogProvider, pred NumberedIngestionPred,
	timeout NumberedTimeoutFun, names ...string) LogChecker

NewNumberedLogChecker returns a log checker that works with numbered log entries generated by load logging pods.

type LogEntry

type LogEntry struct {
	LogName     string
	TextPayload string
	Location    string
	JSONPayload map[string]interface{}
}

LogEntry represents a log entry, received from the logging backend.

func (LogEntry) TryGetEntryNumber

func (entry LogEntry) TryGetEntryNumber() (int, bool)

TryGetEntryNumber returns the number of the log entry in sequence, if it was generated by the load logging pod (requires special log format).

type LogProvider

type LogProvider interface {
	Init() error
	Cleanup()
	ReadEntries(name string) []LogEntry
	LoggingAgentName() string
}

LogProvider interface provides an API to get logs from the logging backend.

type LoggingPod

type LoggingPod interface {
	// Name equals to the Kubernetes pod name.
	Name() string

	// Start method controls when the logging pod is started in the cluster.
	Start(f *framework.Framework) error
}

LoggingPod is an interface of a pod that can be started and that logs something to its stdout, possibly indefinitely.

func NewExecLoggingPod

func NewExecLoggingPod(podName string, cmd []string) LoggingPod

NewExecLoggingPod returns a logging pod that produces logs through executing a command, passed in cmd.

func NewRepeatingLoggingPod

func NewRepeatingLoggingPod(podName string, line string) LoggingPod

NewRepeatingLoggingPod returns a logging pod that each second prints line value to its stdout.

func StartAndReturnSelf

func StartAndReturnSelf(p LoggingPod, f *framework.Framework) (LoggingPod, error)

StartAndReturnSelf is a helper method to start a logging pod and immediately return it.

type LogsQueueCollection

type LogsQueueCollection interface {
	Push(name string, logs ...LogEntry)
	Pop(name string) []LogEntry
}

LogsQueueCollection is a thread-safe set of named log queues.

func NewLogsQueueCollection

func NewLogsQueueCollection(queueSize int) LogsQueueCollection

NewLogsQueueCollection returns a new LogsQueueCollection where each queue is created with a default size of queueSize.

type NumberedIngestionPred

type NumberedIngestionPred func(string, map[int]bool) (bool, error)

NumberedIngestionPred is a IngestionPred that takes into account sequential numbers of ingested entries.

type NumberedTimeoutFun

type NumberedTimeoutFun func([]string, map[string]map[int]bool) error

NumberedTimeoutFun is a TimeoutFun that takes into account sequential numbers of ingested entries.

type TimeoutFun

type TimeoutFun func([]string, []bool) error

TimeoutFun is a function that is called when the waiting times out.

var JustTimeout TimeoutFun = func(names []string, ingested []bool) error {
	failedNames := []string{}
	for i, name := range names {
		if !ingested[i] {
			failedNames = append(failedNames, name)
		}
	}
	return fmt.Errorf("timed out waiting for ingestion, still not ingested: %s",
		strings.Join(failedNames, ","))
}

JustTimeout returns the error with the list of names for which backend is still still missing logs.

Jump to

Keyboard shortcuts

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