 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- func GetMetricFromSource(ctx context.Context, fetcher MetricFetcher, ...) (float64, error)
- func GetMetricUsageRatio(metrics PodMetricsInfo, targetUsage int64) (usageRatio float64, currentUsage int64)
- func GetMetricsFromPods(ctx context.Context, fetcher MetricFetcher, pods []corev1.Pod, ...) ([]float64, error)
- func GetResourceUtilizationRatio(metrics PodMetricsInfo, requests map[string]int64, targetUtilization int32) (utilizationRatio float64, currentUtilization int32, rawAverageValue int64, ...)
- func ParseMetricFromBody(body []byte, metricName string) (float64, error)
- type APAMetricsClient
- func (c *APAMetricsClient) GetMetricFromSource(ctx context.Context, source autoscalingv1alpha1.MetricSource) (float64, error)
- func (c *APAMetricsClient) GetMetricValue(metricKey NamespaceNameMetric, now time.Time) (float64, error)
- func (c *APAMetricsClient) GetMetricsFromPods(ctx context.Context, pods []corev1.Pod, ...) ([]float64, error)
- func (c *APAMetricsClient) GetPodContainerMetric(ctx context.Context, pod corev1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
- func (c *APAMetricsClient) UpdateMetricIntoWindow(now time.Time, metricValue float64) error
- func (c *APAMetricsClient) UpdateMetrics(now time.Time, metricKey NamespaceNameMetric, metricValues ...float64) error
- func (c *APAMetricsClient) UpdatePodListMetric(metricValues []float64, metricKey NamespaceNameMetric, now time.Time) error
 
- type CustomMetricsFetcher
- type KPAMetricsClient
- func (c *KPAMetricsClient) GetMetricFromSource(ctx context.Context, source autoscalingv1alpha1.MetricSource) (float64, error)
- func (c *KPAMetricsClient) GetMetricsFromPods(ctx context.Context, pods []corev1.Pod, ...) ([]float64, error)
- func (c *KPAMetricsClient) GetPodContainerMetric(ctx context.Context, pod corev1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
- func (c *KPAMetricsClient) StableAndPanicMetrics(metricKey NamespaceNameMetric, now time.Time) (float64, float64, error)
- func (c *KPAMetricsClient) UpdateMetricIntoWindow(now time.Time, metricValue float64) error
- func (c *KPAMetricsClient) UpdateMetrics(now time.Time, metricKey NamespaceNameMetric, metricValues ...float64) error
- func (c *KPAMetricsClient) UpdatePodListMetric(metricValues []float64, metricKey NamespaceNameMetric, now time.Time) error
 
- type KubernetesMetricsFetcher
- type MetricClient
- type MetricFetcher
- type MetricType
- type NamespaceNameMetric
- type PodMetric
- type PodMetricsInfo
- type ResourceMetricsFetcher
- type RestMetricsFetcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMetricFromSource ¶
func GetMetricFromSource(ctx context.Context, fetcher MetricFetcher, source autoscalingv1alpha1.MetricSource) (float64, error)
func GetMetricUsageRatio ¶
func GetMetricUsageRatio(metrics PodMetricsInfo, targetUsage int64) (usageRatio float64, currentUsage int64)
GetMetricUsageRatio takes in a set of metrics and a target usage value, and calculates the ratio of desired to actual usage (returning that and the actual usage)
func GetMetricsFromPods ¶
func GetMetricsFromPods(ctx context.Context, fetcher MetricFetcher, pods []corev1.Pod, source autoscalingv1alpha1.MetricSource) ([]float64, error)
func GetResourceUtilizationRatio ¶
func GetResourceUtilizationRatio(metrics PodMetricsInfo, requests map[string]int64, targetUtilization int32) (utilizationRatio float64, currentUtilization int32, rawAverageValue int64, err error)
GetResourceUtilizationRatio takes in a set of metrics, a set of matching requests, and a target utilization percentage, and calculates the ratio of desired to actual utilization (returning that, the actual utilization, and the raw average value)
Types ¶
type APAMetricsClient ¶
type APAMetricsClient struct {
	// contains filtered or unexported fields
}
    func NewAPAMetricsClient ¶
func NewAPAMetricsClient(fetcher MetricFetcher, duration time.Duration) *APAMetricsClient
NewAPAMetricsClient initializes and returns a KPAMetricsClient with specified durations.
func (*APAMetricsClient) GetMetricFromSource ¶
func (c *APAMetricsClient) GetMetricFromSource(ctx context.Context, source autoscalingv1alpha1.MetricSource) (float64, error)
func (*APAMetricsClient) GetMetricValue ¶
func (c *APAMetricsClient) GetMetricValue( metricKey NamespaceNameMetric, now time.Time) (float64, error)
func (*APAMetricsClient) GetMetricsFromPods ¶
func (c *APAMetricsClient) GetMetricsFromPods(ctx context.Context, pods []corev1.Pod, source autoscalingv1alpha1.MetricSource) ([]float64, error)
func (*APAMetricsClient) GetPodContainerMetric ¶
func (c *APAMetricsClient) GetPodContainerMetric(ctx context.Context, pod corev1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
func (*APAMetricsClient) UpdateMetricIntoWindow ¶
func (c *APAMetricsClient) UpdateMetricIntoWindow(now time.Time, metricValue float64) error
func (*APAMetricsClient) UpdateMetrics ¶
func (c *APAMetricsClient) UpdateMetrics(now time.Time, metricKey NamespaceNameMetric, metricValues ...float64) error
func (*APAMetricsClient) UpdatePodListMetric ¶
func (c *APAMetricsClient) UpdatePodListMetric(metricValues []float64, metricKey NamespaceNameMetric, now time.Time) error
type CustomMetricsFetcher ¶
type CustomMetricsFetcher struct {
	// contains filtered or unexported fields
}
    CustomMetricsFetcher fetches custom metrics from Kubernetes' native Custom Metrics API.
func NewCustomMetricsFetcher ¶
func NewCustomMetricsFetcher(client custom_metrics.CustomMetricsClient) *CustomMetricsFetcher
NewCustomMetricsFetcher creates a new fetcher for Custom Metrics API.
func (*CustomMetricsFetcher) FetchMetric ¶
func (*CustomMetricsFetcher) FetchPodMetrics ¶
func (f *CustomMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, metricName string) (float64, error)
FetchPodMetrics fetches custom metrics for a pod using the Custom Metrics API.
type KPAMetricsClient ¶
type KPAMetricsClient struct {
	// contains filtered or unexported fields
}
    func NewKPAMetricsClient ¶
func NewKPAMetricsClient(fetcher MetricFetcher, stableDuration time.Duration, panicDuration time.Duration) *KPAMetricsClient
NewKPAMetricsClient initializes and returns a KPAMetricsClient with specified durations.
func (*KPAMetricsClient) GetMetricFromSource ¶
func (c *KPAMetricsClient) GetMetricFromSource(ctx context.Context, source autoscalingv1alpha1.MetricSource) (float64, error)
func (*KPAMetricsClient) GetMetricsFromPods ¶
func (c *KPAMetricsClient) GetMetricsFromPods(ctx context.Context, pods []corev1.Pod, source autoscalingv1alpha1.MetricSource) ([]float64, error)
func (*KPAMetricsClient) GetPodContainerMetric ¶
func (c *KPAMetricsClient) GetPodContainerMetric(ctx context.Context, pod corev1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
func (*KPAMetricsClient) StableAndPanicMetrics ¶
func (c *KPAMetricsClient) StableAndPanicMetrics( metricKey NamespaceNameMetric, now time.Time) (float64, float64, error)
func (*KPAMetricsClient) UpdateMetricIntoWindow ¶
func (c *KPAMetricsClient) UpdateMetricIntoWindow(now time.Time, metricValue float64) error
func (*KPAMetricsClient) UpdateMetrics ¶
func (c *KPAMetricsClient) UpdateMetrics(now time.Time, metricKey NamespaceNameMetric, metricValues ...float64) error
func (*KPAMetricsClient) UpdatePodListMetric ¶
func (c *KPAMetricsClient) UpdatePodListMetric(metricValues []float64, metricKey NamespaceNameMetric, now time.Time) error
type KubernetesMetricsFetcher ¶
type KubernetesMetricsFetcher struct {
	// contains filtered or unexported fields
}
    func NewKubernetesMetricsFetcher ¶
func NewKubernetesMetricsFetcher(resourceFetcher *ResourceMetricsFetcher, customFetcher *CustomMetricsFetcher) *KubernetesMetricsFetcher
NewKubernetesMetricsFetcher creates a new fetcher for both resource and custom metrics.
func (*KubernetesMetricsFetcher) FetchMetric ¶
func (*KubernetesMetricsFetcher) FetchPodMetrics ¶
func (f *KubernetesMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, containerPort int, metricName string, metricType MetricType) (float64, error)
type MetricClient ¶
type MetricClient interface {
	// GetPodContainerMetric gets the given resource metric (and an associated oldest timestamp)
	// for the specified named container in specific pods in the given namespace and when
	// the container is an empty string it returns the sum of all the container metrics.
	// TODO: should we use `metricKey` all the time?
	GetPodContainerMetric(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
	GetMetricsFromPods(ctx context.Context, pods []v1.Pod, source autoscalingv1alpha1.MetricSource) ([]float64, error)
	GetMetricFromSource(ctx context.Context, source autoscalingv1alpha1.MetricSource) (float64, error)
	// Obsoleted, please use UpdateMetrics
	UpdatePodListMetric(metricValues []float64, metricKey NamespaceNameMetric, now time.Time) error
	UpdateMetrics(now time.Time, metricKey NamespaceNameMetric, metricValues ...float64) error
}
    MetricClient knows how to query a remote interface to retrieve container-level resource metrics as well as pod-level arbitrary metrics
type MetricFetcher ¶
type MetricFetcher interface {
	// Obseleted: Call FetchMetric instead.
	FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)
	FetchMetric(ctx context.Context, protocol autoscalingv1alpha1.ProtocolType, endpoint, path, metricName string) (float64, error)
}
    MetricFetcher defines an interface for fetching metrics. it could be Kubernetes metrics or Pod prometheus metrics.
type MetricType ¶
type MetricType string
MetricType defines the type of metrics to be fetched.
const ( ResourceMetrics MetricType = "resource" CustomMetrics MetricType = "custom" RawMetrics MetricType = "raw" )
type NamespaceNameMetric ¶
type NamespaceNameMetric struct {
	types.NamespacedName // target deployment namespace and name
	MetricName           string
	PaNamespace          string
	PaName               string
}
    NamespaceNameMetric contains the namespace, name and the metric name
func NewNamespaceNameMetric ¶
func NewNamespaceNameMetric(pa *autoscalingv1alpha1.PodAutoscaler) (NamespaceNameMetric, autoscalingv1alpha1.MetricSource, error)
NewNamespaceNameMetric creates a NamespaceNameMetric based on the PodAutoscaler's metrics source. For consistency, it will return the corresponding MetricSource. Currently, it supports only a single metric source. In the future, this could be extended to handle multiple metric sources.
type PodMetric ¶
type PodMetric struct {
	Timestamp time.Time
	// kubernetes metrics return this value.
	Window      time.Duration
	Value       int64
	MetricsName string
	ScaleObjectName string
	// contains filtered or unexported fields
}
    PodMetric contains pod metric value (the metric values are expected to be the metric as a milli-value)
type PodMetricsInfo ¶
PodMetricsInfo contains pod metrics as a map from pod names to PodMetricsInfo
func GetPodContainerMetric ¶
func GetPodContainerMetric(ctx context.Context, fetcher MetricFetcher, pod corev1.Pod, source autoscalingv1alpha1.MetricSource) (PodMetricsInfo, time.Time, error)
type ResourceMetricsFetcher ¶
type ResourceMetricsFetcher struct {
	// contains filtered or unexported fields
}
    ResourceMetricsFetcher fetches resource metrics from Kubernetes metrics API (metrics.k8s.io).
func NewResourceMetricsFetcher ¶
func NewResourceMetricsFetcher(metricsClient *versioned.Clientset) *ResourceMetricsFetcher
func (*ResourceMetricsFetcher) FetchMetric ¶
func (*ResourceMetricsFetcher) FetchPodMetrics ¶
type RestMetricsFetcher ¶
type RestMetricsFetcher struct {
	// contains filtered or unexported fields
}
    RestMetricsFetcher implements MetricFetcher to fetch metrics from Pod's /metrics endpoint.
func NewRestMetricsFetcher ¶
func NewRestMetricsFetcher() *RestMetricsFetcher
func (*RestMetricsFetcher) FetchMetric ¶
func (f *RestMetricsFetcher) FetchMetric(ctx context.Context, protocol autoscalingv1alpha1.ProtocolType, endpoint, path, metricName string) (float64, error)
func (*RestMetricsFetcher) FetchPodMetrics ¶
func (f *RestMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)