Class: Fluent::Plugin::FirelensTagFilterOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_firelens_tag_filter.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



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

def configure(conf)
  super
  @tag_format = @tag.gsub(/%/, '%%').gsub(/\$\{(.*?)\}/, '%{\1}')
  log.debug("tag_format #{@tag_format}")
end

#process(tag, es) ⇒ Object

rewrite message tag from: [containerName]-firelens- to: [tag_prefix]..(stdout|stderr).



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_firelens_tag_filter.rb', line 39

def process(tag, es)
  matched = tag.match(/^(.*?)-firelens-(.*)/)
  if !matched
    log.warn("unexpected tag #{tag}")
    router.emit_stream(@tag_prefix + "." + tag, es)
    return
  end
  v = {
    tag_prefix: @tag_prefix,
    container_name: matched[1],
    task_id: matched[2],
  }
  es.each do |time, record|
    v[:source] = record['source'] || 'unknown'
    router.emit(
      sprintf(@tag_format, v),
      time,
      record,
    )
  end
end