Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
If the global TTL is greater than the min suggested by the plugin us it
  • Loading branch information
jcooklin committed Dec 20, 2015
1 parent 4d5a73e commit ef1d575
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion control/available_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion plugin/collector/snap-collector-mock2/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef1d575

Please sign in to comment.