util

package
v0.0.0-...-0f57273 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const PerfResultEnd = "[Finish:Performance]"

PerfResultEnd is the end of generated perfdata. Analyzing tools can find the end of the perf result with this tag.

View Source
const PerfResultTag = "[Result:Performance]"

PerfResultTag is the prefix of generated perfdata. Analyzing tools can find the perf result with this tag.

Variables

This section is empty.

Functions

func ComputePercentiles

func ComputePercentiles(timeSeries []ResourceUsagePerContainer, percentilesToCompute []int) map[int]ResourceUsagePerContainer

ComputePercentiles calculates percentiles for given data series.

func ConvertSampleToBucket

func ConvertSampleToBucket(sample *model.Sample, h *HistogramVec)

ConvertSampleToBucket converts prometheus sample into HistogramVec bucket.

func ConvertSampleToHistogram

func ConvertSampleToHistogram(sample *model.Sample, h *Histogram)

ConvertSampleToHistogram converts prometheus sample into Histogram.

func CreateSelectorsString

func CreateSelectorsString(namespace, labelSelector, fieldSelector string) string

CreateSelectorsString creates a string representation for given namespace, label selector and field selector.

func ExtractMetricSamples

func ExtractMetricSamples(metricsBlob string) ([]*model.Sample, error)

ExtractMetricSamples unpacks metric blob into prometheus model structures.

func ExtractMetricSamples2

func ExtractMetricSamples2(response []byte) ([]*model.Sample, error)

ExtractMetricSamples2 unpacks metric blob into prometheus model structures.

func GetMasterHost

func GetMasterHost(host string) (string, error)

GetMasterHost turns host name (without prefix and port).

func LeftMergeData

func LeftMergeData(left, right map[int]ResourceUsagePerContainer) map[int]ResourceUsagePerContainer

LeftMergeData merges two data structures.

func ToPrometheusTime

func ToPrometheusTime(t time.Duration) string

ToPrometheusTime returns prometheus string representation of given time.

func WaitForNodes

func WaitForNodes(clientSet clientset.Interface, stopCh <-chan struct{}, options *WaitForNodeOptions) error

WaitForNodes waits till the desired number of nodes is ready. If stopCh is closed before all nodes are ready, the error will be returned.

func WaitForPVCs

func WaitForPVCs(clientSet clientset.Interface, stopCh <-chan struct{}, options *WaitForPVCOptions) error

WaitForPVCs waits till desired number of PVCs is running. PVCs are be specified by namespace, field and/or label selectors. If stopCh is closed before all PVCs are running, the error will be returned.

func WaitForPVs

func WaitForPVs(clientSet clientset.Interface, stopCh <-chan struct{}, options *WaitForPVOptions) error

WaitForPVs waits till desired number of PVs is running. PVs are be specified by field and/or label selectors. If stopCh is closed before all PVs are running, the error will be returned.

func WaitForPods

func WaitForPods(clientSet clientset.Interface, stopCh <-chan struct{}, options *WaitForPodOptions) error

WaitForPods waits till desired number of pods is running. Pods are be specified by namespace, field and/or label selectors. If stopCh is closed before all pods are running, the error will be returned.

Types

type ContainerResourceUsage

type ContainerResourceUsage struct {
	Name                    string
	Timestamp               time.Time
	CPUUsageInCores         float64
	MemoryUsageInBytes      uint64
	MemoryWorkingSetInBytes uint64
	MemoryRSSInBytes        uint64
	// The interval used to calculate CPUUsageInCores.
	CPUInterval time.Duration
}

ContainerResourceUsage represents resource usage by a single container.

type DataItem

type DataItem struct {
	// Data is a map from bucket to real data point (e.g. "Perc90" -> 23.5). Notice
	// that all data items with the same label combination should have the same buckets.
	Data map[string]float64 `json:"data"`
	// Unit is the data unit. Notice that all data items with the same label combination
	// should have the same unit.
	Unit string `json:"unit"`
	// Labels is the labels of the data item.
	Labels map[string]string `json:"labels,omitempty"`
}

DataItem is the data point.

type Histogram

type Histogram struct {
	Labels  map[string]string `json:"labels"`
	Buckets map[string]int    `json:"buckets"`
}

Histogram is a structure that represents distribution of data.

func NewHistogram

func NewHistogram(labels map[string]string) *Histogram

NewHistogram creates new Histogram instance.

func (*Histogram) Quantile

func (h *Histogram) Quantile(q float64) (float64, error)

Quantile calculates the quantile 'q' based on the given buckets of Histogram.

type HistogramVec

type HistogramVec []Histogram

HistogramVec is an array of Histograms.

type LatencyData

