Skip to content
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

Extract query ID from all kill_query procedure variations #425

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

willmostly
Copy link
Contributor

Description

Trino Gateway attempts to extract the query id from the body of queries using the runtime.kill_query procedure from the system catalog. This adds a test for this functionality.

Additional context and related issues

Release notes

( x) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Jul 29, 2024
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 0f19b85 to 1ad0e45 Compare July 29, 2024 19:15
Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Looks fine .. I wish we would not have to mock around for stuff like that but a full integration test seems worse..

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 1ad0e45 to a8355b6 Compare August 30, 2024 21:42
@willmostly willmostly requested a review from ebyhr August 30, 2024 21:45
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from a8355b6 to 83760bd Compare August 30, 2024 21:53
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 9a00f3e to 95e782a Compare September 3, 2024 19:40
@willmostly willmostly changed the title Test extraction of query ID from kill_query procedure Extract query ID from all kill_query procedure variations Sep 3, 2024
ebyhr
ebyhr previously requested changes Sep 4, 2024
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

The regular expression is incorrect in some cases.

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 95e782a to c311199 Compare September 4, 2024 20:10
@mosabua
Copy link
Member

mosabua commented Sep 5, 2024

Needs a rebase now..

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from c311199 to e9226b6 Compare September 9, 2024 19:29
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch 2 times, most recently from 805fd81 to e805660 Compare September 23, 2024 19:05
@willmostly
Copy link
Contributor Author

@ebyhr I switched to using the full query parser, which should be resilient to whitespace, comments, the string literals containing the procedure name, etc

Comment on lines 271 to 272
procedure = Optional.of((Call) node);
procedureArgs = ((Call) node).getArguments();
Copy link
Member

Choose a reason for hiding this comment

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

The method name is getNames. Setting these fields changes doesn't match the naming now. I would recommend moving this logic to ProxyUtils and reverting changes in this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i renamed the method to be more generic. The initial implementation was only concerned with extracting qualified names from SQL, but there is no reason IMO not to extract other information as well. In addition to this specific case of the kill_query call which contains a query id, the Call and CallArguments could be useful for routing logic. For example, perhaps the sync_partition_metadata procedure should always be run on a specific set of clusters.

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from e805660 to 6e9842a Compare September 25, 2024 23:56
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 6e9842a to 76f2c68 Compare September 26, 2024 13:05
catch (Exception e) {
log.error(e, "Error extracting query payload from request");
catch (IOException e) {
log.error(e, "Error reading request body");
Copy link
Member

Choose a reason for hiding this comment

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

Why do we suppress IOException here and throw an exception for non string literal argument of kill_query procedure?

The request.getInputStream() may contain kill_query, but it can go to extractQueryIdIfPresent in case of IOException, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the request body contains the kill_query SQL, then I already know at this point that extractQueryIdIfPresent will not find a query id because Trino doesn't have any endpoints with query id embedded in the path or queryParams that accept a POST. So falling back won't help. If I don't throw on a non-string literal argument, then this request will most likely get routed to a cluster that the target query is not running on, and the user will get a potentially confusing error message back about the query not existing. So throwing on a non-string literal allows us to fail fast with a more meaningful error.

Do you think we should throw on IOException as well? I was just trying to match the existing behavior, but i'm not sure that it is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just noting that this has been changed such that the IOException is not suppressed, and is treated as an error. If the gateway can't read the request body, Trino will not be able to either, so there is no reason to forward the request.

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from 76f2c68 to f4ee990 Compare September 26, 2024 20:57
@ebyhr
Copy link
Member

ebyhr commented Oct 1, 2024

Could you rebase on main to resolve conflicts?

@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch 4 times, most recently from 9e35c95 to c8fe87d Compare October 1, 2024 23:39
@willmostly willmostly requested a review from ebyhr October 2, 2024 00:11
@willmostly willmostly force-pushed the will/test_extract_query_id_from_system_runtime_kill_query branch from c8fe87d to 131228b Compare October 2, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants