lib/fluent/plugin/out_kubernetes.rb in fluent-plugin-kubernetes-0.2.4 vs lib/fluent/plugin/out_kubernetes.rb in fluent-plugin-kubernetes-0.3.0

- old
+ new

@@ -31,10 +31,11 @@ def configure(conf) super require 'docker' + require 'json' end def emit(tag, es, chain) es.each do |time,record| Fluent::Engine.emit('kubernetes', @@ -53,10 +54,21 @@ str.gsub(/\$\{tag_parts\[(\d+)\]\}/) { |m| tag_parts[$1.to_i] } end def enrich_record(tag, record) if @container_id + log = record['log'].strip + if log[0].eql?('{') && log[-1].eql?('}') + begin + parsed_log = JSON.parse(log) + record = record.merge(parsed_log) + unless parsed_log.has_key?('log') + record.delete('log') + end + rescue JSON::ParserError + end + end id = interpolate(tag, @container_id) record['container_id'] = id container = Docker::Container.get(id) if container container_name = container.json['Name'] @@ -75,6 +87,6 @@ end end record end -end \ No newline at end of file +end