Skip to content

ESQL: Enable async get to support formatting #111104

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

Conversation

kanoshiou
Copy link
Contributor

@kanoshiou kanoshiou commented Jul 19, 2024

An async request in text mode (POST _query/async?format=txt) previously returned an empty body without providing an async ID. I have now implemented the second approach mentioned in the issue #110926. Now, the async parameters (Async-ID & Async-running) are returned as headers.

However, I discovered an issue: when using the async ID from a text mode request to query /_query/async/{id}, the returned data format is still JSON. This might be a bug, and perhaps the response should be in plain text format, matching the initial request.

Closes #110926

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.16.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Jul 19, 2024
@gbanasiak gbanasiak added the :Analytics/ES|QL AKA ESQL label Jul 23, 2024
@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) and removed needs:triage Requires assignment of a team area label labels Jul 23, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@bpintea
Copy link
Contributor

bpintea commented Jul 25, 2024

Thanks for your interest, @kanoshiou.

We'll want to make sure that all operations are possible and work in txt mode with the async querying, not just starting the query (see other async APIs); since if that's not an option for some reason, we'll want to reject the async "txt query" all together, rather than add the headers.

Besides that any change would require tests. For txt mode we'll want (besides possible unit tests) integration tests. Have a look at x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestEsqlTestCase.java.

@kanoshiou
Copy link
Contributor Author

all operations are possible and work in txt mode with the async querying, not just starting the query

@bpintea I agree with this. I will work on making sure that when the request is in txt mode, /_query/async/{id} returns correctly. I will also add tests once I have completed all the code changes.

However, after reviewing the code for /_query/async/{id}, I realize that the changes required might be quite extensive. As a new contributor, I might need some additional time to implement these changes, and I would greatly appreciate any guidance.

Currently, /_query/async/{id} uses RestRefCountedChunkedToXContentListener. Would it be possible to simply replace it with EsqlResponseListener as used in /_query/async, or is there a better approach? For example, creating a new listener that extends RestRefCountedChunkedToXContentListener like EsqlResponseListener does and overrides the processResponse method. It seems I also need to store the initial request format in StoredAsyncResponse.

@kanoshiou kanoshiou marked this pull request as draft July 26, 2024 01:52
@kanoshiou kanoshiou marked this pull request as ready for review July 31, 2024 16:29
@kanoshiou
Copy link
Contributor Author

Hi @bpintea ,

I believe I have completed the code. Could you please review it when you have some time?

I've updated the listener for GET /_query/async/{id} to EsqlResponseListener, so it now accepts parameters (delimiter, drop_null_columns and format) like the POST /_query API. Additionally, I have added tests to verify the correctness of the code.

You can now set the format in the request parameters to specify the return style. I’m not sure if this meets your requirements. If there are any other issues with the code, please let me know, and I will continue to modify it.

@kanoshiou
Copy link
Contributor Author

Hi @bpintea ,

I hope this message finds you well. I wanted to gently remind you about #111104. It has been a while since the submission, and I wanted to check if there are any updates or if any further actions are required from my side.

Thank you for your time and assistance!

@bpintea
Copy link
Contributor

bpintea commented Nov 27, 2024

@kanoshiou sorry for getting back late.
Meanwhile, some of the issues covered in your PR had already been addressed, like the headers insertion, now also aligned with the _search API (see #111840).
However, not all of it, specifically the async get, which still doesn't support formatting, neither the originally asked for one, nor one requested as URL parameters (the format one). Worst, it doesn't even consider the Accept header formats. Your PR does address this and would be worth continuing.

@bpintea bpintea self-assigned this Dec 4, 2024
@bpintea bpintea added >feature auto-backport Automatically create backport pull requests when merged v8.18.0 labels Dec 4, 2024
Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor notes, looking good otherwise.

@kanoshiou
Copy link
Contributor Author

@bpintea Thank you very much! I have updated the branch based on your comments.

@bpintea
Copy link
Contributor

bpintea commented Dec 4, 2024

@elasticsearchmachine test this please

@kanoshiou
Copy link
Contributor Author

Hi @bpintea, I would like to know how I should resolve these test failures, as I can't see the details.

@bpintea
Copy link
Contributor

bpintea commented Dec 5, 2024

I would like to know how I should resolve these test failures

I'm not sure how/if you can access the test results. But most of them will be revealed if you run locally ./gradlew -p x-pack/plugin/esql/ check. That would take a while, though since it runs BWC tests as well. You can probably run individual tests too (see ./gradlew tasks --all).
Besides that, another failed test was ./gradlew ":test:external-modules:test-esql-heap-attack:javaRestTest".

The tests failed because of missing media type indication. We're a bit inconsistent here, but ES allows a (search) GET with no media type indication whatsoever, so I need to revise my previous comment about supporting a default -- I've pushed a fix for that. However, I'd kindly ask you to add tests for this (i.e. an async GET with no media indication) then too, both RestEsqlTestCase and EsqlMediaTypeParserTests. Thanks.

@bpintea
Copy link
Contributor

bpintea commented Dec 5, 2024

@elasticsearchmachine test this please

@kanoshiou
Copy link
Contributor Author

@bpintea Thank you for letting me know.

I'd kindly ask you to add tests for this (i.e. an async GET with no media indication) then too, both RestEsqlTestCase and EsqlMediaTypeParserTests. Thanks.

Sure thing! I will implement the tests ASAP.

@kanoshiou
Copy link
Contributor Author

@bpintea I've added the tests. Please review.

@bpintea
Copy link
Contributor

bpintea commented Dec 6, 2024

@elasticsearchmachine test this please

@bpintea
Copy link
Contributor

bpintea commented Dec 9, 2024

@elasticsearchmachine test this please

@bpintea
Copy link
Contributor

bpintea commented Dec 9, 2024

@elasticsearchmachine test this please

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @kanoshiou.


}

static Request prepareRequestWithOptions(RequestObjectBuilder requestObject, Mode mode) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

var json = entityToMap(entity, requestObject.contentType());
checkKeepOnCompletion(requestObject, json, true);
String id = (String) json.get("id");
// results won't be returned since keepOnCompletion is true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: if they're not returned, it's because the waitForCompletion() is provided a very small interval (see addAsyncParameters()), so ES won't have the time to query and respond with results in time.

// results won't be returned since keepOnCompletion is true
assertThat(id, is(not(emptyOrNullString())));

// issue an "async get" request with no Content-Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bpintea bpintea merged commit 67ee034 into elastic:main Dec 9, 2024
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

bpintea pushed a commit to bpintea/elasticsearch that referenced this pull request Dec 9, 2024
I've updated the listener for GET /_query/async/{id} to EsqlResponseListener, so it now accepts parameters (delimiter, drop_null_columns and format) like the POST /_query API. Additionally, I have added tests to verify the correctness of the code.

You can now set the format in the request parameters to specify the return style.

Closes elastic#110926
@kanoshiou
Copy link
Contributor Author

@bpintea, Thank you so much for taking the time to review my code. I truly appreciate your patience and attention to detail. This has been an unforgettable experience, and I have learned a lot.😊

elasticsearchmachine pushed a commit that referenced this pull request Dec 9, 2024
I've updated the listener for GET /_query/async/{id} to EsqlResponseListener, so it now accepts parameters (delimiter, drop_null_columns and format) like the POST /_query API. Additionally, I have added tests to verify the correctness of the code.

You can now set the format in the request parameters to specify the return style.

Closes #110926

Co-authored-by: kanoshiou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged external-contributor Pull request authored by a developer outside the Elasticsearch team >feature Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESQL: Async request disregards format request
5 participants