Documentation
¶
Index ¶
- Constants
- func GetKubernetesMetricName(metricName, windowSize string) string
- func ShortDurationString(d Duration) string
- type AutoScalerOptions
- type DLXOptions
- type Duration
- type MetricsClient
- type MetricsClientKind
- type MetricsClientOptions
- type MultiTargetStrategy
- type QueryTemplate
- type ResolveTargetsFromIngressCallback
- type Resource
- type ResourceScaler
- type ResourceScalerConfig
- type ScaleEvent
- type ScaleResource
Constants ¶
const ( KindK8sMetricsClient = "k8sMetricsClient" KindPrometheusClient = "prometheusClient" )
const (
DefaultResyncInterval = 30 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
func GetKubernetesMetricName ¶ added in v0.10.3
GetKubernetesMetricName constructs a Kubernetes metric name from a base metric name and window size
func ShortDurationString ¶ added in v0.10.3
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 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
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"`
}
type ResourceScaler ¶
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