Use labels for specifying Ingress/RouteGroup backend

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:
Mikkel Oscar Lyderik Larsen
2021-07-31 19:24:50 +02:00
parent c618494177
commit 190f0db092
3 changed files with 28 additions and 16 deletions

View File

@ -351,6 +351,9 @@ spec:
name: myapp name: myapp
metric: metric:
name: requests-per-second name: requests-per-second
selector:
matchLabels:
backend: backend1 # optional backend
target: target:
averageValue: "10" averageValue: "10"
type: AverageValue type: AverageValue
@ -382,6 +385,9 @@ spec:
name: myapp name: myapp
metric: metric:
name: requests-per-second name: requests-per-second
selector:
matchLabels:
backend: backend1 # optional backend
target: target:
averageValue: "10" averageValue: "10"
type: AverageValue type: AverageValue
@ -389,15 +395,13 @@ spec:
### Metric weighting based on backend ### Metric weighting based on backend
Skipper supports sending traffic to different backend based on annotations Skipper supports sending traffic to different backends based on annotations
present on the `Ingress` object, or weights on the RouteGroup backends. When present on the `Ingress` object, or weights on the RouteGroup backends. By
the metric name is specified without a backend as `requests-per-second` then default the number of replicas will be calculated based on the full traffic
the number of replicas will be calculated based on the full traffic served by served by that ingress/routegroup. If however only the traffic being routed to
that ingress/routegroup. If however only the traffic being routed to a a specific backend should be used then the backend name can be specified via
specific backend should be used then the backend name can be specified as a the `backend` label under `matchLabels` for the metric. The ingress annotation
metric name like `requests-per-second,backend1` which would return the where the backend weights can be obtained can be specified through the flag
requests-per-second being sent to the `backend1`. The ingress annotation where
the backend weights can be obtained can be specified through the flag
`--skipper-backends-annotation`. `--skipper-backends-annotation`.
## InfluxDB collector ## InfluxDB collector

View File

@ -247,13 +247,19 @@ func ParseHPAMetrics(hpa *autoscalingv2.HorizontalPodAutoscaler) ([]*MetricConfi
} }
if metric.Type == autoscalingv2.ExternalMetricSourceType && if metric.Type == autoscalingv2.ExternalMetricSourceType &&
metric.External.Metric.Selector != nil && metric.External.Metric.Selector != nil {
metric.External.Metric.Selector.MatchLabels != nil {
for k, v := range metric.External.Metric.Selector.MatchLabels { for k, v := range metric.External.Metric.Selector.MatchLabels {
config.Config[k] = v config.Config[k] = v
} }
} }
if metric.Type == autoscalingv2.ObjectMetricSourceType &&
metric.Object.Metric.Selector != nil {
for k, v := range metric.Object.Metric.Selector.MatchLabels {
config.Config[k] = v
}
}
annotationConfigs, present := parser.GetAnnotationConfig(typeName.Metric.Name, typeName.Type) annotationConfigs, present := parser.GetAnnotationConfig(typeName.Metric.Name, typeName.Type)
if present { if present {
config.CollectorType = annotationConfigs.CollectorType config.CollectorType = annotationConfigs.CollectorType

View File

@ -51,11 +51,13 @@ func NewSkipperCollectorPlugin(client kubernetes.Interface, rgClient rginterface
// NewCollector initializes a new skipper collector from the specified HPA. // NewCollector initializes a new skipper collector from the specified HPA.
func (c *SkipperCollectorPlugin) NewCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) { func (c *SkipperCollectorPlugin) NewCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
if strings.HasPrefix(config.Metric.Name, rpsMetricName) { if strings.HasPrefix(config.Metric.Name, rpsMetricName) {
backend := "" backend, ok := config.Config["backend"]
if len(config.Metric.Name) > len(rpsMetricName) { if !ok {
metricNameParts := strings.Split(config.Metric.Name, rpsMetricBackendSeparator) if len(config.Metric.Name) > len(rpsMetricName) {
if len(metricNameParts) == 2 { metricNameParts := strings.Split(config.Metric.Name, rpsMetricBackendSeparator)
backend = metricNameParts[1] if len(metricNameParts) == 2 {
backend = metricNameParts[1]
}
} }
} }
return NewSkipperCollector(c.client, c.rgClient, c.plugin, hpa, config, interval, c.backendAnnotations, backend) return NewSkipperCollector(c.client, c.rgClient, c.plugin, hpa, config, interval, c.backendAnnotations, backend)