v1

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEFAULT_TASK_TIMEOUT = 5 * time.Second
	DEFAULT_CALL_TIMEOUT = 2 * time.Second
)
View Source
var (
	DEFAULT_CIRCUIT_BREAKER_INTERVAL time.Duration = time.Minute
	DEFAULT_CIRCUIT_BREAKER_TIMEOUT  time.Duration = time.Minute
)
View Source
var (
	DEFAULT_ADAPTIVE_TIMEOUT_INTERVAL time.Duration = time.Minute
	DEFAULT_ADAPTIVE_TIMEOUT_MIN      time.Duration = time.Millisecond
	DEFAULT_ADAPTIVE_TIMEOUT_MAX      time.Duration = time.Minute
)
View Source
var (
	DEFAULT_RETRY_INITIAL_BACKOFF time.Duration = time.Millisecond
)

Functions

func GetPayloadSize

func GetPayloadSize(payloadSpec PayloadSpec) int64

GetPayloadSize parses resource size using "k8s.io/apimachinery/pkg/api/resource", Size is specified. It then looks at Variant for size aliases. Lastly, when none of them is given, default size is returned. The default payload size is defined in "github.com/hanapedia/hexagon/pkg/operator/constants"

func GetPayloadVariant

func GetPayloadVariant(payloadSpec PayloadSpec) constants.PayloadSizeVariant

func ParseResource

func ParseResource(payloadSpec PayloadSpec) (int64, bool)

Types

type AdaptiveTimeoutSpec added in v1.0.18

type AdaptiveTimeoutSpec struct {
	// Min is the minimum timeout duration allowed
	// Must be parsable with time.ParseDuration, otherwise default value will be used
	Min string `json:"min,omitempty"`
	// Max is the maximum timeout duration allowed
	// Must be parsable with time.ParseDuration, otherwise default value will be used
	Max        string `json:"max,omitempty"`
	LatencySLO string `json:"latencySLO,omitempty"` // deprecates Max in v1.2.0
	// RTO is the flag to indicate whether to use RTO
	RTO bool `json:"rto,omitempty"`
	// SLO is the SLO failure rate target used by RTO
	SLO            float64 `json:"slo,omitempty"`
	FailureRateSLO float64 `json:"failureRateSLO,omitempty"` // deprecates SLO in v1.2.0
	// Capacity is the capacity used by RTO to determine the change in load pattern
	Capacity int64 `json:"capacity,omitempty"` // deprecated in v1.2.0
	// Interval is the duration used for the periodic calculation of failure rate
	Interval string `json:"interval,omitempty"`
	// KMargin is the starting kMargin used for rto w/ slo and static kMargin for rto w/out SLO
	KMargin int64 `json:"kMargin,omitempty"`
	// OverloadDetectionTiming specifies the timing for overload detection.
	// can be maxTimeoutGenrated or maxTimeoutExceeded (default)
	OverloadDetectionTiming string `json:"overloadDetectionTiming,omitempty"`
	// OverloadDrainIntervals is the number of intervals for draining overload
	OverloadDrainIntervals uint64 `json:"overloadDrainIntervals,omitempty"`
}

func (*AdaptiveTimeoutSpec) GetFailureRateSLO added in v1.1.2

func (ats *AdaptiveTimeoutSpec) GetFailureRateSLO() float64

func (*AdaptiveTimeoutSpec) GetInterval added in v1.0.18

func (ats *AdaptiveTimeoutSpec) GetInterval() time.Duration

func (*AdaptiveTimeoutSpec) GetLatencySLO added in v1.1.2

func (ats *AdaptiveTimeoutSpec) GetLatencySLO() time.Duration

func (*AdaptiveTimeoutSpec) GetMin added in v1.0.18

func (ats *AdaptiveTimeoutSpec) GetMin() time.Duration

type CircuitBreakerSpec added in v1.0.10

