Skip to content

Commit

Permalink
Fix fluentd plugin when kubernetes labels were missing (#3358)
Browse files Browse the repository at this point in the history
When kubernetes labels were missing in the received data, plugin failed
with error "undefined method `each_key' for nil:NilClass".
  • Loading branch information
fpob authored Mar 3, 2021
1 parent 6ea7122 commit 8c98ee2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/fluentd/lib/fluent/plugin/out_loki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,11 @@ def line_to_loki(record)

if @extract_kubernetes_labels && record.key?('kubernetes')
kubernetes_labels = record['kubernetes']['labels']
kubernetes_labels.each_key do |l|
new_key = l.gsub(%r{[.\-\/]}, '_')
chunk_labels[new_key] = kubernetes_labels[l]
if !kubernetes_labels.nil?
kubernetes_labels.each_key do |l|
new_key = l.gsub(%r{[.\-\/]}, '_')
chunk_labels[new_key] = kubernetes_labels[l]
end
end
end

Expand Down

0 comments on commit 8c98ee2

Please sign in to comment.