diff --git a/fluent-plugin-enhance-k8s-metadata/lib/fluent/plugin/filter_enhance_k8s_metadata.rb b/fluent-plugin-enhance-k8s-metadata/lib/fluent/plugin/filter_enhance_k8s_metadata.rb index c3da2995..81227345 100644 --- a/fluent-plugin-enhance-k8s-metadata/lib/fluent/plugin/filter_enhance_k8s_metadata.rb +++ b/fluent-plugin-enhance-k8s-metadata/lib/fluent/plugin/filter_enhance_k8s_metadata.rb @@ -47,6 +47,7 @@ class EnhanceK8sMetadataFilter < Fluent::Plugin::Filter config_param :cache_ttl, :integer, default: 60 * 60 * 2 config_param :cache_refresh, :integer, default: 60 * 60 config_param :cache_refresh_variation, :integer, default: 60 * 15 + config_param :cache_refresh_apiserver_request_delay, :float, default: Float::NAN def configure(conf) super diff --git a/fluent-plugin-enhance-k8s-metadata/lib/sumologic/kubernetes/cache_strategy.rb b/fluent-plugin-enhance-k8s-metadata/lib/sumologic/kubernetes/cache_strategy.rb index f67fa4f9..c98afe02 100644 --- a/fluent-plugin-enhance-k8s-metadata/lib/sumologic/kubernetes/cache_strategy.rb +++ b/fluent-plugin-enhance-k8s-metadata/lib/sumologic/kubernetes/cache_strategy.rb @@ -27,6 +27,10 @@ def refresh_cache entries.each { |key, _| begin refresh_cache_entry(key) + # Adding friction to avoid aggressive refresh. + if !@cache_refresh_apiserver_request_delay.nan? && !@cache_refresh_apiserver_request_delay.negative? + sleep @cache_refresh_apiserver_request_delay + end rescue => e log.error "Cannot refresh metadata for key #{key}: #{e}" end