type CircuitBreakerSpec struct {
	// MaxRequests is the max number of requests to go through when half open
	// if MaxRequests is 0, circuit breaker will only allow 1 request
	// Use GetMaxRequests to read the value with default values
	MaxRequests uint32 `json:"maxRequests,omitempty"`

	// Interval is the cycle duration to clear the internal count for request success / failure during closed state
	// Must be parsable with time.ParseDuration, otherwise default value will be used
	Interval string `json:"interval,omitempty"`

	// Timeout is the amount of duration that the circuit breaker stays open after breaching the threshold
	// Must be parsable with time.ParseDuration, otherwise default value will be used
	Timeout string `json:"timeout,omitempty"`

	// MinRequests is the min number of requests required to open the circuit
	MinRequests uint32 `json:"minRequests,omitempty"`

	// Ratio is the threshold ratio of failed request / total number of requests
	// If ConsecutiveFails is set as well, whichever trips first will take precedence
	// If neither is set, circuit breaker will trip on the first error
	Ratio float64 `json:"ratio,omitempty"`

	// ConsecutiveFails is the number of consecutive failures as threshold
	// If Ratio is set as well, whichever trips first will take precedence
	// If neither is set, circuit breaker will trip on the first error
	ConsecutiveFails uint32 `json:"consecutiveFails,omitempty"`

	// CountRetries specify whether the retry attempts are counted by the circuit breaker.
	// if set to `true`, the circuit breaker counts each attempt.
	// if set to `false`, the circuit breaker counts all retry attempts as a single request.
	// Note that circuit broken requests will also be retried when set to true.
	CountRetries bool `json:"countRetries,omitempty"`

	// Disabled is the flag to turn off circuit breaker feature entirely
	Disabled bool `json:"disabled,omitempty"`
}

func (*CircuitBreakerSpec) GetInterval added in v1.0.10

func (cbs *CircuitBreakerSpec) GetInterval() time.Duration

Get parsed circuit breaker interval as time.Duration

func (*CircuitBreakerSpec) GetTimeout added in v1.0.10

func (cbs *CircuitBreakerSpec) GetTimeout() time.Duration

Get parsed circuit breaker timeout as time.Duration

type ClusterConfig added in v1.0.10

type ClusterConfig struct {
	ConfigTemplate
	Namespace         string                     `json:"namespace,omitempty"`
	LogLevel          string                     `json:"logLevel,omitempty"`
	ServiceMonitor    bool                       `json:"serviceMonitor,omitempty"`
	DockerHubUsername string                     `json:"dockerHubUsername,omitempty"`
	MetricsPort       int32                      `json:"metricsPort,omitempty"`
	HealthPort        int32                      `json:"healthPort,omitempty"`
	HTTPPort          int32                      `json:"httpPort,omitempty"`
	GRPCPort          int32                      `json:"grpcPort,omitempty"`
	Tracing           TracingClusterConfig       `json:"tracing,omitempty"`
	Kafka             KafkaClusterConfig         `json:"kafka,omitempty"`
	Mongo             MongoClusterConfig         `json:"mongo,omitempty"`
	Redis             RedisClusterConfig         `json:"redis,omitempty"`
	Otel              OtelCollectorClusterConfig `json:"otel,omitempty"`
}

func NewClusterConfig added in v1.0.10

func NewClusterConfig() ClusterConfig

type ConfigKind added in v1.0.10

type ConfigKind string
var (
	ServiceUnitKind   ConfigKind = "ServiceUnit"
	ClusterConfigKind ConfigKind = "ClusterConfig"
)

type ConfigTemplate added in v1.0.10

type ConfigTemplate struct {
	ApiVersion string     `json:"apiVersion,omitempty"`
	Kind       ConfigKind `json:"kind,omitempty"`
}

type ConsumerConfig

type ConsumerConfig struct {
	Variant constants.BrokerVariant `json:"variant,omitempty" validate:"required"`
	Topic   string                  `json:"topic,omitempty" validate:"required"`
}

Config fields for Brokers

func (*ConsumerConfig) GetConsumerGroupId

func (bac *ConsumerConfig) GetConsumerGroupId(serviceName string) string

Get consumer group id

func (*ConsumerConfig) GetGroupByKey

func (bac *ConsumerConfig) GetGroupByKey() string

Get consumer adapter id

func (*ConsumerConfig) GetId

func (bac *ConsumerConfig) GetId(serviceName string) string

Get consumer adapter id

type DeploymentSpec

