utils

package
v0.0.0-...-6eb52ac Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NameIndex       = "name"
	MaxRetryBackoff = 5 * time.Minute
)

Variables

This section is empty.

Functions

func ChannelIsOpen

func ChannelIsOpen(ch <-chan struct{}) bool

ChannelIsOpen checks if the specified channel is open.

func EnterIdleState

func EnterIdleState(stopChan chan os.Signal)

EnterIdleState is used for preventing the pod from exiting after the test is completed, because it then gets restarted. The test client enters the idle state as soon as it has finished the setup and has run the test goroutines.

func InformerSynced

func InformerSynced(syncFunc func() bool, informerName string) error

InformerSynced verifies that the provided sync function is successful.

func MetaNameIndexFunc

func MetaNameIndexFunc(obj interface{}) ([]string, error)

MetaNameIndexFunc is an index function that indexes based on object's name.

func NewK8sClient

func NewK8sClient() (*clientset.Clientset, error)

NewK8sClient returns a K8s client for the K8s cluster where this application runs inside a pod.

func RecordFirstSuccessfulRequest

func RecordFirstSuccessfulRequest(target *TargetSpec, stopChan chan os.Signal, successFunc func(*TargetSpec, time.Time))

RecordFirstSuccessfulRequest sends curl requests continuously to the provided target IP and target port from the test client config, at 1 second intervals, until the first successful response. It records the latency between the provided start time in the targetSpec, and the time of the first successful response.

func Retry

func Retry(attempts int, backoff time.Duration, fn func() error) error

Retry runs a function until it succeeds, with specified number of attempts and base for exponential backoff.

func ShutDownMetricsServer

func ShutDownMetricsServer(ctx context.Context, metricsServer *http.Server)

ShutDownMetricsServer stops the specified metrics server.

func VerifyHostConfig

func VerifyHostConfig(hostConfig *HostConfig) error

VerifyHostConfig ensures that host configuration is valid.

func VerifyTargetConfig

func VerifyTargetConfig(targetConfig *TargetConfig) error

VerifyTargetConfig ensures that target configuration is valid.

Types

type BaseTestClientConfig

type BaseTestClientConfig struct {
	HostConfig   *HostConfig
	TargetConfig *TargetConfig

	MainStopChan  chan os.Signal
	MetricsServer *http.Server
	K8sClient     *clientset.Clientset
}

BaseTestClientConfig contains the common configuration required for a test client to run.

func CreateBaseTestClientConfig

func CreateBaseTestClientConfig(stopChan chan os.Signal) (*BaseTestClientConfig, error)

CreateBaseTestClientConfig creates base test client configuration based on command-line flags. It parses the flags with "flag.Parse()". All flags need to be defined before calling this function.

type BoolMapWithLock

type BoolMapWithLock struct {
	Mp   map[string]bool
	Lock sync.RWMutex
}

type HostConfig

type HostConfig struct {
	// HostNamespace is the namespace of test client pods.
	HostNamespace string
	// MetricsPort is the port number where Prometheus metrics are exposed.
	MetricsPort int
}

HostConfig holds information about the pod specification where the application runs.

type PodEvent

type PodEvent struct {
	PodName    string
	IsAddEvent bool
}

type TargetConfig

type TargetConfig struct {
	// TargetLabelSelector is the label selector of target pods to send requests
	// to.
	TargetLabelSelector string
	// TargetNamespace is the namespace of target pods to send requests to.
	TargetNamespace string
	// TargetPort is the port number of target pods to send requests to.
	TargetPort int
	// MaxTargets is the maximum number of target pods to send requests to.
	MaxTargets int
}

TargetConfig is configuration for target pods.

type TargetSpec

type TargetSpec struct {
	IP, Name, Namespace string
	Port                int
	StartTime           time.Time
}

type TimeMapWithLock

type TimeMapWithLock struct {
	Mp   map[string]time.Time
	Lock sync.RWMutex
}

type TimeWithLock

type TimeWithLock struct {
	Time *time.Time
	Lock sync.RWMutex
}

Jump to

Keyboard shortcuts

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