Skip to content

Commit

Permalink
Fix issue with external metrics when several HPAs use the same query (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vboulineau authored Sep 18, 2020
1 parent 1e0070a commit 4cc3772
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/util/kubernetes/autoscalers/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ func (p *Processor) UpdateExternalMetrics(emList map[string]custommetrics.Extern
var err error
updated = make(map[string]custommetrics.ExternalMetricValue)

batch := []string{}
uniqueQueries := make(map[string]struct{}, len(emList))
batch := make([]string, 0, len(emList))
for _, e := range emList {
q := getKey(e.MetricName, e.Labels, aggregator, rollup)
batch = append(batch, q)
if _, found := uniqueQueries[q]; !found {
uniqueQueries[q] = struct{}{}
batch = append(batch, q)
}
}

metrics, err := p.QueryExternalMetric(batch)
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/kubernetes/autoscalers/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ func TestProcessor_UpdateExternalMetrics(t *testing.T) {
},
},
},
{
"perform unique from list of input externalMetrics",
map[string]custommetrics.ExternalMetricValue{
"id1": {
MetricName: metricName,
Labels: map[string]string{"foo": "bar"},
Valid: false,
},
"id2": {
MetricName: metricName,
Labels: map[string]string{"foo": "bar"},
Valid: false,
},
},
[]datadog.Series{
{
Metric: &metricName,
Points: []datadog.DataPoint{
makePoints(1531492452000, 12),
makePoints(penTime, 14), // Force the penultimate point to be considered fresh at all time(< externalMaxAge)
makePoints(0, 27),
},
Scope: makePtr("foo:bar"),
},
},
map[string]custommetrics.ExternalMetricValue{
"id1": {
MetricName: "requests_per_s",
Labels: map[string]string{"foo": "bar"},
Value: 14,
Valid: true,
},
"id2": {
MetricName: "requests_per_s",
Labels: map[string]string{"foo": "bar"},
Value: 14,
Valid: true,
},
},
},
{
"do not update valid sparse metric",
map[string]custommetrics.ExternalMetricValue{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fix issue in Cluster Agent when using external metrics without DatadogMetrics where multiple HPAs using the same metricName + Labels would prevent all HPAs (except 1st one) to get values from Datadog

0 comments on commit 4cc3772

Please sign in to comment.