type LatencyData interface {
	GetLatency() time.Duration
}

LatencyData is an interface for latance data structure.

type LatencyMetric

type LatencyMetric struct {
	Perc50 time.Duration `json:"Perc50"`
	Perc90 time.Duration `json:"Perc90"`
	Perc99 time.Duration `json:"Perc99"`
}

LatencyMetric represent 50th, 90th and 99th duration quantiles.

func NewLatencyMetric

func NewLatencyMetric(latencies []LatencyData) LatencyMetric

NewLatencyMetric converts latency data array to latency metric.

func NewLatencyMetricPrometheus

func NewLatencyMetricPrometheus(samples []*model.Sample) (*LatencyMetric, error)

NewLatencyMetricPrometheus tries to parse latency data from results of Prometheus query.

func (*LatencyMetric) SetQuantile

func (metric *LatencyMetric) SetQuantile(quantile float64, latency time.Duration)

SetQuantile set quantile value. Only 0.5, 0.9 and 0.99 quantiles are supported.

func (LatencyMetric) String

func (metric LatencyMetric) String() string

func (*LatencyMetric) ToPerfData

func (metric *LatencyMetric) ToPerfData(name string) DataItem

ToPerfData converts latency metric to PerfData.

func (*LatencyMetric) VerifyThreshold

func (metric *LatencyMetric) VerifyThreshold(threshold time.Duration) error

VerifyThreshold verifies latency metric against given percentile thresholds.

type LatencySlice

type LatencySlice []LatencyData

LatencySlice is a sortable latency array.

func (LatencySlice) Len

func (l LatencySlice) Len() int

func (LatencySlice) Less

func (l LatencySlice) Less(i, j int) bool

func (LatencySlice) Swap

func (l LatencySlice) Swap(i, j int)

type NodeStore

type NodeStore struct {
	*ObjectStore
}

NodeStore is a convenient wrapper around cache.Store.

func NewNodeStore

func NewNodeStore(c clientset.Interface, selector *ObjectSelector) (*NodeStore, error)

NewNodeStore creates NodeStore based on a given object selector.

func (*NodeStore) List

func (s *NodeStore) List() []*v1.Node

List returns list of nodes that satisfy conditions provided to NewNodeStore.

type ObjectSelector

type ObjectSelector struct {
	Namespace     string
	LabelSelector string
	FieldSelector string
}

ObjectSelector is an aggregation of namespace, labelSelector and fieldSelector.

func NewObjectSelector

func NewObjectSelector() *ObjectSelector

NewObjectSelector creates default object selector.

func (*ObjectSelector) Parse

func (o *ObjectSelector) Parse(params map[string]interface{}) error

Parse parses namespace, labelSelector and fieldSelector from params map.

func (*ObjectSelector) String

func (o *ObjectSelector) String() string

String returns string representation of the selector.

type ObjectStore

type ObjectStore struct {
	cache.Store

	Reflector *cache.Reflector
	// contains filtered or unexported fields
}

ObjectStore is a convenient wrapper around cache.Store.

func (*ObjectStore) Stop

func (s *ObjectStore) Stop()

Stop stops ObjectStore watch.

type ObjectTransitionTimes

type ObjectTransitionTimes struct {
	// contains filtered or unexported fields
}

ObjectTransitionTimes stores beginning time of each phase. It can calculate transition latency between phases. ObjectTransitionTimes is thread-safe.

func NewObjectTransitionTimes

func NewObjectTransitionTimes(name string) *ObjectTransitionTimes

NewObjectTransitionTimes creates new ObjectTransitionTimes instance.

func (*ObjectTransitionTimes) CalculateTransitionsLatency

func (o *ObjectTransitionTimes) CalculateTransitionsLatency(t map[string]Transition) map[string]*LatencyMetric

CalculateTransitionsLatency returns a latency map for given transitions.

func (*ObjectTransitionTimes) Count

func (o *ObjectTransitionTimes) Count(phase string) int

Count returns number of key having given phase entry.

func (*ObjectTransitionTimes) Get

func (o *ObjectTransitionTimes) Get(key, phase string) (time.Time, bool)

Get returns time of given phase for given key.

func (*ObjectTransitionTimes) Set

func (o *ObjectTransitionTimes) Set(key, phase string, t time.Time)

Set sets time of given phase for given key.

type PVCDiff

type PVCDiff map[string]*pvcInfo

PVCDiff represets diff between old and new group of pvcs.

func DiffPVCs

func DiffPVCs(oldPVCs []*corev1.PersistentVolumeClaim, curPVCs []*corev1.PersistentVolumeClaim) PVCDiff

DiffPVCs computes a PVCDiff given 2 lists of PVCs.

func (PVCDiff) AddedPVCs

