Module: KubernetesMetadata::CacheStrategy
- Included in:
- Fluent::Plugin::KubernetesMetadataFilter
- Defined in:
- lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb
Instance Method Summary collapse
-
#get_pod_metadata(key, namespace_name, pod_name, time, batch_miss_cache) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
Instance Method Details
#get_pod_metadata(key, namespace_name, pod_name, time, batch_miss_cache) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fluent/plugin/kubernetes_metadata_cache_strategy.rb', line 24 def (key, namespace_name, pod_name, time, batch_miss_cache) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity = {} ids = @id_cache[key] if ids.nil? @stats.bump(:id_cache_miss) if batch_miss_cache.key?("#{namespace_name}_#{pod_name}") return batch_miss_cache["#{namespace_name}_#{pod_name}"] end = (namespace_name, pod_name) if ids = { pod_id: ['pod_id'] } @id_cache[key] = ids return end = (namespace_name) ids = { pod_id: ['pod_id'], namespace_id: ['namespace_id'] } if !ids[:pod_id].nil? && !ids[:namespace_id].nil? # pod found and namespace found = .merge() else if ids[:pod_id].nil? && !ids[:namespace_id].nil? # rubocop:disable Style/IfInsideElse # pod not found, but namespace found @stats.bump(:id_cache_pod_not_found_namespace) ns_time = Time.parse(['creation_timestamp']) if ns_time <= Time.at(time.to_f) # rubocop:disable Metrics/BlockNesting # namespace is older then record for pod ids[:pod_id] = key = @cache.fetch(ids[:pod_id]) do { 'pod_id' => ids[:pod_id] } end end = .merge() else if !ids[:pod_id].nil? && ids[:namespace_id].nil? # rubocop:disable Metrics/BlockNesting # pod found, but namespace NOT found # this should NEVER be possible since pod meta can # only be retrieved with a namespace @stats.bump(:id_cache_namespace_not_found_pod) else # nothing found @stats.bump(:id_cache_orphaned_record) end if @allow_orphans # rubocop:disable Metrics/BlockNesting log.trace("orphaning message for: #{namespace_name}/#{pod_name} ") = { 'orphaned_namespace' => namespace_name, 'namespace_name' => @orphaned_namespace_name, 'namespace_id' => @orphaned_namespace_id } else = {} end batch_miss_cache["#{namespace_name}_#{pod_name}"] = end end @id_cache[key] = ids unless batch_miss_cache.key?("#{namespace_name}_#{pod_name}") else # SLOW PATH = @cache.fetch(ids[:pod_id]) do @stats.bump(:pod_cache_miss) m = (namespace_name, pod_name) m.nil? || m.empty? ? { 'pod_id' => ids[:pod_id] } : m end = @namespace_cache.fetch(ids[:namespace_id]) do m = unless @stats.bump(:namespace_cache_miss) (namespace_name) end m.nil? || m.empty? ? { 'namespace_id' => ids[:namespace_id] } : m end = .merge() end # remove namespace info that is only used for comparison .delete('creation_timestamp') .delete_if { |_k, v| v.nil? } end |