mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-05-19 11:38:13 +00:00
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:
@ -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()
|
||||
|
Reference in New Issue
Block a user