lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.2 vs lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.3
- old
+ new
@@ -11,12 +11,14 @@
config_param :count_interval, :time, :default => nil
config_param :unit, :string, :default => 'minute'
config_param :output_per_tag, :bool, :default => false
config_param :aggregate, :string, :default => 'tag'
config_param :tag, :string, :default => 'groupcount'
- config_param :tag_prefix, :string, :default => nil
- config_param :input_tag_remove_prefix, :string, :default => nil
+ config_param :tag_prefix, :string, :default => nil # obsolete
+ config_param :add_tag_prefix, :string, :default => nil
+ config_param :input_tag_remove_prefix, :string, :default => nil # obsolete
+ config_param :remove_tag_prefix, :string, :default => nil
config_param :group_by_keys, :string, :default => nil
config_param :group_by_expression, :string, :default => nil
config_param :max_key, :string, :default => nil
config_param :min_key, :string, :default => nil
config_param :avg_key, :string, :default => nil
@@ -54,17 +56,22 @@
when 'all' then :all
else
raise Fluent::ConfigError, "groupcounter aggregate allows tag/all"
end
+ @add_tag_prefix ||= @tag_prefix
+ @remove_tag_prefix ||= @input_tag_remove_prefix
if @output_per_tag
- raise Fluent::ConfigError, "tag_prefix must be specified with output_per_tag" unless @tag_prefix
- @tag_prefix_string = @tag_prefix + '.'
+ raise Fluent::ConfigError, "add_tag_prefix must be specified with output_per_tag" unless @add_tag_prefix
end
-
- if @input_tag_remove_prefix
- @removed_prefix_string = @input_tag_remove_prefix + '.'
+ if @add_tag_prefix
+ @tag_prefix_string = @add_tag_prefix + '.'
+ else
+ @tag_prefix_string = ''
+ end
+ if @remove_tag_prefix
+ @removed_prefix_string = @remove_tag_prefix + '.'
@removed_length = @removed_prefix_string.length
end
@group_by_keys = @group_by_keys.split(',') if @group_by_keys
@@ -150,11 +157,11 @@
# this method emits messages (periodically called)
def flush_emit
time = Fluent::Engine.now
if @output_per_tag
flush.each do |tag, message|
- Fluent::Engine.emit(@tag_prefix_string + tag, time, message)
+ Fluent::Engine.emit("#{@tag_prefix_string}#{tag}", time, message)
end
else
message = flush
Fluent::Engine.emit(@tag, time, message) unless message.empty?
end
@@ -263,12 +270,11 @@
return a if b.nil?
a > b ? b : a
end
def stripped_tag(tag)
- return tag unless @input_tag_remove_prefix
+ return tag unless @remove_tag_prefix
return tag[@removed_length..-1] if tag.start_with?(@removed_prefix_string) and tag.length > @removed_length
- return tag[@removed_length..-1] if tag == @input_tag_remove_prefix
tag
end
# Store internal status into a file
#