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
No known key found for this signature in database
GPG Key ID: 50AD98B2A0D8D4EF
3 changed files with 28 additions and 16 deletions

View File

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

View File

@ -247,13 +247,19 @@ func ParseHPAMetrics(hpa *autoscalingv2.HorizontalPodAutoscaler) ([]*MetricConfi
}
if metric.Type == autoscalingv2.ExternalMetricSourceType &&
metric.External.Metric.Selector != nil &&
metric.External.Metric.Selector.MatchLabels != nil {
metric.External.Metric.Selector != nil {
for k, v := range metric.External.Metric.Selector.MatchLabels {
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)
if present {
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.
func (c *SkipperCollectorPlugin) NewCollector(hpa *autoscalingv2.HorizontalPodAutoscaler, config *MetricConfig, interval time.Duration) (Collector, error) {
if strings.HasPrefix(config.Metric.Name, rpsMetricName) {
backend := ""
if len(config.Metric.Name) > len(rpsMetricName) {
metricNameParts := strings.Split(config.Metric.Name, rpsMetricBackendSeparator)
if len(metricNameParts) == 2 {
backend = metricNameParts[1]
backend, ok := config.Config["backend"]
if !ok {
if len(config.Metric.Name) > len(rpsMetricName) {
metricNameParts := strings.Split(config.Metric.Name, rpsMetricBackendSeparator)
if len(metricNameParts) == 2 {
backend = metricNameParts[1]
}
}
}
return NewSkipperCollector(c.client, c.rgClient, c.plugin, hpa, config, interval, c.backendAnnotations, backend)