type DeploymentSpec struct {
	Replicas                       int32                        `json:"replicas,omitempty"`
	Gateway                        *Gateway                     `json:"gateway,omitempty"`
	Resource                       *corev1.ResourceRequirements `json:"resources,omitempty"`
	EnvVar                         []corev1.EnvVar              `json:"env,omitempty"`
	EnableTopologySpreadConstraint bool                         `json:"enableTopologySpreadConstraint,omitempty"`
	DisableReadinessProbe          bool                         `json:"disableReadinessProbe,omitempty"`
}

DeploymentSpec contains configuration for deployment

type Gateway

type Gateway struct {
	// VirtualUsers is the number of virtual users simulated.
	VirtualUsers int32 `json:"virtualUsers,omitempty"`

	// Duration given in minutes
	Duration int32 `json:"duration,omitempty"`
}

Gateway contains config information about loadgenerator

type InvocationConfig

type InvocationConfig struct {
	Variant constants.SeverAdapterVariant `json:"variant,omitempty" validate:"required,oneof=rest grpc"`
	Service string                        `json:"service,omitempty" validate:"required"`
	Action  constants.Action              `json:"action,omitempty" validate:"required"`
	Route   string                        `json:"route,omitempty" validate:"required"`
	Payload PayloadSpec                   `json:"payload,omitempty"`
}

Config fields for server services

func (*InvocationConfig) GetGroupByKey

func (sac *InvocationConfig) GetGroupByKey() string

Get group key

func (*InvocationConfig) GetId

func (sac *InvocationConfig) GetId() string

Get server secondary adapter id

type KafkaClusterConfig added in v1.0.10

type KafkaClusterConfig struct {
	Port         int32  `json:"port,omitempty"`
	ClusterName  string `json:"clusterName,omitempty"`
	Namespace    string `json:"namespace,omitempty"`
	Partitions   int32  `json:"partitions,omitempty"`
	Replications int32  `json:"replications,omitempty"`
}

type MongoClusterConfig added in v1.0.10

type MongoClusterConfig struct {
	ImageName string `json:"imageName,omitempty"`
	Port      int32  `json:"port,omitempty"`
	Username  string `json:"username,omitempty"`
	Password  string `json:"password,omitempty"`
}

type OtelCollectorClusterConfig added in v1.0.10

type OtelCollectorClusterConfig struct {
	Port      int32  `json:"port,omitempty"`
	Name      string `json:"name,omitempty"`
	Namespace string `json:"namespace,omitempty"`
}

type PayloadSpec

type PayloadSpec struct {
	Size    string                       `json:"size,omitempty"`
	Variant constants.PayloadSizeVariant `json:"variant,omitempty" validate:"omitempty,oneof=small medium large"`
	Count   int                          `json:"payloadCount,omitempty"`
}

PayloadSpec contains configuration for payload sent by adapters

type PrimaryAdapterSpec

type PrimaryAdapterSpec struct {
	ServerConfig     *ServerConfig     `json:"server,omitempty"`
	ConsumerConfig   *ConsumerConfig   `json:"consumer,omitempty"`
	RepositoryConfig *RepositoryConfig `json:"repository,omitempty"`
	TaskSpecs        []TaskSpec        `json:"tasks,omitempty" validate:"required"`

	// +optional
	Selector *metav1.LabelSelector `json:"selector,omitempty"`
}

PrimaryAdapterSpec must be attachted to a service unit

func (*PrimaryAdapterSpec) GetGroupByKey

func (ias *PrimaryAdapterSpec) GetGroupByKey() string

Get primary adapter group by key

func (*PrimaryAdapterSpec) GetId

func (ias *PrimaryAdapterSpec) GetId(serviceName string) string

Get primary adapter id

type ProducerConfig

type ProducerConfig struct {
	Variant constants.BrokerVariant `json:"variant,omitempty" validate:"required,oneof=kafka rabbitmq pulsar"`
	Topic   string                  `json:"topic,omitempty" validate:"required"`
	Payload PayloadSpec             `json:"payload,omitempty"`
}

Config fields for Brokers

func (*ProducerConfig) GetGroupByKey

func (bac *ProducerConfig) GetGroupByKey() string

