Making TTL configurable, at least globally

Making metrics expiration TTL configurable globally configurable.
This is so RemoveExpired can be tested. Not making the TTL configurable
per metric yet because it could change behaviour in production.

Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
This commit is contained in:
Muhammad Muaaz Saleem
2018-11-20 10:34:44 +01:00
parent 49cdca4c68
commit b1745c5eed
2 changed files with 15 additions and 10 deletions

View File

@ -208,8 +208,10 @@ func TestExternalMetricStorage(t *testing.T) {
func TestMetricsExpiration(t *testing.T) {
metricStore := NewMetricStore()
oldTime := v1.Time{Time: time.Now().UTC().Add(time.Hour * -1)}
// Override global TTL to test expiration
metricsTTL = func() time.Time {
return time.Now().UTC().Add(time.Hour * -1)
}
customMetric := collector.CollectedMetric{
Type: v2beta1.MetricSourceType("Object"),
@ -221,20 +223,19 @@ func TestMetricsExpiration(t *testing.T) {
Kind: "Node",
APIVersion: "core/v1",
},
Timestamp: oldTime,
Timestamp: v1.Time{Time: metricsTTL()},
},
}
externalMetric := collector.CollectedMetric {
externalMetric := collector.CollectedMetric{
Type: v2beta1.MetricSourceType("External"),
External: external_metrics.ExternalMetricValue{
MetricName: "metric-per-unit",
Value: *resource.NewQuantity(0, ""),
Timestamp: oldTime,
Timestamp: v1.Time{Time: metricsTTL()},
},
}
metricStore.Insert(customMetric)
metricStore.Insert(externalMetric)
metricStore.RemoveExpired()