func (p PVCDiff) AddedPVCs() []string

AddedPVCs returns a slice of PVCs that were added.

func (PVCDiff) DeletedPVCs

func (p PVCDiff) DeletedPVCs() []string

DeletedPVCs returns a slice of PVCs that were present at the beginning and then disappeared.

func (PVCDiff) String

func (p PVCDiff) String(ignorePhases sets.String) string

Print formats and prints the give PVCDiff.

type PVCStore

type PVCStore struct {
	*ObjectStore
}

PVCStore is a convenient wrapper around cache.Store.

func NewPVCStore

func NewPVCStore(c clientset.Interface, selector *ObjectSelector) (*PVCStore, error)

NewPVCStore creates PVCStore based on a given object selector.

func (*PVCStore) List

func (s *PVCStore) List() []*v1.PersistentVolumeClaim

List returns list of pvcs (that satisfy conditions provided to NewPVCStore).

type PVCsStartupStatus

type PVCsStartupStatus struct {
	Pending  int
	Bound    int
	Lost     int
	Expected int
	Created  int
}

PVCsStartupStatus represents phase of a pvc group.

func ComputePVCsStartupStatus

func ComputePVCsStartupStatus(pvcs []*corev1.PersistentVolumeClaim, expected int) PVCsStartupStatus

ComputePVCsStartupStatus computes PVCsStartupStatus for a group of PVCs.

func (*PVCsStartupStatus) String

func (s *PVCsStartupStatus) String() string

String returns string representation for PVCsStartupStatus.

type PVDiff

type PVDiff map[string]*pvInfo

PVDiff represents diff between old and new group of PVs.

func DiffPVs

func DiffPVs(oldPVs []*corev1.PersistentVolume, curPVs []*corev1.PersistentVolume) PVDiff

DiffPVs computes a PVDiff given 2 lists of PVs.

func (PVDiff) AddedPVs

func (p PVDiff) AddedPVs() []string

AddedPVs returns a slice of PVs that were added.

func (PVDiff) DeletedPVs

func (p PVDiff) DeletedPVs() []string

DeletedPVs returns a slice of PVs that were present at the beginning and then disappeared.

func (PVDiff) String

func (p PVDiff) String(ignorePhases sets.String) string

Print formats and prints the given PVDiff.

type PVStore

type PVStore struct {
	*ObjectStore
}

PVStore is a convenient wrapper around cache.Store.

func NewPVStore

func NewPVStore(c clientset.Interface, selector *ObjectSelector) (*PVStore, error)

NewPVStore creates PVStore based on a given object selector.

func (*PVStore) List

func (s *PVStore) List() []*v1.PersistentVolume

List returns list of pvs (that satisfy conditions provided to NewPVStore).

type PVsStartupStatus

type PVsStartupStatus struct {
	Pending   int
	Available int
	Bound     int
	Released  int
	Failed    int
	Expected  int
	Created   int
}

PVsStartupStatus represents phase of a PV group.

func ComputePVsStartupStatus

func ComputePVsStartupStatus(PVs []*corev1.PersistentVolume, expected int) PVsStartupStatus

ComputePVsStartupStatus computes PVsStartupStatus for a group of PVs.

func (*PVsStartupStatus) String

func (s *PVsStartupStatus) String() string

String returns string representation for PVsStartupStatus.

type PerfData

type PerfData struct {
	// Version is the version of the metrics. The metrics consumer could use the version
	// to detect metrics version change and decide what version to support.
	Version   string     `json:"version"`
	DataItems []DataItem `json:"dataItems"`
	// Labels is the labels of the dataset.
	Labels map[string]string `json:"labels,omitempty"`
}

PerfData contains all data items generated in current test.

func LatencyMapToPerfData

func LatencyMapToPerfData(latency map[string]*LatencyMetric) *PerfData

LatencyMapToPerfData converts latency map into PerfData.

type PodDiff

type PodDiff map[string]*podDiffInfo

PodDiff represets diff between old and new group of pods.

func DiffPods

func DiffPods(oldPods []*corev1.Pod, curPods []*corev1.Pod) PodDiff

DiffPods computes a PodDiff given 2 lists of pods.

func (PodDiff) AddedPods

func (p PodDiff) AddedPods() []string

AddedPods returns a slice of pods that were added.

func (PodDiff) DeletedPods

func (p PodDiff) DeletedPods() []string

DeletedPods returns a slice of pods that were present at the beginning and then disappeared.

func (PodDiff) String

func (p PodDiff) String(ignorePhases sets.String) string

Print formats and prints the give PodDiff.

type PodStore

type PodStore struct {
	*ObjectStore
}

PodStore is a convenient wrapper around cache.Store.

