Class: Fluent::Plugin::SwarmMetadataFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_swarm_metadata.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_metadata(container_id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/fluent/plugin/filter_swarm_metadata.rb', line 28

def self.(container_id)
  begin
    Docker::Container.get(container_id).info
  rescue Docker::Error::NotFoundError
    nil
  end
end

Instance Method Details

#configure(conf) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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]
     = @cache.getset(container_id){SwarmMetadataFilter.(container_id)}

    record['swarm_namespace'] = ['Config']['Labels']['com.docker.stack.namespace'] || @fallback_key
    record['swarm_service_name'] = ['Config']['Labels']['com.docker.swarm.service.name'] || @fallback_key
    record['swarm_task_name'] = ['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