Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_sample: duplicate record to support destructive change #4586

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading