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
make first part of user agent header configurable #9471
Conversation
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.
LGTM
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.
LGTM in general. Minor comments
@@ -66,7 +66,8 @@ public JsonAsyncHttpPinotClientTransport() { | |||
} | |||
|
|||
public JsonAsyncHttpPinotClientTransport(Map<String, String> headers, String scheme, | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, TlsProtocols tlsProtocols) { | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, |
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.
(format) Please follow the Pinot Style. Same for other changes
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.
Annotate appId
as @Nullable
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.
The format is still not correct. Please update the IDE style setting and reformat
@@ -43,13 +43,15 @@ public class JsonAsyncHttpPinotClientTransportFactory implements PinotClientTran | |||
private int _readTimeoutMs = Integer.parseInt(DEFAULT_BROKER_READ_TIMEOUT_MS); | |||
private int _connectTimeoutMs = Integer.parseInt(DEFAULT_BROKER_READ_TIMEOUT_MS); | |||
private int _handshakeTimeoutMs = Integer.parseInt(DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS); | |||
private String _appId = ""; |
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.
Suggest setting it to null
if not available
@@ -94,6 +96,7 @@ public JsonAsyncHttpPinotClientTransportFactory withConnectionProperties(Propert | |||
DEFAULT_BROKER_CONNECT_TIMEOUT_MS)); | |||
_handshakeTimeoutMs = Integer.parseInt(properties.getProperty("brokerHandshakeTimeoutMs", | |||
DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS)); | |||
_appId = properties.getProperty("appId", ""); |
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.
Set it to null
if not available
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.
^^
@@ -56,14 +56,18 @@ public static SSLContext getSSLContextFromProperties(Properties properties) { | |||
} | |||
|
|||
|
|||
public static String getUserAgentVersionFromClassPath(String userAgentKey) { | |||
public static String getUserAgentVersionFromClassPath(String userAgentKey, String appId) { |
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.
public static String getUserAgentVersionFromClassPath(String userAgentKey, String appId) { | |
public static String getUserAgentVersionFromClassPath(String userAgentKey, @Nullable String appId) { |
Properties userAgentProperties = new Properties(); | ||
try { | ||
userAgentProperties.load(ConnectionUtils.class.getClassLoader() | ||
.getResourceAsStream("version.properties")); | ||
} catch (IOException e) { | ||
LOGGER.warn("Unable to set user agent version"); | ||
} | ||
return userAgentProperties.getProperty(userAgentKey, "pinot-java"); | ||
String userAgentFromProperties = userAgentProperties.getProperty(userAgentKey, "unknown"); | ||
if (appId != null && appId.length() > 0) { |
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.
(nit) StringUtils.isNotEmpty(appId)
@@ -52,7 +52,8 @@ public class PinotControllerTransport { | |||
|
|||
|
|||
public PinotControllerTransport(Map<String, String> headers, String scheme, | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, TlsProtocols tlsProtocols) { | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, |
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.
Same comments as in JsonAsyncHttpPinotClientTransport
@@ -41,12 +41,13 @@ public class PinotControllerTransportFactory { | |||
private int _readTimeoutMs = Integer.parseInt(DEFAULT_CONTROLLER_READ_TIMEOUT_MS); | |||
private int _connectTimeoutMs = Integer.parseInt(DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS); | |||
private int _handshakeTimeoutMs = Integer.parseInt(DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS); | |||
private String _appId = ""; |
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.
Same comments as in JsonAsyncHttpPinotClientTransportFactory
Codecov Report
@@ Coverage Diff @@
## master #9471 +/- ##
============================================
+ Coverage 69.89% 69.90% +0.01%
- Complexity 4742 4818 +76
============================================
Files 1910 1910
Lines 101787 101798 +11
Branches 15445 15447 +2
============================================
+ Hits 71139 71161 +22
+ Misses 25628 25604 -24
- Partials 5020 5033 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
will fix, should I trim the appId to 32 characters? |
Is there a constraint on the appId length? If so, we should fail it when user configure it with a too long value |
I will take 256 chars. |
@@ -104,6 +104,7 @@ public BrokerCache(Properties properties, String controllerUrl) { | |||
DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS)); | |||
int handshakeTimeoutMs = Integer.parseInt(properties.getProperty("controllerHandshakeTimeoutMs", | |||
DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS)); | |||
String appId = properties.getProperty("appId", DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS); |
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.
String appId = properties.getProperty("appId", DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS); | |
String appId = properties.getProperty("appId"); |
@@ -66,7 +66,8 @@ public JsonAsyncHttpPinotClientTransport() { | |||
} | |||
|
|||
public JsonAsyncHttpPinotClientTransport(Map<String, String> headers, String scheme, | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, TlsProtocols tlsProtocols) { | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, |
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.
The format is still not correct. Please update the IDE style setting and reformat
@@ -94,6 +96,7 @@ public JsonAsyncHttpPinotClientTransportFactory withConnectionProperties(Propert | |||
DEFAULT_BROKER_CONNECT_TIMEOUT_MS)); | |||
_handshakeTimeoutMs = Integer.parseInt(properties.getProperty("brokerHandshakeTimeoutMs", | |||
DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS)); | |||
_appId = properties.getProperty("appId", ""); |
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.
^^
return userAgentProperties.getProperty("ua", "unknown"); | ||
String userAgentFromProperties = userAgentProperties.getProperty("ua", "unknown"); | ||
if (StringUtils.isNotEmpty(appId)) { | ||
return appId.substring(0, Math.min(org.apache.pinot.client.utils.ConnectionUtils.APP_ID_MAX_CHARS, |
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.
(minor) import ConnectionUtils
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.
[WARNING] src/main/java/org/apache/pinot/client/controller/PinotControllerTransport.java:[45,60] (imports) AvoidStaticImport: Using a static member import should be avoided - org.apache.pinot.client.utils.ConnectionUtils.APP_ID_MAX_CHARS.
@@ -80,6 +81,7 @@ public PinotControllerTransportFactory withConnectionProperties(Properties prope | |||
DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS)); | |||
_handshakeTimeoutMs = Integer.parseInt(properties.getProperty("controllerHandshakeTimeoutMs", | |||
DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS)); | |||
_appId = properties.getProperty("appId", ""); |
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.
Same here, we want to set null
when it is not configured
_appId = properties.getProperty("appId", ""); | |
_appId = properties.getProperty("appId"); |
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.
Please take a look at the failed tests
@@ -70,7 +70,8 @@ public JsonAsyncHttpPinotClientTransport() { | |||
} | |||
|
|||
public JsonAsyncHttpPinotClientTransport(Map<String, String> headers, String scheme, String extraOptionString, | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, TlsProtocols tlsProtocols) { | |||
@Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, |
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.
Please reformat this file
I don't see anything related to this failure in this PR:
nor this codepath:
|
This PR adds the configuration option to prefix the User Agent header with a custom appId. This allows the server to see where the queries originate from.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#library_and_net_tool_ua_strings