Documentation ¶
Overview ¶
Package k8shorizmetrics provides a simplified interface for gathering metrics and calculating replicas in the same way that the Horizontal Pod Autoscaler (HPA) does. This is split into two parts, gathering metrics, and evaluating metrics (calculating replicas). You can use these parts separately, or together to create a full evaluation process in the same way the HPA does.
Index ¶
- type Evaluator
- func (e *Evaluator) Evaluate(gatheredMetrics []*metrics.Metric, currentReplicas int32) (int32, error)
- func (e *Evaluator) EvaluateSingleMetric(gatheredMetric *metrics.Metric, currentReplicas int32) (int32, error)
- func (e *Evaluator) EvaluateSingleMetricWithOptions(gatheredMetric *metrics.Metric, currentReplicas int32, tolerance float64) (int32, error)
- func (e *Evaluator) EvaluateWithOptions(gatheredMetrics []*metrics.Metric, currentReplicas int32, tolerance float64) (int32, error)
- type EvaluatorMultiMetricError
- type ExternalEvaluater
- type ExternalGatherer
- type Gatherer
- func (c *Gatherer) Gather(specs []autoscalingv2.MetricSpec, namespace string, ...) ([]*metrics.Metric, error)
- func (c *Gatherer) GatherSingleMetric(spec autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector) (*metrics.Metric, error)
- func (c *Gatherer) GatherSingleMetricWithOptions(spec autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector, ...) (*metrics.Metric, error)
- func (c *Gatherer) GatherWithOptions(specs []autoscalingv2.MetricSpec, namespace string, ...) ([]*metrics.Metric, error)
- type GathererMultiMetricError
- type ObjectEvaluater
- type ObjectGatherer
- type PodsEvaluater
- type PodsGatherer
- type ResourceEvaluater
- type ResourceGatherer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evaluator ¶
type Evaluator struct { External ExternalEvaluater Object ObjectEvaluater Pods PodsEvaluater Resource ResourceEvaluater Tolerance float64 }
Evaluator provides functionality for deciding how many replicas a resource should have based on provided metrics.
func NewEvaluator ¶
NewEvaluator sets up an evaluate that can process external, object, pod and resource metrics
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(gatheredMetrics []*metrics.Metric, currentReplicas int32) (int32, error)
Evaluate returns the target replica count for an array of multiple metrics If an error occurs evaluating any metric this will return a EvaluatorMultiMetricError. If a partial error occurs, meaning some metrics were evaluated successfully and others failed, the 'Partial' property of this error will be set to true.
func (*Evaluator) EvaluateSingleMetric ¶
func (e *Evaluator) EvaluateSingleMetric(gatheredMetric *metrics.Metric, currentReplicas int32) (int32, error)
EvaluateSingleMetric returns the target replica count for a single metrics
func (*Evaluator) EvaluateSingleMetricWithOptions ¶
func (e *Evaluator) EvaluateSingleMetricWithOptions(gatheredMetric *metrics.Metric, currentReplicas int32, tolerance float64) (int32, error)
EvaluateSingleMetricWithOptions returns the target replica count for a single metrics with provided options
func (*Evaluator) EvaluateWithOptions ¶
func (e *Evaluator) EvaluateWithOptions(gatheredMetrics []*metrics.Metric, currentReplicas int32, tolerance float64) (int32, error)
EvaluateWithOptions returns the target replica count for an array of multiple metrics with provided options If an error occurs evaluating any metric this will return a EvaluatorMultiMetricError. If a partial error occurs, meaning some metrics were evaluated successfully and others failed, the 'Partial' property of this error will be set to true.
type EvaluatorMultiMetricError ¶
EvaluatorMultiMetricError occurs when evaluating multiple metrics, if any metric fails to be evaluated this error will be returned which contains all of the individual errors in the 'Errors' slice, if some metrics were evaluated successfully the error will have the 'Partial' property set to true.
func (*EvaluatorMultiMetricError) Error ¶
func (e *EvaluatorMultiMetricError) Error() string
type ExternalEvaluater ¶
type ExternalEvaluater interface {
Evaluate(currentReplicas int32, gatheredMetric *metrics.Metric, tolerance float64) (int32, error)
}
ExternalEvaluater produces a replica count based on an external metric provided
type ExternalGatherer ¶
type ExternalGatherer interface { Gather(metricName, namespace string, metricSelector *metav1.LabelSelector, podSelector labels.Selector) (*externalmetrics.Metric, error) GatherPerPod(metricName, namespace string, metricSelector *metav1.LabelSelector) (*externalmetrics.Metric, error) }
ExternalGatherer allows retrieval of external metrics.
type Gatherer ¶
type Gatherer struct { Resource ResourceGatherer Pods PodsGatherer Object ObjectGatherer External ExternalGatherer ScaleClient k8sscale.ScalesGetter CPUInitializationPeriod time.Duration DelayOfInitialReadinessStatus time.Duration }
Gatherer provides functionality for retrieving metrics on supplied metric specs.
func NewGatherer ¶
func NewGatherer( metricsclient metricsclient.Client, podlister corelisters.PodLister, cpuInitializationPeriod time.Duration, delayOfInitialReadinessStatus time.Duration) *Gatherer
NewGatherer sets up a new Metric Gatherer
func (*Gatherer) Gather ¶
func (c *Gatherer) Gather(specs []autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector) ([]*metrics.Metric, error)
Gather returns all of the metrics gathered based on the metric specs provided. If an error occurs gathering any metric this will return a GatherMultiMetricError. If a partial error occurs, meaning some metrics were gathered successfully and others failed, the 'Partial' property of this error will be set to true.
func (*Gatherer) GatherSingleMetric ¶
func (c *Gatherer) GatherSingleMetric(spec autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector) (*metrics.Metric, error)
GatherSingleMetric returns the metric gathered based on a single metric spec.
func (*Gatherer) GatherSingleMetricWithOptions ¶
func (c *Gatherer) GatherSingleMetricWithOptions(spec autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector, cpuInitializationPeriod time.Duration, delayOfInitialReadinessStatus time.Duration) (*metrics.Metric, error)
GatherSingleMetricWithOptions returns the metric gathered based on a single metric spec with options.
func (*Gatherer) GatherWithOptions ¶
func (c *Gatherer) GatherWithOptions(specs []autoscalingv2.MetricSpec, namespace string, podSelector labels.Selector, cpuInitializationPeriod time.Duration, delayOfInitialReadinessStatus time.Duration) ([]*metrics.Metric, error)
GatherWithOptions returns all of the metrics gathered based on the metric specs provided with options. If an error occurs gathering any metric this will return a GatherMultiMetricError. If a partial error occurs, meaning some metrics were gathered successfully and others failed, the 'Partial' property of this error will be set to true.
type GathererMultiMetricError ¶
GathererMultiMetricError occurs when gathering multiple metrics, if any metric fails to be gathered this error will be returned which contains all of the individual errors in the 'Errors' slice, if some metrics were gathered successfully the error will have the 'Partial' property set to true.
func (*GathererMultiMetricError) Error ¶
func (e *GathererMultiMetricError) Error() string
type ObjectEvaluater ¶
type ObjectEvaluater interface {
Evaluate(currentReplicas int32, gatheredMetric *metrics.Metric, tolerance float64) (int32, error)
}
ObjectEvaluater produces a replica count based on an object metric provided
type ObjectGatherer ¶
type ObjectGatherer interface { Gather(metricName string, namespace string, objectRef *autoscalingv2.CrossVersionObjectReference, podSelector labels.Selector, metricSelector labels.Selector) (*objectmetrics.Metric, error) GatherPerPod(metricName string, namespace string, objectRef *autoscalingv2.CrossVersionObjectReference, metricSelector labels.Selector) (*objectmetrics.Metric, error) }
ObjectGatherer allows retrieval of object metrics.
type PodsEvaluater ¶
type PodsEvaluater interface {
Evaluate(currentReplicas int32, gatheredMetric *metrics.Metric) int32
}
PodsEvaluater produces a replica count based on a pods metric provided
type PodsGatherer ¶
type PodsGatherer interface {
Gather(metricName string, namespace string, podSelector labels.Selector, metricSelector labels.Selector) (*podsmetrics.Metric, error)
}
PodsGatherer allows retrieval of pods metrics.
type ResourceEvaluater ¶
type ResourceEvaluater interface {
Evaluate(currentReplicas int32, gatheredMetric *metrics.Metric, tolerance float64) (int32, error)
}
ResourceEvaluater produces an evaluation based on a resource metric provided
type ResourceGatherer ¶
type ResourceGatherer interface { Gather(resourceName corev1.ResourceName, namespace string, podSelector labels.Selector, cpuInitializationPeriod time.Duration, delayOfInitialReadinessStatus time.Duration) (*resourcemetrics.Metric, error) GatherRaw(resourceName corev1.ResourceName, namespace string, podSelector labels.Selector, cpuInitializationPeriod time.Duration, delayOfInitialReadinessStatus time.Duration) (*resourcemetrics.Metric, error) }
ResourceGatherer allows retrieval of resource metrics.
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
external
Package external provides utilities for gathering and evaluating external metrics
|
Package external provides utilities for gathering and evaluating external metrics |
fake
Package fake provides stubs for testing.
|
Package fake provides stubs for testing. |
object
Package object provides utilities for gathering and evaluating object metrics
|
Package object provides utilities for gathering and evaluating object metrics |
pods
Package pods provides utilities for gathering and evaluating pods metrics
|
Package pods provides utilities for gathering and evaluating pods metrics |
podutil
Package podutil provides utilities for getting pod information from the K8s APIs.
|
Package podutil provides utilities for getting pod information from the K8s APIs. |
replicas
Package replicas provides utilities for getting replica counts from the K8s APIs.
|
Package replicas provides utilities for getting replica counts from the K8s APIs. |
resource
Package resource provides utilities for gathering and evaluating resource metrics
|
Package resource provides utilities for gathering and evaluating resource metrics |
resourceclient
Package resourceclient provides utilities for retrieving arbitrary K8s resources from the APIs.
|
Package resourceclient provides utilities for retrieving arbitrary K8s resources from the APIs. |
testutil
Package testutil provides test utilities.
|
Package testutil provides test utilities. |
Package metrics provides models for all of the metrics returned from the K8s APIs grouped into a single model.
|
Package metrics provides models for all of the metrics returned from the K8s APIs grouped into a single model. |
external
Package external contains models for external metrics as returned by the K8s metrics APIs.
|
Package external contains models for external metrics as returned by the K8s metrics APIs. |
object
Package object contains models for object metrics as returned by the K8s metrics APIs.
|
Package object contains models for object metrics as returned by the K8s metrics APIs. |
podmetrics
Package podmetrics contains models for an individual pod's metrics as returned by the K8s metrics APIs.
|
Package podmetrics contains models for an individual pod's metrics as returned by the K8s metrics APIs. |
pods
Package pods contains models for metrics relating to a set of pods as returned by the K8s metrics APIs.
|
Package pods contains models for metrics relating to a set of pods as returned by the K8s metrics APIs. |
resource
Package resource contains models for resource metrics as returned by the K8s metrics APIs.
|
Package resource contains models for resource metrics as returned by the K8s metrics APIs. |
value
Package value contains models for how K8s metric values are actually defined.
|
Package value contains models for how K8s metric values are actually defined. |
Package metricsclient provides a standard and easily instantiated way of querying metrics from the K8s APIs.
|
Package metricsclient provides a standard and easily instantiated way of querying metrics from the K8s APIs. |
Package podsclient provides an on-demand client for retrieving pods, without using caching, as the HorizontalPodAutoscaler does.
|
Package podsclient provides an on-demand client for retrieving pods, without using caching, as the HorizontalPodAutoscaler does. |