mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 11:06:04 +00:00
Handle 0 values in max collector and unknown metric type
This commit is contained in:
parent
37003d6513
commit
417f650caa
@ -24,7 +24,7 @@ func NewWeightedMaxCollector(interval time.Duration, weight float64, collectors
|
||||
|
||||
// GetMetrics gets metrics from all collectors and return the higest value.
|
||||
func (c *WeightedMaxCollector) GetMetrics() ([]CollectedMetric, error) {
|
||||
var max CollectedMetric
|
||||
var max *CollectedMetric
|
||||
for _, collector := range c.collectors {
|
||||
values, err := collector.GetMetrics()
|
||||
if err != nil {
|
||||
@ -32,14 +32,19 @@ func (c *WeightedMaxCollector) GetMetrics() ([]CollectedMetric, error) {
|
||||
}
|
||||
|
||||
for _, value := range values {
|
||||
if max != nil {
|
||||
if value.Custom.Value.MilliValue() > max.Custom.Value.MilliValue() {
|
||||
max = value
|
||||
max = &value
|
||||
}
|
||||
} else {
|
||||
max = &value
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
max.Custom.Value = *resource.NewMilliQuantity(int64(float64(max.Custom.Value.MilliValue())*c.weight), resource.DecimalSI)
|
||||
return []CollectedMetric{max}, nil
|
||||
|
||||
return []CollectedMetric{*max}, nil
|
||||
}
|
||||
|
||||
// Interval returns the interval at which the collector should run.
|
||||
|
@ -103,7 +103,10 @@ func (c *SkipperCollector) getCollector() (Collector, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
backendWeight := getMaxWeights(ingress.Annotations, c.config.MetricLabels.MatchLabels[hostLabel])
|
||||
backendWeight := 1.0
|
||||
if c.config.MetricLabels != nil {
|
||||
backendWeight = getMaxWeights(ingress.Annotations, c.config.MetricLabels.MatchLabels[hostLabel])
|
||||
}
|
||||
|
||||
config := c.config
|
||||
|
||||
@ -147,7 +150,6 @@ func (c *SkipperCollector) GetMetrics() ([]CollectedMetric, error) {
|
||||
if len(values) != 1 {
|
||||
return nil, fmt.Errorf("expected to only get one metric value, got %d", len(values))
|
||||
}
|
||||
|
||||
value := values[0]
|
||||
return []CollectedMetric{value}, nil
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -54,6 +55,8 @@ func (s *MetricStore) Insert(value collector.CollectedMetric) {
|
||||
s.insertCustomMetric(value.Custom, value.Labels)
|
||||
case autoscalingv2beta2.ExternalMetricSourceType:
|
||||
s.insertExternalMetric(value.External)
|
||||
default:
|
||||
logrus.Errorf("value type unknown: %v", value.Type)
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +88,7 @@ func (s *MetricStore) insertCustomMetric(value custom_metrics.MetricValue, label
|
||||
metrics, ok := s.customMetricsStore[value.Metric.Name]
|
||||
if !ok {
|
||||
s.customMetricsStore[value.Metric.Name] = map[schema.GroupResource]map[string]map[string]customMetricsStoredMetric{
|
||||
groupResource: map[string]map[string]customMetricsStoredMetric{
|
||||
groupResource: {
|
||||
value.DescribedObject.Namespace: map[string]customMetricsStoredMetric{
|
||||
value.DescribedObject.Name: metric,
|
||||
},
|
||||
@ -97,7 +100,7 @@ func (s *MetricStore) insertCustomMetric(value custom_metrics.MetricValue, label
|
||||
group, ok := metrics[groupResource]
|
||||
if !ok {
|
||||
metrics[groupResource] = map[string]map[string]customMetricsStoredMetric{
|
||||
value.DescribedObject.Namespace: map[string]customMetricsStoredMetric{
|
||||
value.DescribedObject.Namespace: {
|
||||
value.DescribedObject.Name: metric,
|
||||
},
|
||||
}
|
||||
@ -113,6 +116,7 @@ func (s *MetricStore) insertCustomMetric(value custom_metrics.MetricValue, label
|
||||
}
|
||||
|
||||
namespace[value.DescribedObject.Name] = metric
|
||||
|
||||
}
|
||||
|
||||
// insertExternalMetric inserts an external metric into the store.
|
||||
|
Loading…
x
Reference in New Issue
Block a user