From 76876f113b05e5fff0e091f6ac2983a1dd7599eb Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 14 Aug 2024 13:39:19 +0900 Subject: [PATCH] in_sample: duplicate record to support destructive change When in_sample plugin is used with filter parser which uses remove_key_name_field, it raises the following error repeatedly. #0 dump an error event: error_class=ArgumentError error="message does not exist" This kind of error occurs when key_name and remove_key_name_field removes key from record with destructive change in filter parser affects generated sample data. ref. https://github.com/fluent/fluentd/issues/4575 Signed-off-by: Kentaro Hayashi --- lib/fluent/plugin/in_sample.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/in_sample.rb b/lib/fluent/plugin/in_sample.rb index ccd918aa10..0afda7f0a7 100644 --- a/lib/fluent/plugin/in_sample.rb +++ b/lib/fluent/plugin/in_sample.rb @@ -118,14 +118,13 @@ def emit(num) end def generate - d = @sample[@sample_index] + d = @sample[@sample_index].dup unless d @sample_index = 0 - d = @sample[@sample_index] + d = @sample[@sample_index].dup end @sample_index += 1 if @auto_increment_key - d = d.dup d[@auto_increment_key] = @storage.update(:auto_increment_value){|v| v + 1 } end d