scalertypes

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

View Source
const (
	KindK8sMetricsClient = "k8sMetricsClient"
	KindPrometheusClient = "prometheusClient"
)
View Source
const (
	DefaultResyncInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

func GetKubernetesMetricName added in v0.10.3

func GetKubernetesMetricName(metricName, windowSize string) string

GetKubernetesMetricName constructs a Kubernetes metric name from a base metric name and window size

func ShortDurationString added in v0.10.3

func ShortDurationString(d Duration) string

ShortDurationString formats a Duration into a short string representation by removing trailing zeros

Types

type AutoScalerOptions

type AutoScalerOptions struct {
	Namespace            string
	ScaleInterval        Duration
	GroupKind            schema.GroupKind
	MetricsClientOptions MetricsClientOptions
}

type DLXOptions

type DLXOptions struct {
	Namespace string

	// comma delimited
	TargetNameHeader                  string
	TargetPathHeader                  string
	TargetPort                        int
	ListenAddress                     string
	ResourceReadinessTimeout          Duration
	MultiTargetStrategy               MultiTargetStrategy
	LabelSelector                     string
	ResolveTargetsFromIngressCallback ResolveTargetsFromIngressCallback `json:"-"`
	ResyncInterval                    Duration
	KubeClientSet                     kubernetes.Interface `json:"-"`
}

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type MetricsClient added in v0.10.3

type MetricsClient interface {
	// GetResourceMetrics retrieves metrics for multiple resources.
	//
	// Parameters:
	//   - resources: A slice of resources to retrieve metrics for
	//
	// Returns:
	//   - map[string]map[string]int: A nested map structure where:
	//     * The outer map key is the resource name (e.g., deployment name)
	//     * The inner map key is the metric name
	//     * The inner map value is the metric value as an integer
	//     Example: map["my-deployment"]["requests_per_minute"] = 42
	//   - error: An error if metric retrieval fails
	//
	// The dual map structure allows efficient lookup of metric values by resource name
	// and then by metric name, enabling the autoscaler to check multiple metrics
	// per resource when making scaling decisions.
	GetResourceMetrics(resources []Resource) (map[string]map[string]int, error)
}

MetricsClient defines an interface for retrieving resource metrics used by the autoscaler.

type MetricsClientKind added in v0.10.3

type MetricsClientKind string

type MetricsClientOptions added in v0.10.3

type MetricsClientOptions struct {
	MetricsClientKind MetricsClientKind
	URL               string
	QueryTemplates    []QueryTemplate
}

type MultiTargetStrategy added in v0.5.1

type MultiTargetStrategy string
const (
	MultiTargetStrategyRandom  MultiTargetStrategy = "random"
	MultiTargetStrategyPrimary MultiTargetStrategy = "primary"
	MultiTargetStrategyCanary  MultiTargetStrategy = "canary"
)

type QueryTemplate added in v0.10.3

type QueryTemplate struct {
	Name     string
	Template string
}

QueryTemplate defines a named Prometheus query template.

func (*QueryTemplate) CreateQueryTemplate added in v0.10.3

func (q *QueryTemplate) CreateQueryTemplate() (*template.Template, error)

CreateQueryTemplate parses and validates the query template

type ResolveTargetsFromIngressCallback added in v0.10.0

type ResolveTargetsFromIngressCallback func(ingress *networkingv1.Ingress) ([]string, error)

ResolveTargetsFromIngressCallback defines a function that extracts a list of target identifiers (e.g., names of services the Ingress routes traffic to) from a Kubernetes Ingress resource.

This function is expected to be implemented externally and passed into the IngressWatcher, allowing for custom logic such as parsing annotations, labels, or other ingress metadata.

Parameters:

  • ingress: The Kubernetes Ingress resource to extract targets from

Returns:

  • []string: A slice of target identifiers (e.g., service names, endpoint addresses)
  • error: An error if target resolution fails

Implementation guidelines: - Return a non-nil slice when targets are successfully resolved - Return a non-nil error if resolution fails - Should handle nil or malformed Ingress objects gracefully and return an error in such cases

type Resource

type Resource struct {
	Name               string          `json:"name,omitempty"`
	Namespace          string          `json:"namespace,omitempty"`
	ScaleResources     []ScaleResource `json:"scale_resources,omitempty"`
	LastScaleEvent     *ScaleEvent     `json:"last_scale_event,omitempty"`
	LastScaleEventTime *time.Time      `json:"last_scale_event_time,omitempty"`
}

func (Resource) String

func (r Resource) String() string

type ResourceScaler

type ResourceScaler interface {
	SetScale([]Resource, int) error
	SetScaleCtx(context.Context, []Resource, int) error
	GetResources() ([]Resource, error)
	GetConfig() (*ResourceScalerConfig, error)
	ResolveServiceName(Resource) (string, error)
}

type ResourceScalerConfig

type ResourceScalerConfig struct {
	KubeconfigPath    string
	AutoScalerOptions AutoScalerOptions
	DLXOptions        DLXOptions
}

type ScaleEvent

type ScaleEvent string
const (
	ResourceUpdatedScaleEvent        ScaleEvent = "resourceUpdated"
	ScaleFromZeroStartedScaleEvent   ScaleEvent = "scaleFromZeroStarted"
	ScaleFromZeroCompletedScaleEvent ScaleEvent = "scaleFromZeroCompleted"
	ScaleToZeroStartedScaleEvent     ScaleEvent = "scaleToZeroStarted"
	ScaleToZeroCompletedScaleEvent   ScaleEvent = "scaleToZeroCompleted"
)

func ParseScaleEvent

func ParseScaleEvent(scaleEventStr string) (ScaleEvent, error)

type ScaleResource

type ScaleResource struct {
	MetricName string   `json:"metric_name,omitempty"`
	WindowSize Duration `json:"windows_size,omitempty"`
	Threshold  int      `json:"threshold,omitempty"`
}

func (ScaleResource) GetKubernetesMetricName

func (sr ScaleResource) GetKubernetesMetricName() string

GetKubernetesMetricName constructs a Kubernetes metric name from a base metric name and window size

func (ScaleResource) String

func (sr ScaleResource) String() string

Jump to

Keyboard shortcuts

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