Skip to content

Commit d4f559d

Browse files
committed
Apply code review suggestions: to use decorator as a proc call, doc syntax fix, unit test errors fix.
1 parent a92a71e commit d4f559d

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

docs/index.asciidoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ The next scheduled run:
235235
{es} Query Language (ES|QL) provides a SQL-like interface for querying your {es} data.
236236

237237
To use {esql}, this plugin needs to be installed in {ls} 8.17.4 or newer, and must be connected to {es} 8.11 or newer.
238-
|===
239238

240239
To configure {esql} query in the plugin, set the `response_type` to `esql` and provide your {esql} query in the `query` parameter.
241240

lib/logstash/inputs/elasticsearch.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ def register
312312
if @response_type == 'esql'
313313
validate_ls_version_for_esql_support!
314314
validate_esql_query!
315-
ignored_options = original_params.keys & %w(index size slices search_api, docinfo, docinfo_target, docinfo_fields)
316-
@logger.info("Configured #{ignored_options} params are ignored in ES|QL query") if ignored_options&.size > 1
315+
not_allowed_options = original_params.keys & %w(index size slices search_api, docinfo, docinfo_target, docinfo_fields)
316+
raise(LogStash::ConfigurationError, "Configured #{not_allowed_options} params are not allowed while using ES|QL query") if not_allowed_options&.size > 1
317317
else
318318
@base_query = LogStash::Json.load(@query)
319319
if @slices

lib/logstash/inputs/elasticsearch/esql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Esql
1717
# @param plugin [LogStash::Inputs::Elasticsearch] The parent plugin instance
1818
def initialize(client, plugin)
1919
@client = client
20-
@plugin = plugin
20+
@event_decorator = plugin.method(:decorate_event)
2121
@target_field = plugin.params["target"]
2222
@retries = plugin.params["retries"]
2323

@@ -80,7 +80,7 @@ def process_response(columns, values, output_queue)
8080
event.set(field_reference, ESQL_PARSERS_BY_TYPE[column.type].call(value))
8181
end
8282
end
83-
@plugin.decorate_event(event)
83+
@event_decorator.call(event)
8484
output_queue << event
8585
rescue => e
8686
# if event creation fails with whatever reason, inform user and tag with failure and return entry as it is

spec/inputs/elasticsearch_esql_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
describe LogStash::Inputs::Elasticsearch::Esql do
77
let(:client) { instance_double(Elasticsearch::Client) }
88
let(:esql_client) { double("esql-client") }
9-
let(:plugin) { instance_double(LogStash::Inputs::Elasticsearch, params: plugin_config) }
9+
10+
let(:plugin) { instance_double(LogStash::Inputs::Elasticsearch, params: plugin_config, decorate_event: nil) }
1011
let(:plugin_config) do
1112
{
1213
"query" => "FROM test-index | STATS count() BY field",
@@ -19,7 +20,6 @@
1920
it "sets up the ESQL client with correct parameters" do
2021
expect(esql_executor.instance_variable_get(:@query)).to eq(plugin_config["query"])
2122
expect(esql_executor.instance_variable_get(:@retries)).to eq(plugin_config["retries"])
22-
expect(esql_executor.instance_variable_get(:@plugin)).to eq(plugin)
2323
expect(esql_executor.instance_variable_get(:@target_field)).to eq(nil)
2424
end
2525
end

spec/inputs/elasticsearch_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,24 @@ def extract_transport(client) # on 7.x client.transport is a ES::Transport::Clie
14391439
end
14401440
end
14411441

1442+
context "ES|QL query and DSL params used together" do
1443+
let(:config) {
1444+
super().merge({
1445+
"index" => "my-index",
1446+
"size" => 1,
1447+
"slices" => 1,
1448+
"search_api" => "auto",
1449+
"docinfo" => true,
1450+
"docinfo_target" => "[@metadata][docinfo]",
1451+
"docinfo_fields" => ["_index"],
1452+
})}
1453+
1454+
it "raises a config error" do
1455+
mixed_fields = %w[index size slices docinfo_fields]
1456+
expect { plugin.register }.to raise_error(LogStash::ConfigurationError, /Configured #{mixed_fields} params are not allowed while using ES|QL query/)
1457+
end
1458+
end
1459+
14421460
describe "ES|QL query" do
14431461
context "when query is valid" do
14441462
it "does not raise an error" do

0 commit comments

Comments
 (0)