mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 19:16:06 +00:00
Use labels for specifying Ingress/RouteGroup backend
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:
parent
c618494177
commit
190f0db092
22
README.md
22
README.md
@ -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
|
||||
|
@ -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
|
||||
|
@ -51,13 +51,15 @@ 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 := ""
|
||||
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)
|
||||
}
|
||||
return nil, fmt.Errorf("metric '%s' not supported", config.Metric.Name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user