class Fluent::Plugin::SwarmMetadataFilter

Public Class Methods

get_metadata(container_id) click to toggle source
# File lib/fluent/plugin/filter_swarm_metadata.rb, line 28
def self.get_metadata(container_id)
  begin
    Docker::Container.get(container_id).info
  rescue Docker::Error::NotFoundError
    nil
  end
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_swarm_metadata.rb, line 36
def configure(conf)
  super

  require 'docker'
  require 'lru_redux'

  Docker.url = @docker_url

  @cache = LruRedux::ThreadSafeCache.new(@cache_size)
  @container_id_regexp_compiled = Regexp.compile(@container_id_regexp)
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_swarm_metadata.rb, line 48
def filter(tag, time, record)
  container_id = tag.match(@container_id_regexp_compiled)

  if container_id && container_id[0]
    container_id = container_id[0]
    metadata = @cache.getset(container_id){SwarmMetadataFilter.get_metadata(container_id)}

    record['swarm_namespace'] = metadata['Config']['Labels']['com.docker.stack.namespace'] || @fallback_key
    record['swarm_service_name'] = metadata['Config']['Labels']['com.docker.swarm.service.name'] || @fallback_key
    record['swarm_task_name'] = metadata['Config']['Labels']['com.docker.swarm.task.name'] || @fallback_key
  else
    record['swarm_namespace'] = @fallback_key
    record['swarm_service_name'] = @fallback_key
    record['swarm_task_name'] = @fallback_key
  end
  record
end