From 3b03339613c5afa583032f2ae22a83a9247cc449 Mon Sep 17 00:00:00 2001 From: Joel Cooklin Date: Sun, 20 Dec 2015 13:21:05 -0800 Subject: [PATCH] Use the global TTL if it is greater than what the plugin advertises (as a minimum) Fixes #641 --- control/available_plugin.go | 3 ++- control/control_test.go | 2 ++ plugin/collector/snap-collector-mock2/mock/mock.go | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/control/available_plugin.go b/control/available_plugin.go index 3303c4f6b..492d2ff2c 100644 --- a/control/available_plugin.go +++ b/control/available_plugin.go @@ -367,7 +367,8 @@ func (p *apPool) applyPluginMeta(ap *availablePlugin) error { // Set the cache TTL cacheTTL := strategy.GlobalCacheExpiration - if ap.meta.CacheTTL != 0 { + // if the plugin exposes a default TTL that is greater the the global default use it + if ap.meta.CacheTTL != 0 && ap.meta.CacheTTL > strategy.GlobalCacheExpiration { cacheTTL = ap.meta.CacheTTL } diff --git a/control/control_test.go b/control/control_test.go index ad26ee9ae..d29e09848 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -881,6 +881,8 @@ func TestCollectDynamicMetrics(t *testing.T) { So(err, ShouldBeNil) ttl, err = pool.CacheTTL() So(err, ShouldBeNil) + // The minimum TTL advertised by the plugin is 100ms therefore the TTL for the + // pool should be the global cache expiration So(ttl, ShouldEqual, strategy.GlobalCacheExpiration) mts, errs := c.CollectMetrics([]core.Metric{m}, time.Now().Add(time.Second*1)) hits, err := pool.CacheHits(core.JoinNamespace(m.namespace), 2) diff --git a/plugin/collector/snap-collector-mock2/mock/mock.go b/plugin/collector/snap-collector-mock2/mock/mock.go index 2ed1f3463..2b1a7c0d9 100644 --- a/plugin/collector/snap-collector-mock2/mock/mock.go +++ b/plugin/collector/snap-collector-mock2/mock/mock.go @@ -110,7 +110,14 @@ func (f *Mock) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) { //Meta returns meta data for testing func Meta() *plugin.PluginMeta { - return plugin.NewPluginMeta(Name, Version, Type, []string{plugin.SnapGOBContentType}, []string{plugin.SnapGOBContentType}) + return plugin.NewPluginMeta( + Name, + Version, + Type, + []string{plugin.SnapGOBContentType}, + []string{plugin.SnapGOBContentType}, + plugin.CacheTTL(100*time.Millisecond), + ) } //Random number generator