-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
@@ -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+).*"); |
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.
regex .. uff
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.
I am curious if trino also uses the same pattern.
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.
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.
gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
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.
Overall looks good, apart from minor comments.
gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/main/java/io/trino/gateway/ha/handler/QueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
2bc7f9f
to
24d9c17
Compare
gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java
Outdated
Show resolved
Hide resolved
e7d8f53
to
c89ea0d
Compare
@@ -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+).*"); |
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.
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?
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.
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
gateway-ha/src/main/java/io/trino/gateway/ha/handler/QueryIdCachingProxyHandler.java
Show resolved
Hide resolved
c89ea0d
to
5a6bbad
Compare
@Chaho12 also confirmed in the dev sync on the 6th of March that this PR is good to go. |
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.
Thanks for adding the comments.
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 thepath
.