Get broker secondary adapter group by key

func (*ProducerConfig) GetId

func (bac *ProducerConfig) GetId() string

Get broker secondary adapter id

type RedisClusterConfig added in v1.0.10

type RedisClusterConfig struct {
	ImageName string `json:"imageName,omitempty"`
	Port      int32  `json:"port,omitempty"`
}

type RepositoryClientConfig

type RepositoryClientConfig struct {
	Name    string                      `json:"name,omitempty" validate:"required"`
	Variant constants.RepositoryVariant `json:"variant,omitempty" validate:"required,oneof=mongo redis postgre"`
	Action  constants.Action            `json:"action,omitempty" validate:"omitempty"`
	Payload PayloadSpec                 `json:"payload,omitempty"`
}

Config fields for repository services

func (*RepositoryClientConfig) GetGroupByKey

func (sac *RepositoryClientConfig) GetGroupByKey() string

Get repository secondary adapter group by key

func (*RepositoryClientConfig) GetId

func (sac *RepositoryClientConfig) GetId() string

Get repository secondary adapter id

type RepositoryConfig

type RepositoryConfig struct {
	Variant constants.RepositoryVariant `json:"variant,omitempty" validate:"required,oneof=mongo redis"`
}

Config fields for repository services

func (*RepositoryConfig) GetGroupByKey

func (rac *RepositoryConfig) GetGroupByKey() string

Get repository adapter group by key

func (*RepositoryConfig) GetId

func (sac *RepositoryConfig) GetId(serviceName string) string

Get repository adapter id

type ResiliencySpec added in v1.0.10

type ResiliencySpec struct {
	// IsCritical takes boolean specifying whether to fail
	// the parent primary adapter call when this secondary adapter call fails.
	IsCritical bool `json:"isCritical,omitempty"`

	// Retry configurations
	Retry RetrySpec `json:"retry,omitempty"`

	// CircutBreaker configurations
	CircutBreaker CircuitBreakerSpec `json:"circuitBreaker,omitempty"`

	// taskTimeout is used as the value for request timeout of the calls INCLUDING all retries.
	// Must be parsable with time.ParseDuration, otherwise default value will be used.
	TaskTimeout string `json:"taskTimeout,omitempty"`
	// callTimeout refers to the timeout assigend to each call attempt
	CallTimeout string `json:"callTimeout,omitempty"`

	// AdaptiveTaskTimeout takes configurations for adaptive task timeout
	AdaptiveTaskTimeout AdaptiveTimeoutSpec `json:"adaptiveTaskTimeout,omitempty"`

	// AdaptiveCallTimeout takes configurations for adaptive call timeout
	AdaptiveCallTimeout AdaptiveTimeoutSpec `json:"adaptiveCallTimeout,omitempty"`
}

ResiliencySpec is the configuration for what the service unit will do when the secondary adapter call fails

func (ResiliencySpec) GetCallTimeout added in v1.0.10

func (r ResiliencySpec) GetCallTimeout() time.Duration

Get parsed getCallTimeout as time.Duration

func (ResiliencySpec) GetTaskTimeout added in v1.0.10

func (r ResiliencySpec) GetTaskTimeout() time.Duration

Get parsed taskTimeout as time.Duration

type RetryBackoffPolicy added in v1.0.10

type RetryBackoffPolicy = string
const (
	NO_BACKOFF          RetryBackoffPolicy = "none"
	CONSTANT_BACKOFF    RetryBackoffPolicy = "constant"
	LINEAR_BACKOFF      RetryBackoffPolicy = "linear"
	EXPONENTIAL_BACKOFF RetryBackoffPolicy = "exponential"
)

type RetrySpec added in v1.0.10

type RetrySpec struct {
	// BackoffPolicy configurs the backoff policy used for subsequent retries.
	// Available configurations are
	//   - none: Default. No retry backoff.
	//   - constant: Retries without any backoffs.
	//   - linear: Retries with linearly scaling backoff. Scaling can be configured from RetryBackoffScaling
	//   - exponential: Retries with exponentially scaling backoff.
	BackoffPolicy RetryBackoffPolicy `json:"backoffPolicy,omitempty"`

	// MaxAttempt specifies the max number of retries before giving up.
	MaxAttempt int `json:"maxAttempt,omitempty"`

	// InitialBackoff specifies the initial duration to backoff
	//
	// Must be parsable using time.ParseDuration
	InitialBackoff string `json:"initialBackoff,omitempty"`

	// Disabled is the flag to turn off retry feature entirely
	Disabled bool `json:"disabled,omitempty"`
}

