-
Notifications
You must be signed in to change notification settings - Fork 84
Esql support #233
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
Open
mashhurs
wants to merge
11
commits into
logstash-plugins:main
Choose a base branch
from
mashhurs:esql-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Esql support #233
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a307db2
ES|QL support: ESQL executor implementation, response type to accept …
mashhurs 9c35f22
Merge with upstream, warn if query doesn't include METADATA which DSL…
mashhurs 6f99055
Run unit tests with the LS version which actually supports the ES|QL.
mashhurs 086a592
Add query type to the agent. DRY of supported ES/LS versions.
mashhurs e30e0f9
Remove query type from user-agent since it is useless, put back accid…
mashhurs 7746c14
Initial docs added for ES|QL.
mashhurs 76303d8
Update query to include condition with string.
mashhurs 1fb29f7
Tested escaped chars cases, uses orignal query.
mashhurs 5d47f2f
Integration tests added.
mashhurs c291e24
Skip the ESQL test if LS with the ES client which doesn't support ESQ…
mashhurs 22e72e9
Add comments on response type and query params about ES|QL acceptance…
mashhurs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'logstash/helpers/loggable_try' | ||
|
||
module LogStash | ||
module Inputs | ||
class Elasticsearch | ||
class Esql | ||
include LogStash::Util::Loggable | ||
|
||
ESQL_JOB = "ES|QL job" | ||
|
||
# Initialize the ESQL query executor | ||
# @param client [Elasticsearch::Client] The Elasticsearch client instance | ||
# @param plugin [LogStash::Inputs::Elasticsearch] The parent plugin instance | ||
def initialize(client, plugin) | ||
@client = client | ||
@plugin = plugin | ||
@retries = plugin.params["retries"] | ||
|
||
@query = plugin.params["query"] | ||
unless @query.include?('METADATA') | ||
logger.warn("The query doesn't have METADATA keyword. Including it makes _id and _version available in the documents", {:query => @query}) | ||
end | ||
end | ||
|
||
# Execute the ESQL query and process results | ||
# @param output_queue [Queue] The queue to push processed events to | ||
# @param query A query (to obey interface definition) | ||
def do_run(output_queue, query) | ||
logger.info("ES|QL executor starting") | ||
response = retryable(ESQL_JOB) do | ||
@client.esql.query({ body: { query: @query }, format: 'json' }) | ||
end | ||
# retriable already printed error details | ||
return if response == false | ||
|
||
if response&.headers&.dig("warning") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review note: interestingly warnings in response headers. |
||
logger.warn("ES|QL executor received warning", {:message => response.headers["warning"]}) | ||
end | ||
if response['values'] && response['columns'] | ||
process_response(response['values'], response['columns'], output_queue) | ||
end | ||
end | ||
|
||
# Execute a retryable operation with proper error handling | ||
# @param job_name [String] Name of the job for logging purposes | ||
# @yield The block to execute | ||
# @return [Boolean] true if successful, false otherwise | ||
def retryable(job_name, &block) | ||
stud_try = ::LogStash::Helpers::LoggableTry.new(logger, job_name) | ||
stud_try.try((@retries + 1).times) { yield } | ||
rescue => e | ||
error_details = {:message => e.message, :cause => e.cause} | ||
error_details[:backtrace] = e.backtrace if logger.debug? | ||
logger.error("#{job_name} failed with ", error_details) | ||
false | ||
end | ||
|
||
private | ||
|
||
# Process the ESQL response and push events to the output queue | ||
# @param values [Array[Array]] The ESQL query response hits | ||
# @param columns [Array[Hash]] The ESQL query response columns | ||
# @param output_queue [Queue] The queue to push processed events to | ||
def process_response(values, columns, output_queue) | ||
values.each do |value| | ||
mapped_data = map_column_and_values(columns, value) | ||
@plugin.decorate_and_push_to_queue(output_queue, mapped_data) | ||
end | ||
end | ||
|
||
# Map column names to their corresponding values | ||
# @param columns [Array] Array of column definitions | ||
# @param values [Array] Array of values for the current row | ||
# @return [Hash] Mapped data with column names as keys | ||
def map_column_and_values(columns, values) | ||
columns.each_with_index.with_object({}) do |(column, index), mapped_data| | ||
mapped_data[column["name"]] = values[index] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review note: before releasing this change, I will backport and release 4.23.0 first