Skip to content

Commit

Permalink
Merge pull request #4586 from kenhys/dup-sample
Browse files Browse the repository at this point in the history
in_sample: duplicate record to support destructive change
  • Loading branch information
kenhys authored Aug 16, 2024
2 parents c8c6040 + e8441f1 commit accd0c8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/fluent/plugin/in_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SampleInput < Input
config_param :auto_increment_key, :string, default: nil
desc "The boolean to suspend-and-resume incremental value after restart"
config_param :suspend, :bool, default: false,deprecated: 'This parameters is ignored'
desc "Reuse the sample data to reduce the load when sending large amounts of data. You can enable it if filter does not do destructive change"
config_param :reuse_record, :bool, default: false
desc "The sample data to be generated. An array of JSON hashes or a single JSON hash."
config_param :sample, alias: :dummy, default: [{"message" => "sample"}] do |val|
begin
Expand Down Expand Up @@ -117,15 +119,19 @@ def emit(num)
end
end

def generate
d = @sample[@sample_index]
unless d
@sample_index = 0
d = @sample[@sample_index]
end
def next_sample
d = @reuse_record ? @sample[@sample_index] : @sample[@sample_index].dup
@sample_index += 1
return d if d

@sample_index = 0
next_sample
end

def generate
d = next_sample
if @auto_increment_key
d = d.dup
d = d.dup if @reuse_record
d[@auto_increment_key] = @storage.update(:auto_increment_value){|v| v + 1 }
end
d
Expand Down

0 comments on commit accd0c8

Please sign in to comment.