func NewPodStore

func NewPodStore(c clientset.Interface, selector *ObjectSelector) (*PodStore, error)

NewPodStore creates PodStore based on given object selector.

func (*PodStore) List

func (s *PodStore) List() []*v1.Pod

List returns list of pods (that satisfy conditions provided to NewPodStore).

type PodsStartupStatus

type PodsStartupStatus struct {
	Expected           int
	Terminating        int
	Running            int
	Scheduled          int
	RunningButNotReady int
	Waiting            int
	Pending            int
	Unknown            int
	Inactive           int
	Created            int
	RunningUpdated     int
}

PodsStartupStatus represents status of a pods group.

func ComputePodsStartupStatus

func ComputePodsStartupStatus(pods []*corev1.Pod, expected int, isPodUpdated func(*corev1.Pod) bool) PodsStartupStatus

ComputePodsStartupStatus computes PodsStartupStatus for a group of pods.

func (*PodsStartupStatus) String

func (s *PodsStartupStatus) String() string

String returns string representation for podsStartupStatus.

type PodsStatus

type PodsStatus struct {
	// contains filtered or unexported fields
}

PodsStatus is a collection of current pod phases and node assignments data.

func ComputePodsStatus

func ComputePodsStatus(pods []*corev1.Pod, expected int) *PodsStatus

ComputePodsStatus computes PodsStatus for a group of pods.

func (*PodsStatus) String

func (ps *PodsStatus) String() string

String returns string representation of a PodsStatus.

type PrometheusQueryExecutor

type PrometheusQueryExecutor struct {
	// contains filtered or unexported fields
}

PrometheusQueryExecutor executes queries against Prometheus instance running inside test cluster.

func NewQueryExecutor

func NewQueryExecutor(c clientset.Interface) *PrometheusQueryExecutor

NewQueryExecutor creates instance of PrometheusQueryExecutor.

func (*PrometheusQueryExecutor) Query

func (e *PrometheusQueryExecutor) Query(query string, queryTime time.Time) ([]*model.Sample, error)

Query executes given prometheus query at given point in time.

type ResourceConstraint

type ResourceConstraint struct {
	CPUConstraint    float64 `json: cpuConstraint`
	MemoryConstraint uint64  `json: memoryConstraint`
}

ResourceConstraint specifies constraint on resources.

type ResourceUsagePerContainer

type ResourceUsagePerContainer map[string]*ContainerResourceUsage

ResourceUsagePerContainer is a map of ContainerResourceUsage for containers.

type SSHResult

type SSHResult struct {
	User   string
	Host   string
	Cmd    string
	Stdout string
	Stderr string
	Code   int
}

SSHResult represents result of ssh command.

func SSH

func SSH(cmd, host, provider string) (SSHResult, error)

SSH runs command on given host using ssh.

type SingleContainerSummary

type SingleContainerSummary struct {
	Name string
	Cpu  float64
	Mem  uint64
}

SingleContainerSummary is a resource usage summary for a single container.

type Transition

type Transition struct {
	From      string
	To        string
	Threshold time.Duration
}

Transition describe transition between two phases.

type UsageDataPerContainer

type UsageDataPerContainer struct {
	CpuData        []float64
	MemUseData     []uint64
	MemWorkSetData []uint64
}

UsageDataPerContainer contains resource usage data series.

type WaitForNodeOptions

type WaitForNodeOptions struct {
	Selector             *ObjectSelector
	MinDesiredNodeCount  int
	MaxDesiredNodeCount  int
	EnableLogging        bool
	CallerName           string
	WaitForNodesInterval time.Duration
}

WaitForNodeOptions is an options object used by WaitForNodes methods.

type WaitForPVCOptions

type WaitForPVCOptions struct {
	Selector            *ObjectSelector
	DesiredPVCCount     int
	EnableLogging       bool
	CallerName          string
	WaitForPVCsInterval time.Duration
}

WaitForPVCOptions is an options used by WaitForPVCs methods.

type WaitForPVOptions

type WaitForPVOptions struct {
	Selector           *ObjectSelector
	DesiredPVCount     int
	EnableLogging      bool
	CallerName         string
	WaitForPVsInterval time.Duration
}

WaitForPVOptions is an options used by WaitForPVs methods.

type WaitForPodOptions

type WaitForPodOptions struct {
	Selector            *ObjectSelector
	DesiredPodCount     int
	EnableLogging       bool
	CallerName          string
	WaitForPodsInterval time.Duration

	// IsPodUpdated can be used to detect which pods have been already updated.
	// nil value means all pods are updated.
	IsPodUpdated func(*v1.Pod) bool
}

WaitForPodOptions is an options used by WaitForPods methods.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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