Class: Fluent::Plugin::RecordsMergerOutput

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

Overview

fluentd records merger

Defined Under Namespace

Classes: PlaceholderExpander

Constant Summary collapse

PATTERN_MAX_NUM =
20

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fluent/plugin/out_records_merger.rb', line 51

def configure(conf)
  super
  # conf: {"@type"=>"records_merger", "tag"=>"merged1", "main_tag"=>"accesslog.1.main", "sub_tag1"=>"accesslog.1.sub1", "sub_tag2"=>"accesslog.1.sub2"}, []
  @tag = conf['tag'] # これも,結局 ${tag} とかを有効にする関係で使わなくなりそう.
  # set the tags set by the user
  @last_records = {}
  @main_tag = conf['main_tag']

  @sub_tags = []
  (1..PATTERN_MAX_NUM).each do |i|
    next unless conf["sub_tag#{i}"]

    @sub_tags.push(conf["sub_tag#{i}"])
  end

  if conf['merge_timing']
    @merge_timing = conf['merge_timing']
  end

  @tolerable_time_range = conf['tolerable_time_range'].to_i

  @flags4merge = Array.new(@sub_tags.size + 1, 0)
  @force_emit = conf['force_emit']

  # from out-record-reformer
  map = {}
  conf.elements.select { |element| element.name == 'record' }.each do |element|
    element.each_pair do |k, v|
      element.key?(k) # to suppress unread configuration warning
      map[k] = parse_value(v)
    end
  end

  placeholder_expander_params = {
    log: log,
    auto_typecast: @auto_typecast
  }
  @placeholder_expander = PlaceholderExpander.new(placeholder_expander_params)
  @map = @placeholder_expander.preprocess_map(map)
  @tag = @placeholder_expander.preprocess_map(@tag)
  @hostname = Socket.gethostname
  @condition = conf['condition']
  @keep_records = conf['keep_records']
  if conf['sub_is_must'] == "false"
    @sub_is_must = false
  else
    @sub_is_must = true
  end
end

#process(tag, es) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fluent/plugin/out_records_merger.rb', line 109

def process(tag, es)
  if @merge_timing == 'before'
    if @main_tag == tag
      store_to_lastrecords(tag, es)
      @flags4merge[0] = 1
      check_timegap if @tolerable_time_range > 0
      emit_new_event(es) if (@flags4merge.all? { |flag| flag == 1 } || @sub_is_must == false)
    elsif @sub_tags.include?(tag)
      store_to_lastrecords(tag, es)
      @flags4merge[@sub_tags.index(tag) + 1] = 1
      check_timegap if @tolerable_time_range > 0
    end
  elsif @merge_timing == 'after'
    if @main_tag == tag
      store_to_lastrecords(tag, es)
      @flags4merge[0] = 1
      check_timegap if @tolerable_time_range > 0
    elsif @sub_tags.include?(tag)
      if @flags4merge[0] == 1
        store_to_lastrecords(tag, es)
        @flags4merge[@sub_tags.index(tag) + 1] = 1
        check_timegap if @tolerable_time_range > 0
        emit_new_event(es) if (@flags4merge.all? {|flag| flag == 1}  || @sub_is_must == false)
      end
    else
      p 'something else has come! check it!' + tag.to_s
    end
  elsif @merge_timing == 'simple'
    if @main_tag == tag
      store_to_lastrecords(tag, es)
      @flags4merge[0] = 1
      check_timegap if @tolerable_time_range > 0
      emit_new_event(es) if (@flags4merge.all? { |flag| flag == 1 }  || @sub_is_must == false)
    elsif @sub_tags.include?(tag)
      store_to_lastrecords(tag, es)
      @flags4merge[@sub_tags.index(tag) + 1] = 1
      check_timegap if @tolerable_time_range > 0
      emit_new_event(es) if (@flags4merge.all? { |flag| flag == 1 }  || @sub_is_must == false)
    else
      p 'something else has come! check it!' + tag.to_s
    end
  end
rescue StandardError => e
  log.warn "record_reformer: #{e.class} #{e.message} #{e.backtrace.first}"
  log.debug "record_reformer: tag:#{@tag} map:#{@map} record:#{@last_records} placeholder_values"
end

#shutdownObject



105
106
107
# File 'lib/fluent/plugin/out_records_merger.rb', line 105

def shutdown
  super
end

#startObject



101
102
103
# File 'lib/fluent/plugin/out_records_merger.rb', line 101

def start
  super
end