func (*RetrySpec) GetInitialBackoff added in v1.0.10

func (rs *RetrySpec) GetInitialBackoff() time.Duration

Get parsed initial backoff as time.Duration

func (*RetrySpec) GetNthBackoff added in v1.0.10

func (rs *RetrySpec) GetNthBackoff(n int) time.Duration

GetNthBackoff returns the backoff duration for Nth retry attempt.

type SecondaryAdapterConfig

type SecondaryAdapterConfig struct {
	InvocationConfig *InvocationConfig       `json:"invocation,omitempty"`
	RepositoryConfig *RepositoryClientConfig `json:"repository,omitempty"`
	ProducerConfig   *ProducerConfig         `json:"producer,omitempty"`
	StressorConfig   *StressorConfig         `json:"stressor,omitempty"`
}

secondary Adapter definition for a task. one of the adapter type must be provided

func (SecondaryAdapterConfig) GetGroupByKey

func (sac SecondaryAdapterConfig) GetGroupByKey() string

Get primary adapter group by key Get secondary adapter id

func (*SecondaryAdapterConfig) GetId

func (sac *SecondaryAdapterConfig) GetId() string

Get secondary adapter id

type ServerConfig

type ServerConfig struct {
	Variant constants.SeverAdapterVariant `json:"variant,omitempty" validate:"required,oneof=rest grpc"`
	Action  constants.Action              `json:"action,omitempty" validate:"required"`
	Route   string                        `json:"route,omitempty" validate:"required"`
	Payload PayloadSpec                   `json:"payload,omitempty"`

	// applies to only gateway service
	// refers to the weight applied to the route
	// intentionally a pointer to destinguish 0
	Weight *int32 `json:"weight,omitempty"`
}

Config fields for repository services

func (*ServerConfig) GetGroupByKey

func (sac *ServerConfig) GetGroupByKey() string

Get invocation adapter id

func (*ServerConfig) GetId

func (sac *ServerConfig) GetId(serviceName string) string

Get invocation adapter id

type ServiceUnitConfig

type ServiceUnitConfig struct {
	ConfigTemplate
	Name           string               `json:"name,omitempty" validate:"required"`
	Version        string               `json:"version,omitempty" validate:"required"`
	AdapterConfigs []PrimaryAdapterSpec `json:"adapters,omitempty" validate:"required"`
	DeploymentSpec DeploymentSpec       `json:"deployment,omitempty"`
}

this type is not used by the custom resource.

type StressorConfig

type StressorConfig struct {
	Name        string                    `json:"name,omitempty" validate:"required"`
	Variant     constants.StressorValiant `json:"variant,omitempty" validate:"required,oneof=cpu memory disk"`
	Iterations  int                       `json:"iters,omitempty" validate:"omitempty"`
	ThreadCount int                       `json:"threads,omitempty" validate:"omitempty"`
	Payload     PayloadSpec               `json:"payload,omitempty"`
}

Config fields for Stressor

func (*StressorConfig) GetGroupByKey added in v1.0.13

func (iac *StressorConfig) GetGroupByKey() string

Get internal adapter id

func (*StressorConfig) GetId

func (iac *StressorConfig) GetId() string

Get internal adapter id

type TaskSpec added in v1.0.10

type TaskSpec struct {
	AdapterConfig *SecondaryAdapterConfig `json:"adapter,omitempty" validate:"required"`
	Concurrent    bool                    `json:"concurrent,omitempty" `
	Resiliency    ResiliencySpec          `json:"resiliency,omitempty"`
}

A spec for atask to be performed

type TracingClusterConfig added in v1.0.10

type TracingClusterConfig struct {
	Enabled bool `json:"enabled,omitempty"`
}

Jump to

Keyboard shortcuts

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