Sha256: c660fdb67d6a82de0e4df44871ac8c55a29567cae74d98b9e71c3bae5fad16a9

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'fluent/output'

module Fluent
  class Fluent::AppendKubernetesAnnotationsToTag < Fluent::Output
    Fluent::Plugin.register_output('append_kubernetes_annotations_to_tag', self)

    config_param :annotations, :string

    def configure(conf)
      super

      @annotations = conf['annotations'].split(',')
    end

    def emit(tag, es, chain)
      es.each do |time, record|
        events(tag, time, record).each do |(tag, time, record)|
          router.emit(tag, time, record)
        end
      end

      chain.next

    rescue
      log.error "Failed to re-format docker record #{tag}"
      # this seems to be a way to safely swallow records we don't know how to format
      ""
    end

    private

    def events(tag, time, record)
      [
        event(tag, time, record)
      ]
    end

    def event(tag, time, record)
      new_tag = if record.has_key?('kubernetes') && record['kubernetes'].has_key?('annotations')
                  kubernetes_annotations_tag_appender.append(tag,
                                                             record['kubernetes']['annotations'],
                                                             record['kubernetes']['container_name'])
      else
        tag
      end

      [
        new_tag,
        time,
        record
      ]
    end

    def kubernetes_annotations_tag_appender
      @kubernetes_annotations_tag_appender ||= KubernetesAnnotationsTagAppender.new(@annotations)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-append-kubernetes-annotations-to-tag-0.1.0.pre.3 lib/fluent/plugin/out_append_kubernetes_annotations_to_tag.rb