metrics

package
v0.5.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMetrics

func CollectMetrics(ctx context.Context, spec types.CollectionSpec, factory MetricFetcherFactory) (*types.MetricSnapshot, error)

CollectMetrics gathers metrics for a scaling target using the factory pattern

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)

func ParseMetricFromBody

func ParseMetricFromBody(body []byte, metricName string) (float64, error)

Types

type AggregatorMetricsClient

type AggregatorMetricsClient interface {
	UpdateMetrics(now time.Time, metricKey types.MetricKey, metricValues ...float64) error
	GetMetricValue(metricKey types.MetricKey, now time.Time) (float64, float64, error)
	GetTrendAnalysis(metricKey types.MetricKey, now time.Time) (direction float64, velocity float64, confidence float64)
	CalculatePodAwareConfidence(metricKey types.MetricKey, podCount int, now time.Time) float64
}

AggregatorMetricsClient interface defines what aggregators need from metrics storage This interface should be consumed by aggregators but defined where it's implemented

type CustomMetricsFetcher

type CustomMetricsFetcher struct {
	// contains filtered or unexported fields
}

CustomMetricsFetcher handles Kubernetes custom metrics

func (*CustomMetricsFetcher) FetchPodMetrics

func (f *CustomMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)

type DefaultMetricFetcherFactory

type DefaultMetricFetcherFactory struct {
	// contains filtered or unexported fields
}

DefaultMetricFetcherFactory implements MetricFetcherFactory with all fetcher types

func NewDefaultMetricFetcherFactory

func NewDefaultMetricFetcherFactory(
	resourceClient *versioned.Clientset,
	customClient custom_metrics.CustomMetricsClient,
) *DefaultMetricFetcherFactory

NewDefaultMetricFetcherFactory creates a factory with all fetcher types

func (*DefaultMetricFetcherFactory) For

For returns the appropriate fetcher for the given metric source type

type ExternalMetricsFetcher

type ExternalMetricsFetcher struct {
	// contains filtered or unexported fields
}

ExternalMetricsFetcher handles external metrics with per-pod adaptation

func NewExternalMetricsFetcher

func NewExternalMetricsFetcher() *ExternalMetricsFetcher

func (*ExternalMetricsFetcher) FetchPodMetrics

func (f *ExternalMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)

type MetricFetcher

type MetricFetcher interface {
	// FetchPodMetrics fetches a metric value for a specific pod based on MetricSourceType:
	// - POD: Direct HTTP connection to pod (http://pod_ip:port/path)
	// - RESOURCE: Kubernetes resource metrics API (cpu, memory)
	// - CUSTOM: Kubernetes custom metrics API
	// - EXTERNAL: External services, adapted to per-pod semantics
	FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)
}

MetricFetcher defines a unified interface for fetching metrics. All metrics are fetched per-pod to maintain uniform upper layer logic. External metrics are adapted to appear as per-pod values.

type MetricFetcherFactory

type MetricFetcherFactory interface {
	// For returns the appropriate fetcher for the given metric source
	For(source autoscalingv1alpha1.MetricSource) MetricFetcher
}

MetricFetcherFactory provides a clean way to get the right fetcher for each metric source type

type MetricsClient

type MetricsClient struct {
	// contains filtered or unexported fields
}

MetricsClient provides metric data storage (windows and history) for all scaling strategies It does NOT fetch metrics - fetching is done separately via MetricFetcherFactory IMPORTANT: This client is shared across multiple PodAutoscalers, so we need proper isolation

func NewMetricsClient

func NewMetricsClient(granularity time.Duration) *MetricsClient

NewMetricsClient creates a new metrics client for storing metric windows and history

func (*MetricsClient) CalculatePodAwareConfidence

func (c *MetricsClient) CalculatePodAwareConfidence(metricKey types.MetricKey, podCount int, now time.Time) float64

CalculatePodAwareConfidence combines pod count with statistical confidence (stubbed - returns 0)

func (*MetricsClient) GetEnhancedStats

func (c *MetricsClient) GetEnhancedStats(metricKey types.MetricKey, now time.Time) (windowStats, historyStats types.WindowStats, err error)

GetEnhancedStats returns both window and historical statistics for a specific metricKey

func (*MetricsClient) GetMetricValue

func (c *MetricsClient) GetMetricValue(metricKey types.MetricKey, now time.Time) (float64, float64, error)

GetMetricValue returns the metric value from the stable window for a specific metricKey Both KPA and APA use the stable window (APA doesn't use panic window)

func (*MetricsClient) GetTrendAnalysis

func (c *MetricsClient) GetTrendAnalysis(metricKey types.MetricKey, now time.Time) (direction float64, velocity float64, confidence float64)

GetTrendAnalysis calculates trend direction and velocity (stubbed - returns zeros)

func (*MetricsClient) GetUnifiedStats

func (c *MetricsClient) GetUnifiedStats(metricKey types.MetricKey, now time.Time) (stableStats, panicStats types.WindowStats, err error)

GetUnifiedStats returns stats for both stable and panic windows for a specific metricKey

func (*MetricsClient) UpdateMetrics

func (c *MetricsClient) UpdateMetrics(now time.Time, metricKey types.MetricKey, metricValues ...float64) error

UpdateMetrics records metrics to all configured windows for the given metricKey

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

type PodMetricsInfo map[string]PodMetric

PodMetricsInfo contains pod metrics as a map from pod names to PodMetricsInfo

type ResourceMetricsFetcher

type ResourceMetricsFetcher struct {
	// contains filtered or unexported fields
}

ResourceMetricsFetcher handles Kubernetes resource metrics (cpu, memory)

func NewResourceMetricsFetcher

func NewResourceMetricsFetcher(metricsClient *versioned.Clientset) *ResourceMetricsFetcher

func (*ResourceMetricsFetcher) FetchPodMetrics

func (f *ResourceMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)

type RestMetricsFetcher

type RestMetricsFetcher struct {
	// contains filtered or unexported fields
}

RestMetricsFetcher implements MetricFetcher for POD type metrics (HTTP connections to pods)

func NewRestMetricsFetcher

func NewRestMetricsFetcher() *RestMetricsFetcher

func NewRestMetricsFetcherWithConfig

func NewRestMetricsFetcherWithConfig(config metrics.EngineMetricsFetcherConfig) *RestMetricsFetcher

NewRestMetricsFetcherWithConfig creates a RestMetricsFetcher with custom configuration

func (*RestMetricsFetcher) FetchPodMetrics

func (f *RestMetricsFetcher) FetchPodMetrics(ctx context.Context, pod v1.Pod, source autoscalingv1alpha1.MetricSource) (float64, error)

Jump to

Keyboard shortcuts

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