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

Fix query id extraction from request query #265

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

willmostly
Copy link
Contributor

The logic for extracting a query id from the request query was broken. The test for this functionality was also broken, since it passed the query to the extraction method as part of the path.

@cla-bot cla-bot bot added the cla-signed label Feb 27, 2024
@@ -61,6 +61,7 @@ public class QueryIdCachingProxyHandler
public static final String HOST_HEADER = "Host";
private static final int QUERY_TEXT_LENGTH_FOR_HISTORY = 200;
private static final Pattern QUERY_ID_PATTERN = Pattern.compile(".*[/=?](\\d+_\\d+_\\d+_\\w+).*");
private static final Pattern QUERY_ID_PARAM_PATTERN = Pattern.compile(".*(?:%2F|=|^)(\\d+_\\d+_\\d+_\\w+).*");
Copy link
Member

Choose a reason for hiding this comment

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

regex .. uff

Copy link
Member

Choose a reason for hiding this comment

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

I am curious if trino also uses the same pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trino uses a lightweight test that only checks for characters in the set [_a-z0-9]. A queryId could technically be something like "testqueryid", as you see in some tests, but the generator imposes a specific format

These patterns impose additional restrictions on where a queryid can appear to reduce false positives.

Copy link
Member

@vishalya vishalya left a comment

Choose a reason for hiding this comment

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

Overall looks good, apart from minor comments.

@willmostly willmostly force-pushed the will/match_query_id_in_param branch 2 times, most recently from 2bc7f9f to 24d9c17 Compare February 28, 2024 18:44
@willmostly willmostly force-pushed the will/match_query_id_in_param branch 2 times, most recently from e7d8f53 to c89ea0d Compare February 29, 2024 18:00
@@ -60,7 +60,8 @@ public class QueryIdCachingProxyHandler
public static final String SOURCE_HEADER = "X-Trino-Source";
public static final String HOST_HEADER = "Host";
private static final int QUERY_TEXT_LENGTH_FOR_HISTORY = 200;
private static final Pattern QUERY_ID_PATTERN = Pattern.compile(".*[/=?](\\d+_\\d+_\\d+_\\w+).*");
private static final Pattern QUERY_ID_PATH_PATTERN = Pattern.compile(".*/(\\d+_\\d+_\\d+_\\w+).*");
private static final Pattern QUERY_ID_PARAM_PATTERN = Pattern.compile(".*(?:%2F|(?i)query_?id(?-i)=|^)(\\d+_\\d+_\\d+_\\w+).*");
Copy link
Member

Choose a reason for hiding this comment

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

oh how I hate regex like this .. should we somehow add some Java doc that explains it a little bit .. or do we just treat the test as the docs?

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 good even if the regex is really not easily readable. Feel free to add some javadoc if you think it helps .. but otherwise also feel free to ship as it is now

@willmostly willmostly force-pushed the will/match_query_id_in_param branch from c89ea0d to 5a6bbad Compare March 6, 2024 18:09
@mosabua
Copy link
Member

mosabua commented Mar 6, 2024

@Chaho12 also confirmed in the dev sync on the 6th of March that this PR is good to go.

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.

Thanks for adding the comments.

@mosabua mosabua merged commit 8bd5e90 into trinodb:main Mar 6, 2024
2 checks passed
@github-actions github-actions bot added this to the 7 milestone Mar 6, 2024
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.

5 participants