diff --git a/pkg/util/kubernetes/autoscalers/datadogexternal.go b/pkg/util/kubernetes/autoscalers/datadogexternal.go index 61bbe1993bf70..c00e8d59ad79e 100644 --- a/pkg/util/kubernetes/autoscalers/datadogexternal.go +++ b/pkg/util/kubernetes/autoscalers/datadogexternal.go @@ -197,7 +197,7 @@ func (p *Processor) queryDatadogExternal(ddQueries []string, timeWindow time.Dur newVal, err := strconv.Atoi(queryLimits.Remaining) if err == nil { getMinRemainingRequestsTracker().update(newVal) - rateLimitsRemainingMin.Set(float64(minRemainingRequestsTracker.val), queryEndpoint, le.JoinLeaderLabel) + rateLimitsRemainingMin.Set(float64(minRemainingRequestsTracker.get()), queryEndpoint, le.JoinLeaderLabel) } return processedMetrics, nil diff --git a/pkg/util/kubernetes/autoscalers/datadogexternal_util.go b/pkg/util/kubernetes/autoscalers/datadogexternal_util.go index 8aec3ec874862..fbfb06197d73c 100644 --- a/pkg/util/kubernetes/autoscalers/datadogexternal_util.go +++ b/pkg/util/kubernetes/autoscalers/datadogexternal_util.go @@ -39,3 +39,7 @@ func (mt *minTracker) update(newVal int) { mt.timestamp = time.Now() } } + +func (mt *minTracker) get() int { + return mt.val +} diff --git a/pkg/util/kubernetes/autoscalers/datadogexternal_util_test.go b/pkg/util/kubernetes/autoscalers/datadogexternal_util_test.go index b4c9374067c95..e9781496bf39a 100644 --- a/pkg/util/kubernetes/autoscalers/datadogexternal_util_test.go +++ b/pkg/util/kubernetes/autoscalers/datadogexternal_util_test.go @@ -14,34 +14,34 @@ import ( "github.com/stretchr/testify/assert" ) -func TestUpdateMinimumRemainingRequests(t *testing.T) { +func TestUpdateMinTracker(t *testing.T) { expiryDuration := 60 * time.Second - mrr := newMinTracker(expiryDuration) + mt := newMinTracker(expiryDuration) // Should update - mrr.update(10) - assert.Equal(t, mrr.val, 10) + mt.update(10) + assert.Equal(t, mt.get(), 10) // Should not update, since value didn't expire yet - mrr.update(11) - assert.Equal(t, mrr.val, 10) + mt.update(11) + assert.Equal(t, mt.get(), 10) // simulate waiting half the expirationDuration - mrr.timestamp = time.Now().Add(-expiryDuration / 2) + mt.timestamp = time.Now().Add(-expiryDuration / 2) // Should not update - mrr.update(199) - assert.Equal(t, mrr.val, 10) + mt.update(199) + assert.Equal(t, mt.get(), 10) // Shoud update, even if value didn't expire because new value is lower - mrr.update(5) - assert.Equal(t, mrr.val, 5) + mt.update(5) + assert.Equal(t, mt.get(), 5) // Change timestamp to simulate expiration - mrr.timestamp = time.Now().Add(-2 * expiryDuration) + mt.timestamp = time.Now().Add(-2 * expiryDuration) // Shoud update because current value has expired - mrr.update(100) - assert.Equal(t, mrr.val, 100) + mt.update(100) + assert.Equal(t, mt.get(), 100) }