Skip to content

Commit 65eb675

Browse files
committed
Rename warning msg field name to avoid conflicts. Generate a target apply method to avoid null checks at runtime.
1 parent d4f559d commit 65eb675

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/logstash/inputs/elasticsearch/esql.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ class Esql
1818
def initialize(client, plugin)
1919
@client = client
2020
@event_decorator = plugin.method(:decorate_event)
21-
@target_field = plugin.params["target"]
2221
@retries = plugin.params["retries"]
2322

23+
target_field = plugin.params["target"]
24+
if target_field
25+
def self.apply_target(path) = "[#{target_field}][#{path}]"
26+
else
27+
def self.apply_target(path) = path
28+
end
29+
2430
@query = plugin.params["query"]
2531
unless @query.include?('METADATA')
2632
logger.info("`METADATA` not found the query. `_id`, `_version` and `_index` will not be available in the result", {:query => @query})
@@ -40,7 +46,7 @@ def do_run(output_queue, query)
4046
return if response == false
4147

4248
if response&.headers&.dig("warning")
43-
logger.warn("ES|QL executor received warning", {:message => response.headers["warning"]})
49+
logger.warn("ES|QL executor received warning", {:warning_message => response.headers["warning"]})
4450
end
4551
columns = response['columns']&.freeze
4652
values = response['values']&.freeze
@@ -76,7 +82,7 @@ def process_response(columns, values, output_queue)
7682
# `unless value.nil?` is a part of `drop_null_columns` that if some of columns' values are not `nil`, `nil` values appear
7783
# we should continuously filter out them to achieve full `drop_null_columns` on each individual row (ideal `LIMIT 1` result)
7884
unless value.nil?
79-
field_reference = @target_field.nil? ? column.field_reference : "[#{@target_field}][#{column.field_reference}]"
85+
field_reference = apply_target(column.field_reference)
8086
event.set(field_reference, ESQL_PARSERS_BY_TYPE[column.type].call(value))
8187
end
8288
end

spec/inputs/elasticsearch_esql_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
it "logs a warning if the response contains a warning header" do
7171
allow(response).to receive(:headers).and_return({ "warning" => "some warning" })
72-
expect(esql_executor.logger).to receive(:warn).with("ES|QL executor received warning", { :message => "some warning" })
72+
expect(esql_executor.logger).to receive(:warn).with("ES|QL executor received warning", { :warning_message => "some warning" })
7373
esql_executor.do_run(output_queue, plugin_config["query"])
7474
end
7575

0 commit comments

Comments
 (0)