Skip to content

Commit

Permalink
Bug 1852341: skip nil keys in json filter
Browse files Browse the repository at this point in the history
  • Loading branch information
blockloop committed Sep 3, 2020
1 parent 6a38810 commit 8d3fcd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def filter_stream(tag, es)
def do_merge_json_log(record)
json_fields.each do |merge_json_log_key|
if record.has_key?(merge_json_log_key)
value = record[merge_json_log_key].strip
value = (record[merge_json_log_key] || "").strip
if value.start_with?('{') && value.end_with?('}')
begin
record = JSON.parse(value).merge(record)
Expand All @@ -80,7 +80,7 @@ def do_merge_json_log(record)
def do_replace_json_log(record)
json_fields.each do |merge_json_log_key|
if record.has_key?(merge_json_log_key)
value = record[merge_json_log_key].strip
value = (record[merge_json_log_key] || "").strip
if value.start_with?('{') && value.end_with?('}')
begin
parsed_value = JSON.parse(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,16 @@ def emit_with_tag(tag, msg={}, conf='')
debugit(@driver, 'in test')
assert_match /\[debug\]: parse_json_field could not parse field \[skip1\] as JSON: value \[\{"bogusvalue\}\]/, @logs[0]
end
test 'fallback if given field is nil' do
# test that - skip1 is skipped because it has a nil key
json_string_val2 = '{"k":{"b":"c"},"l":["e","f"],"m":97,"n":{"i":"j"}}'
orig_a_value = 'orig a value'
rec = emit_with_tag('tag', {'skip1'=>nil, 'a'=>orig_a_value, 'jsonfield'=>json_string_val2},'
merge_json_log true
json_fields skip1,jsonfield
')
assert_equal({'skip1'=>nil, 'a'=>orig_a_value, 'jsonfield'=>json_string_val2}, rec)
debugit(@driver, 'in test')
end
end
end

0 comments on commit 8d3fcd2

Please sign in to comment.